CN113657410A - Image contour extraction method based on artificial intelligence and related equipment - Google Patents

Image contour extraction method based on artificial intelligence and related equipment Download PDF

Info

Publication number
CN113657410A
CN113657410A CN202110947886.0A CN202110947886A CN113657410A CN 113657410 A CN113657410 A CN 113657410A CN 202110947886 A CN202110947886 A CN 202110947886A CN 113657410 A CN113657410 A CN 113657410A
Authority
CN
China
Prior art keywords
pixel
pixel value
value
image
array
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202110947886.0A
Other languages
Chinese (zh)
Inventor
郑如刚
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
OneConnect Smart Technology Co Ltd
OneConnect Financial Technology Co Ltd Shanghai
Original Assignee
OneConnect Financial Technology Co Ltd Shanghai
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by OneConnect Financial Technology Co Ltd Shanghai filed Critical OneConnect Financial Technology Co Ltd Shanghai
Priority to CN202110947886.0A priority Critical patent/CN113657410A/en
Publication of CN113657410A publication Critical patent/CN113657410A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F18/00Pattern recognition
    • G06F18/20Analysing
    • G06F18/22Matching criteria, e.g. proximity measures

Landscapes

  • Engineering & Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Bioinformatics & Cheminformatics (AREA)
  • Bioinformatics & Computational Biology (AREA)
  • Artificial Intelligence (AREA)
  • Evolutionary Biology (AREA)
  • Evolutionary Computation (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Image Analysis (AREA)

Abstract

The invention relates to the technical field of artificial intelligence, and provides an image contour extraction method based on artificial intelligence and related equipment, which comprise the following steps: responding to the contour extraction instruction, and inputting the image to be processed into OpenCV for image processing; acquiring a black, white and gray scale image output by the OpenCV and acquiring a pixel matrix of the black, white and gray scale image; calculating the shortest sub-array needing to be sequenced in the pixel matrix; determining a target pixel corresponding to the shortest sub-array in the pixel matrix; and extracting the outline of the black, white and gray scale image according to the target pixel to obtain a target image. The method and the device can accurately extract the outline in the image.

Description

Image contour extraction method based on artificial intelligence and related equipment
Technical Field
The invention relates to the technical field of artificial intelligence, in particular to an image contour extraction method and device based on artificial intelligence, electronic equipment and a storage medium.
Background
Currently, visual recognition is usually adopted for image matting, but traditional visual recognition is only a recognition mechanism regardless of an AI algorithm or a training library, and the last step is realized through OpenCV. During OpenCV image recognition, black, white and gray three-color removal is firstly carried out on the image to determine an approximate range, then approximate naked eye interception is carried out in a mask mode manually, but the manual determination of the pixel points on the boundary is very time-consuming. In addition, the pixel points of the manually determined boundary are not accurate, which results in that the outline of the extracted image is fuzzy.
Disclosure of Invention
In view of the foregoing, it is desirable to provide an image contour extraction method, an image contour extraction apparatus, an electronic device, and a storage medium based on artificial intelligence, which can accurately extract a contour in an image.
The first aspect of the invention provides an image contour extraction method based on artificial intelligence, which comprises the following steps:
responding to the contour extraction instruction, and inputting the image to be processed into OpenCV for image processing;
acquiring a black, white and gray scale image output by the OpenCV and acquiring a pixel matrix of the black, white and gray scale image;
calculating the shortest sub-array needing to be sequenced in the pixel matrix;
determining a target pixel corresponding to the shortest sub-array in the pixel matrix;
and extracting the outline of the black, white and gray scale image according to the target pixel to obtain a target image.
In an optional embodiment, the calculating the shortest sub-array to be sorted in the pixel matrix includes:
initializing a first variable and a second variable;
arranging the pixel matrix into a pixel vector;
traversing the pixel vector from right to left, storing a first traversed pixel value as a first minimum value, continuously traversing the pixel vector to left, updating the currently traversed pixel value to the first minimum value if the currently traversed pixel value is smaller than the first minimum value, and updating the first variable to be a first index position of the first minimum value in the pixel vector if the currently traversed pixel value is larger than the first minimum value;
traversing the pixel vector from left to right, storing the traversed first pixel value as a first maximum value, continuing traversing the pixel vector to the right, if the currently traversed pixel value is greater than the first maximum value, updating the currently traversed pixel value to be the first maximum value, and if the currently traversed pixel value is less than the first maximum value, updating the second variable to be a second index position of the first maximum value in the pixel vector;
and determining the shortest sub-array according to the updated first variable and the second variable.
In an optional embodiment, the method further comprises:
obtaining a first right pixel value located on the right side of the first minimum value in the pixel vector;
judging whether a first target pixel value larger than the first right pixel value exists in the shortest sub-array or not;
when a first target pixel value larger than the first right pixel value exists in the shortest sub-array, reading a first maximum value in the shortest sub-array;
traversing the pixel vector to the right starting from the first minimum;
if the pixel value of the current traversal is larger than the first maximum value, acquiring a first left pixel value positioned on the left side of the pixel value of the current traversal in the pixel vector;
updating the first variable to a third indexed position of the first left pixel value in the pixel vector.
In an optional embodiment, the determining whether there is a first target pixel value greater than the first right pixel value in the shortest sub-array includes:
traversing the pixel vector to the left starting from the first minimum value, comparing the traversed pixel value with the first right pixel value;
when the traversed pixel value is larger than the first right pixel value, determining that a first target pixel value larger than the first right pixel value exists in the shortest sub-array;
and when the traversed pixel value is smaller than the first right pixel value, continuing traversing the pixel vector leftwards until the first maximum value is traversed, and when the first maximum value is smaller than the first right pixel value, determining that no first target pixel value larger than the first right pixel value exists in the shortest sub-array.
In an optional embodiment, the method further comprises:
obtaining a second left pixel value located to the left of the first maximum value in the pixel vector;
judging whether a second target pixel value smaller than the second left pixel value exists in the shortest sub-array or not;
when a second target pixel value smaller than the second left pixel value exists in the shortest sub-array, reading a first minimum value in the shortest sub-array;
traversing the pixel vector to the left starting from the first maximum;
if the pixel value of the current traversal is smaller than the first minimum value, acquiring a second right pixel value positioned on the right side of the pixel value of the current traversal in the pixel vector;
updating the second variable to be a fourth index position of the second right pixel value in the pixel vector.
In an optional embodiment, the determining whether there is a second target pixel value smaller than the second left pixel value in the shortest sub-array includes:
traversing the pixel vector to the right starting from the first maximum, comparing the traversed pixel value with the second left pixel value;
when the traversed pixel value is smaller than the second left pixel value, determining that a second target pixel value smaller than the second left pixel value exists in the shortest sub-array;
and when the traversed pixel value is larger than the first minimum value, continuing traversing the pixel vector rightwards until the first minimum value is traversed, and when the first minimum value is larger than the second left pixel value, determining that no second target pixel value larger than the second left pixel value exists in the shortest sub-array.
In an optional embodiment, after obtaining the target image, the method further comprises:
searching in a search server according to the target image to obtain a plurality of candidate search images;
calculating the similarity between each candidate search image and the target image;
obtaining the maximum similarity in the plurality of similarities;
and determining the candidate search image corresponding to the maximum similarity as a target search image.
A second aspect of the present invention provides an artificial intelligence-based image contour extraction apparatus, the apparatus comprising:
the processing module is used for responding to the contour extraction instruction and inputting the image to be processed into OpenCV for image processing;
an obtaining module, configured to obtain a black-white-gray scale image output by the OpenCV, and obtain a pixel matrix of the black-white-gray scale image;
the calculation module is used for calculating the shortest sub-array needing to be sequenced in the pixel matrix;
the determining module is used for determining a target pixel corresponding to the shortest sub-array in the pixel matrix;
and the extraction module is used for extracting the outline of the black, white and gray scale image according to the target pixel to obtain a target image.
A third aspect of the invention provides an electronic device comprising a processor for implementing the artificial intelligence based image contour extraction method when executing a computer program stored in a memory.
A fourth aspect of the present invention provides a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, implements the artificial intelligence based image contour extraction method.
In summary, the image contour extraction method, the image contour extraction device, the electronic device and the storage medium based on artificial intelligence according to the present invention can obtain a distortion-free black-white-gray scale image by processing the image through OpenCV, so as to calculate the shortest sub-array to be sorted in the pixel matrix corresponding to the black-white-gray scale image, and the shortest sub-array determines the change of the pixel boundary in the black-white-gray scale image, so that the accuracy of determining the boundary is higher, and the extracted contour is more accurate.
Drawings
Fig. 1 is a flowchart of an artificial intelligence-based image contour extraction method according to an embodiment of the present invention.
Fig. 2 is a structural diagram of an artificial intelligence-based image contour extraction apparatus according to a second embodiment of the present invention.
Fig. 3 is a schematic structural diagram of an electronic device according to a third embodiment of the present invention.
Detailed Description
In order that the above objects, features and advantages of the present invention can be more clearly understood, a detailed description of the present invention will be given below with reference to the accompanying drawings and specific embodiments. It should be noted that the embodiments of the present invention and features of the embodiments may be combined with each other without conflict.
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs. The terminology used herein in the description of the invention is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention.
The image contour extraction method based on artificial intelligence provided by the embodiment of the invention is executed by electronic equipment, and correspondingly, the image contour extraction device based on artificial intelligence is operated in the electronic equipment.
Example one
Fig. 1 is a flowchart of an artificial intelligence-based image contour extraction method according to an embodiment of the present invention.
The image processing method and the image processing device can process the image based on an artificial intelligence technology, so that the outline in the image is extracted. Among them, Artificial Intelligence (AI) is a theory, method, technique and application system that simulates, extends and expands human Intelligence using a digital computer or a machine controlled by a digital computer, senses the environment, acquires knowledge and uses the knowledge to obtain the best result.
The artificial intelligence infrastructure generally includes technologies such as sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technologies, operation/interaction systems, mechatronics, and the like. The artificial intelligence software technology mainly comprises a computer vision technology, a robot technology, a biological recognition technology, a voice processing technology, a natural language processing technology, machine learning/deep learning and the like.
The image contour extraction method based on artificial intelligence specifically comprises the following steps, and the sequence of the steps in the flowchart can be changed and some steps can be omitted according to different requirements.
And S11, responding to the contour extraction instruction, and inputting the image to be processed into OpenCV for image processing.
The image referred to in this embodiment is an RGB image.
The contour extraction instruction can be triggered manually by a user or automatically when the image to be processed is acquired.
After the contour extraction instruction is triggered, the image to be processed is loaded into an OpenCV (open Source Computer Vision library), and the image to be processed is processed by means of the OpenCV.
OpenCV is an open-source, free computer vision library. The method includes the steps that OpenCV is installed in computer equipment in advance, environment variables are configured, and processing of an image to be processed in OpenCV refers to the fact that the image to be processed is processed by calling an image processing function in OpenCV through the computer equipment.
And S12, acquiring a black-white-gray scale image output by the OpenCV and acquiring a pixel matrix of the black-white-gray scale image.
After image processing is performed by OpenCV, an image to be processed is changed into an image of three color levels of black, white and gray, and is output. The image of three levels of black, white and gray output by OpenCV is called a black-white-gray level image. The black pixels are marked as (0, 0, 0), the gray pixels are marked as (120, 120, 120), and the white pixels are marked as (255, 255, 255).
One two-dimensional image corresponds to one two-dimensional matrix, and pixel values of pixel points of the two-dimensional image are read out and written into a predefined array. In the embodiment, the shortest sub-array needing to be sorted is determined by means of the idea of sorting the arrays from small to large, so that the boundary point is determined according to the shortest sub-array.
And S13, calculating the shortest sub-array needing to be sorted in the pixel matrix.
After determining the approximate outline of the target object in the image, the conventional method is to change the background to white and the foreground to black, but this method cannot perform accurate positioning of the outline, and generally the stroke and the back boundary are not very accurate aiming points when changing.
In an optional embodiment, the calculating the shortest sub-array to be sorted in the pixel matrix includes:
initializing a first variable and a second variable;
arranging the pixel matrix into a pixel vector;
traversing the pixel vector from right to left, storing a first traversed pixel value as a first minimum value, continuously traversing the pixel vector to left, updating the currently traversed pixel value to the first minimum value if the currently traversed pixel value is smaller than the first minimum value, and updating the first variable to be a first index position of the first minimum value in the pixel vector if the currently traversed pixel value is larger than the first minimum value;
traversing the pixel vector from left to right, storing the traversed first pixel value as a first maximum value, continuing traversing the pixel vector to the right, if the currently traversed pixel value is greater than the first maximum value, updating the currently traversed pixel value to be the first maximum value, and if the currently traversed pixel value is less than the first maximum value, updating the second variable to be a second index position of the first maximum value in the pixel vector;
and determining the shortest sub-array according to the updated first variable and the second variable.
The first variable initialized may be denoted as X1 and the second variable initialized may be denoted as X2.
A two-dimensional pixel matrix is arranged as a one-dimensional pixel vector in left-to-right and top-to-bottom order.
And when the traversed second pixel value is smaller than the stored first minimum value, updating the traversed second pixel value to the first minimum value for the first time. And if the traversed third pixel value is smaller than the first minimum value after the first updating, updating the traversed third pixel value to the first minimum value for the second time. And if the traversed third pixel value is larger than the first minimum value after the first updating, updating the first index position of the traversed second pixel value in the pixel vector as a first variable.
And when the traversed second pixel value is larger than the stored first maximum value, updating the traversed second pixel value to the first maximum value for the first time. And if the traversed third pixel value is larger than the first maximum value after the first time of updating, updating the traversed third pixel value to the first maximum value for the second time. And if the traversed third pixel value is smaller than the first maximum value after the first updating, updating a second index position of the traversed second pixel value in the pixel vector to be a second variable.
The shortest subarray is a pixel value between the first variable and the second variable.
In this embodiment, if the currently traversed pixel value is greater than the first minimum value, it is indicated that, if the pixel value is to be ordered, the first minimum value should be located on the left side of the currently traversed pixel value, and at this time, the first minimum value is located on the right side of the currently traversed pixel value, so that the first variable needs to be updated. That is, the first variable is the location responsible for recording the case where disorder occurs to the far right. Similarly, if the currently traversed pixel value is smaller than the first maximum value, it indicates that the first maximum value should be located on the right of the currently traversed pixel value if ordering is required, and at this time, the first maximum value is located on the left of the currently traversed pixel value, so that the second variable needs to be updated. That is, the second variable is the position responsible for recording the situation where disorder occurs to the far left.
Illustratively, given an unordered array arr ═ 1, 5, 3, 4, 2, 6, 7, since 2 < 6, and 2 is less than 4, the index position where the first variable is 2 is updated, and since 5 > 1, and 5 > 3, the index position where the second variable is 5 is updated, the shortest sub-path in the unordered array is [5, 3, 4, 2], i.e., [5, 3, 4, 2] needs to be sorted. Calibrating the pixel value corresponding to the shortest sub-path is equivalent to calibrating the boundary in the image.
It should be understood that there is no absolute magnitude relationship between the first minimum and the first maximum, both being extreme values, and the first minimum may be greater than the first maximum.
In other embodiments, the pixel vector may be traversed from right to left and from right to left, and the parallel execution may improve the efficiency of traversal, thereby improving the efficiency of determining the shortest sub-array.
In an optional embodiment, the method further comprises:
obtaining a first right pixel value located on the right side of the first minimum value in the pixel vector;
judging whether a first target pixel value larger than the first right pixel value exists in the shortest sub-array or not;
when a first target pixel value larger than the first right pixel value exists in the shortest sub-array, reading a first maximum value in the shortest sub-array;
traversing the pixel vector to the right starting from the first minimum;
if the pixel value of the current traversal is larger than the first maximum value, acquiring a first left pixel value positioned on the left side of the pixel value of the current traversal in the pixel vector;
updating the first variable to a third indexed position of the first left pixel value in the pixel vector.
Wherein the first right pixel value is a pixel value in the pixel vector immediately to the right of the first minimum value. The first right pixel value is the minimum of all pixel values in the pixel vector that are located to the right of the first minimum value.
And reading a first maximum value in the shortest sub-array and traversing the pixel vector one by one from the first minimum value to the right as long as a first target pixel value larger than the first right pixel value is determined in the shortest sub-array, which indicates that the pixel vector has unordered pixel values besides the shortest sub-array. And if the pixel value traversed at present is smaller than the first maximum value, continuing to traverse the pixel vector rightwards until the pixel value traversed rightwards is larger than the first maximum value. When traversing to the pixel value larger than the first maximum value in the pixel vector to the right, acquiring a first left pixel value positioned at the left of the currently traversed pixel value in the pixel vector, so as to update the first variable to be a third index position of the first left pixel value in the pixel vector, and further updating the shortest sub-array according to the currently updated first variable.
In an optional embodiment, the determining whether there is a first target pixel value greater than the first right pixel value in the shortest sub-array includes:
traversing the pixel vector to the left starting from the first minimum value, comparing the traversed pixel value with the first right pixel value;
when the traversed pixel value is larger than the first right pixel value, determining that a first target pixel value larger than the first right pixel value exists in the shortest sub-array;
and when the traversed pixel value is smaller than the first right pixel value, continuing traversing the pixel vector leftwards until the first maximum value is traversed, and when the first maximum value is smaller than the first right pixel value, determining that no first target pixel value larger than the first right pixel value exists in the shortest sub-array.
For example, assuming that the pixel vector a1 is [1, 7, 2, 6, 3, 4, 5, 8], the first minimum value is 3, and the first maximum value is 7, the shortest sub-path is determined to be [7, 2, 6, 3], the first right pixel value 4 to the right of the first minimum value 3 traverses the shortest sub-path from the first minimum value 3 to the left, and the pixel value 6 in the shortest sub-path is greater than the first right pixel value 4, and the first target pixel value greater than the first right pixel value in the shortest sub-array is determined.
In this optional embodiment, it is only necessary to determine that the first target pixel value greater than the first right pixel value exists in the shortest sub-array, that is, it may be determined that unordered pixel values exist in pixel values other than the shortest sub-path in the pixel vector, and then the shortest sub-path needs to be further updated.
For example, after determining that there is a first target pixel value greater than the first right pixel value in the shortest sub-array, reading a first maximum value 7 in the shortest sub-array, traversing pixel vector a1 to the right from a first minimum value of 3, and continuing to traverse pixel value 8 in the pixel vector to the right since pixel values 4 and 5 in the pixel vector traversed to the right are both less than the first maximum value of 7, and pixel value 8 is greater than the first maximum value of 7, updating a third index position where a first left pixel value 5 located to the left of the currently traversed pixel value 8 is located as a first variable, and updating a first shortest path as [7, 2, 6, 3, 4, 5 ].
In an optional embodiment, the method further comprises:
obtaining a second left pixel value located to the left of the first maximum value in the pixel vector;
judging whether a second target pixel value smaller than the second left pixel value exists in the shortest sub-array or not;
when a second target pixel value smaller than the second left pixel value exists in the shortest sub-array, reading a first minimum value in the shortest sub-array;
traversing the pixel vector to the left starting from the first maximum;
if the pixel value of the current traversal is smaller than the first minimum value, acquiring a second right pixel value positioned on the right side of the pixel value of the current traversal in the pixel vector;
updating the second variable to be a fourth index position of the second right pixel value in the pixel vector.
Wherein the second left pixel value is the pixel value in the pixel vector immediately to the left of the first maximum. The second left pixel value is the largest of all pixel values in the pixel vector that are to the right of the first maximum value.
As long as it is determined that there is a second target pixel value smaller than the second left pixel value in the shortest sub-array, it indicates that there are unordered pixel values in the pixel vector in addition to the shortest sub-array, and thus the first minimum value in the shortest sub-array is read and the pixel vector is traversed one by one to the left starting from the first maximum value. And if the pixel value traversed at present is larger than the first minimum value, continuing to traverse the pixel vector leftwards until the pixel value traversed leftwards is smaller than the first minimum value. And when traversing to the pixel value smaller than the first minimum value in the pixel vector leftwards, acquiring a second right pixel value positioned at the right side of the currently traversed pixel value in the pixel vector, so as to update the second variable to be a fourth index position of the second right pixel value in the pixel vector, and further updating the shortest sub-array according to the currently updated second variable.
In an optional embodiment, the determining whether there is a second target pixel value smaller than the second left pixel value in the shortest sub-array includes:
traversing the pixel vector to the right starting from the first maximum, comparing the traversed pixel value with the second left pixel value;
when the traversed pixel value is smaller than the second left pixel value, determining that a second target pixel value smaller than the second left pixel value exists in the shortest sub-array;
and when the traversed pixel value is larger than the first minimum value, continuing traversing the pixel vector rightwards until the first minimum value is traversed, and when the first minimum value is larger than the second left pixel value, determining that no second target pixel value larger than the second left pixel value exists in the shortest sub-array.
For example, assuming that the pixel vector a2 is [1, 4, 7, 3, 2, 5, 6, 8], the first minimum value is 2 and the first maximum value is 7, the shortest sub-path is determined to be [7, 3, 2], the second left pixel value 4 to the left of the first maximum value 7 traverses the shortest sub-path from the first maximum value 7 to the right, and the pixel value 3 in the shortest sub-path is smaller than the second left pixel value 4, and the second target pixel value smaller than the second left pixel value 4 in the shortest sub-array is determined.
In this optional embodiment, it is only necessary to determine that there is a second target pixel value smaller than the second left pixel value 4 in the shortest sub-array, that is, it may be determined that there is an unordered pixel value in the pixel values of the pixel vector except for the shortest sub-path, and the shortest sub-path needs to be further updated.
For example, after determining that there is a second target pixel value greater than the second left pixel value in the shortest sub-array, reading a first minimum value 2 in the shortest sub-array, traversing pixel vector a2 leftward from a first maximum value 7, and continuing traversing pixel value 1 in the pixel vector leftward since pixel value 4 in the pixel vector traversed leftward is greater than the first minimum value 2, and updating a fourth index position where a second right pixel value 4 located right of the currently traversed pixel value 1 is located as a second variable, where the first shortest path is updated to [4, 7, 3, 2], and pixel value 1 is less than the first minimum value 2.
For another example, for the pixel vector [1, 4, 7, 3, 2, 5, 6, 8], since the first minimum value is 2 and the first maximum value is 7, the determined shortest sub-path is [7, 3, 2], the first right pixel value located on the right side of the first minimum value 2 in the pixel vector is 5, the second left pixel value located on the left side of the first maximum value 7 in the pixel vector is 4, and since the shortest sub-path not only has the first target pixel value greater than the first right pixel value 5 but also has the second target pixel value less than the second left pixel value 4, the process of the above embodiment is adopted, and the finally determined shortest sub-path is [4, 7, 3, 2, 5, 6 ].
And S14, determining the corresponding target pixel of the shortest sub-array in the pixel matrix.
Any pixel value in the shortest sub-array is necessarily smaller than the number on the left side in the pixel vector and larger than the number on the right side of the pixel vector.
And reducing the pixel vector into a pixel matrix, determining the position of the shortest sub-array in the pixel matrix, and determining the position of the target pixel in the pixel matrix according to the position of the shortest sub-array.
And S15, extracting the outline of the black-white-gray scale image according to the target pixel to obtain a target image.
And dividing the boundary point of the contour of the target object by using the position of the target pixel, and taking the obtained image as an image of the target object, namely the target image.
The target object is extracted from the black, white and gray scale image, and can be used by professional and non-professional people, and the extracted target object can also be used as a video title.
In an optional embodiment, after obtaining the target image, the method further comprises:
searching in a search server according to the target image to obtain a plurality of candidate search images;
calculating the similarity between each candidate search image and the target image;
obtaining the maximum similarity in the plurality of similarities;
and determining the candidate search image corresponding to the maximum similarity as a target search image.
The search server stores a large number of images in advance, and a plurality of candidate search images are retrieved from the search server in response to a search instruction input by a user. In order to further determine the most similar target search image from the plurality of candidate search images, the size normalization is performed on each candidate search image according to the size of the target image, so that the target image and each candidate search image have the same size, and the similarity is convenient to calculate.
The calculation of the similarity is the prior art, and for example, the similarity between the target image and the candidate search image may be calculated by calculating a euclidean distance or a cosine angle between the target image and the candidate search image. The greater the similarity, the closer the corresponding candidate search image is to the target image. The smaller the similarity, the farther away the corresponding candidate search image is from the target image.
In other embodiments, the retrieval may be performed in the played video according to the target image, for example, each frame of the played video is extracted to obtain a plurality of frame images, then the similarity between each frame image and the target image is calculated, and the frame image with the similarity greater than a preset similarity threshold is used as the target frame image, so that only the target frame image is played. Therefore, the method and the device can improve the picture of the content needing to be watched in the played video watched by the user, and improve the playing efficiency.
According to the image contour extraction method based on artificial intelligence, provided by the invention, the image is processed through OpenCV, and a distortion-free black, white and gray scale image can be obtained, so that the shortest sub-array needing to be sequenced in the pixel matrix corresponding to the black, white and gray scale image is calculated, the shortest sub-array determines the change of the pixel boundary in the black, white and gray scale image, the accuracy rate of determining the boundary is higher, and the extracted contour is more accurate.
Example two
Fig. 2 is a structural diagram of an artificial intelligence-based image contour extraction apparatus according to a second embodiment of the present invention.
In some embodiments, the artificial intelligence based image contour extraction device 20 may include a plurality of functional modules composed of computer program segments. The computer program of each program segment in the artificial intelligence based image contour extraction apparatus 20 can be stored in a memory of an electronic device and executed by at least one processor to perform (see detailed description of fig. 1) the functions of artificial intelligence based image contour extraction.
In this embodiment, the image contour extraction device 20 based on artificial intelligence can be divided into a plurality of functional modules according to the functions performed by the device. The functional module may include: the system comprises a processing module 201, an acquisition module 202, a calculation module 203, a determination module 204, an extraction module 205 and a search module 206. The module referred to herein is a series of computer program segments capable of being executed by at least one processor and capable of performing a fixed function and is stored in memory. In the present embodiment, the functions of the modules will be described in detail in the following embodiments.
The processing module 201 is configured to, in response to the contour extraction instruction, input the image to be processed into OpenCV for image processing.
The image referred to in this embodiment is an RGB image.
The contour extraction instruction can be triggered manually by a user or automatically when the image to be processed is acquired.
After the contour extraction instruction is triggered, the image to be processed is loaded into an OpenCV (open Source Computer Vision library), and the image to be processed is processed by means of the OpenCV.
OpenCV is an open-source, free computer vision library. The method includes the steps that OpenCV is installed in computer equipment in advance, environment variables are configured, and processing of an image to be processed in OpenCV refers to the fact that the image to be processed is processed by calling an image processing function in OpenCV through the computer equipment.
The obtaining module 202 is configured to obtain a black-white-gray scale image output by the OpenCV, and obtain a pixel matrix of the black-white-gray scale image.
After image processing is performed by OpenCV, an image to be processed is changed into an image of three color levels of black, white and gray, and is output. The image of three levels of black, white and gray output by OpenCV is called a black-white-gray level image. The black pixels are marked as (0, 0, 0), the gray pixels are marked as (120, 120, 120), and the white pixels are marked as (255, 255, 255).
One two-dimensional image corresponds to one two-dimensional matrix, and pixel values of pixel points of the two-dimensional image are read out and written into a predefined array. In the embodiment, the shortest sub-array needing to be sorted is determined by means of the idea of sorting the arrays from small to large, so that the boundary point is determined according to the shortest sub-array.
The calculating module 203 is configured to calculate a shortest sub-array that needs to be sorted in the pixel matrix.
After determining the approximate outline of the target object in the image, the conventional method is to change the background to white and the foreground to black, but this method cannot perform accurate positioning of the outline, and generally the stroke and the back boundary are not very accurate aiming points when changing.
In an optional embodiment, the calculating module 203 calculates the shortest sub-array to be sorted in the pixel matrix includes:
initializing a first variable and a second variable;
arranging the pixel matrix into a pixel vector;
traversing the pixel vector from right to left, storing a first traversed pixel value as a first minimum value, continuously traversing the pixel vector to left, updating the currently traversed pixel value to the first minimum value if the currently traversed pixel value is smaller than the first minimum value, and updating the first variable to be a first index position of the first minimum value in the pixel vector if the currently traversed pixel value is larger than the first minimum value;
traversing the pixel vector from left to right, storing the traversed first pixel value as a first maximum value, continuing traversing the pixel vector to the right, if the currently traversed pixel value is greater than the first maximum value, updating the currently traversed pixel value to be the first maximum value, and if the currently traversed pixel value is less than the first maximum value, updating the second variable to be a second index position of the first maximum value in the pixel vector;
and determining the shortest sub-array according to the updated first variable and the second variable.
The first variable initialized may be denoted as X1 and the second variable initialized may be denoted as X2.
A two-dimensional pixel matrix is arranged as a one-dimensional pixel vector in left-to-right and top-to-bottom order.
And when the traversed second pixel value is smaller than the stored first minimum value, updating the traversed second pixel value to the first minimum value for the first time. And if the traversed third pixel value is smaller than the first minimum value after the first updating, updating the traversed third pixel value to the first minimum value for the second time. And if the traversed third pixel value is larger than the first minimum value after the first updating, updating the first index position of the traversed second pixel value in the pixel vector as a first variable.
And when the traversed second pixel value is larger than the stored first maximum value, updating the traversed second pixel value to the first maximum value for the first time. And if the traversed third pixel value is larger than the first maximum value after the first time of updating, updating the traversed third pixel value to the first maximum value for the second time. And if the traversed third pixel value is smaller than the first maximum value after the first updating, updating a second index position of the traversed second pixel value in the pixel vector to be a second variable.
The shortest subarray is a pixel value between the first variable and the second variable.
In this embodiment, if the currently traversed pixel value is greater than the first minimum value, it is indicated that, if the pixel value is to be ordered, the first minimum value should be located on the left side of the currently traversed pixel value, and at this time, the first minimum value is located on the right side of the currently traversed pixel value, so that the first variable needs to be updated. That is, the first variable is the location responsible for recording the case where disorder occurs to the far right. Similarly, if the currently traversed pixel value is smaller than the first maximum value, it indicates that the first maximum value should be located on the right of the currently traversed pixel value if ordering is required, and at this time, the first maximum value is located on the left of the currently traversed pixel value, so that the second variable needs to be updated. That is, the second variable is the position responsible for recording the situation where disorder occurs to the far left.
Illustratively, given an unordered array arr ═ 1, 5, 3, 4, 2, 6, 7, since 2 < 6, and 2 is less than 4, the index position where the first variable is 2 is updated, and since 5 > 1, and 5 > 3, the index position where the second variable is 5 is updated, the shortest sub-path in the unordered array is [5, 3, 4, 2], i.e., [5, 3, 4, 2] needs to be sorted. Calibrating the pixel value corresponding to the shortest sub-path is equivalent to calibrating the boundary in the image.
It should be understood that there is no absolute magnitude relationship between the first minimum and the first maximum, both being extreme values, and the first minimum may be greater than the first maximum.
In other embodiments, the pixel vector may be traversed from right to left and from right to left, and the parallel execution may improve the efficiency of traversal, thereby improving the efficiency of determining the shortest sub-array.
In an optional embodiment, the calculation module 203 is further configured to:
obtaining a first right pixel value located on the right side of the first minimum value in the pixel vector;
judging whether a first target pixel value larger than the first right pixel value exists in the shortest sub-array or not;
when a first target pixel value larger than the first right pixel value exists in the shortest sub-array, reading a first maximum value in the shortest sub-array;
traversing the pixel vector to the right starting from the first minimum;
if the pixel value of the current traversal is larger than the first maximum value, acquiring a first left pixel value positioned on the left side of the pixel value of the current traversal in the pixel vector;
updating the first variable to a third indexed position of the first left pixel value in the pixel vector.
Wherein the first right pixel value is a pixel value in the pixel vector immediately to the right of the first minimum value. The first right pixel value is the minimum of all pixel values in the pixel vector that are located to the right of the first minimum value.
And reading a first maximum value in the shortest sub-array and traversing the pixel vector one by one from the first minimum value to the right as long as a first target pixel value larger than the first right pixel value is determined in the shortest sub-array, which indicates that the pixel vector has unordered pixel values besides the shortest sub-array. And if the pixel value traversed at present is smaller than the first maximum value, continuing to traverse the pixel vector rightwards until the pixel value traversed rightwards is larger than the first maximum value. When traversing to the pixel value larger than the first maximum value in the pixel vector to the right, acquiring a first left pixel value positioned at the left of the currently traversed pixel value in the pixel vector, so as to update the first variable to be a third index position of the first left pixel value in the pixel vector, and further updating the shortest sub-array according to the currently updated first variable.
In an optional embodiment, the determining whether there is a first target pixel value greater than the first right pixel value in the shortest sub-array includes:
traversing the pixel vector to the left starting from the first minimum value, comparing the traversed pixel value with the first right pixel value;
when the traversed pixel value is larger than the first right pixel value, determining that a first target pixel value larger than the first right pixel value exists in the shortest sub-array;
and when the traversed pixel value is smaller than the first right pixel value, continuing traversing the pixel vector leftwards until the first maximum value is traversed, and when the first maximum value is smaller than the first right pixel value, determining that no first target pixel value larger than the first right pixel value exists in the shortest sub-array.
For example, assuming that the pixel vector a1 is [1, 7, 2, 6, 3, 4, 5, 8], the first minimum value is 3, and the first maximum value is 7, the shortest sub-path is determined to be [7, 2, 6, 3], the first right pixel value 4 to the right of the first minimum value 3 traverses the shortest sub-path from the first minimum value 3 to the left, and the pixel value 6 in the shortest sub-path is greater than the first right pixel value 4, and the first target pixel value greater than the first right pixel value in the shortest sub-array is determined.
In this optional embodiment, it is only necessary to determine that the first target pixel value greater than the first right pixel value exists in the shortest sub-array, that is, it may be determined that unordered pixel values exist in pixel values other than the shortest sub-path in the pixel vector, and then the shortest sub-path needs to be further updated.
For example, after determining that there is a first target pixel value greater than the first right pixel value in the shortest sub-array, reading a first maximum value 7 in the shortest sub-array, traversing pixel vector a1 to the right from a first minimum value of 3, and continuing to traverse pixel value 8 in the pixel vector to the right since pixel values 4 and 5 in the pixel vector traversed to the right are both less than the first maximum value of 7, and pixel value 8 is greater than the first maximum value of 7, updating a third index position where a first left pixel value 5 located to the left of the currently traversed pixel value 8 is located as a first variable, and updating a first shortest path as [7, 2, 6, 3, 4, 5 ].
In an optional embodiment, the calculation module 203 is further configured to:
obtaining a second left pixel value located to the left of the first maximum value in the pixel vector;
judging whether a second target pixel value smaller than the second left pixel value exists in the shortest sub-array or not;
when a second target pixel value smaller than the second left pixel value exists in the shortest sub-array, reading a first minimum value in the shortest sub-array;
traversing the pixel vector to the left starting from the first maximum;
if the pixel value of the current traversal is smaller than the first minimum value, acquiring a second right pixel value positioned on the right side of the pixel value of the current traversal in the pixel vector;
updating the second variable to be a fourth index position of the second right pixel value in the pixel vector.
Wherein the second left pixel value is the pixel value in the pixel vector immediately to the left of the first maximum. The second left pixel value is the largest of all pixel values in the pixel vector that are to the right of the first maximum value.
As long as it is determined that there is a second target pixel value smaller than the second left pixel value in the shortest sub-array, it indicates that there are unordered pixel values in the pixel vector in addition to the shortest sub-array, and thus the first minimum value in the shortest sub-array is read and the pixel vector is traversed one by one to the left starting from the first maximum value. And if the pixel value traversed at present is larger than the first minimum value, continuing to traverse the pixel vector leftwards until the pixel value traversed leftwards is smaller than the first minimum value. And when traversing to the pixel value smaller than the first minimum value in the pixel vector leftwards, acquiring a second right pixel value positioned at the right side of the currently traversed pixel value in the pixel vector, so as to update the second variable to be a fourth index position of the second right pixel value in the pixel vector, and further updating the shortest sub-array according to the currently updated second variable.
In an optional embodiment, the determining whether there is a second target pixel value smaller than the second left pixel value in the shortest sub-array includes:
traversing the pixel vector to the right starting from the first maximum, comparing the traversed pixel value with the second left pixel value;
when the traversed pixel value is smaller than the second left pixel value, determining that a second target pixel value smaller than the second left pixel value exists in the shortest sub-array;
and when the traversed pixel value is larger than the first minimum value, continuing traversing the pixel vector rightwards until the first minimum value is traversed, and when the first minimum value is larger than the second left pixel value, determining that no second target pixel value larger than the second left pixel value exists in the shortest sub-array.
For example, assuming that the pixel vector a2 is [1, 4, 7, 3, 2, 5, 6, 8], the first minimum value is 2 and the first maximum value is 7, the shortest sub-path is determined to be [7, 3, 2], the second left pixel value 4 to the left of the first maximum value 7 traverses the shortest sub-path from the first maximum value 7 to the right, and the pixel value 3 in the shortest sub-path is smaller than the second left pixel value 4, and the second target pixel value smaller than the second left pixel value 4 in the shortest sub-array is determined.
In this optional embodiment, it is only necessary to determine that there is a second target pixel value smaller than the second left pixel value 4 in the shortest sub-array, that is, it may be determined that there is an unordered pixel value in the pixel values of the pixel vector except for the shortest sub-path, and the shortest sub-path needs to be further updated.
For example, after determining that there is a second target pixel value greater than the second left pixel value in the shortest sub-array, reading a first minimum value 2 in the shortest sub-array, traversing pixel vector a2 leftward from a first maximum value 7, and continuing traversing pixel value 1 in the pixel vector leftward since pixel value 4 in the pixel vector traversed leftward is greater than the first minimum value 2, and updating a fourth index position where a second right pixel value 4 located right of the currently traversed pixel value 1 is located as a second variable, where the first shortest path is updated to [4, 7, 3, 2], and pixel value 1 is less than the first minimum value 2.
For another example, for the pixel vector [1, 4, 7, 3, 2, 5, 6, 8], since the first minimum value is 2 and the first maximum value is 7, the determined shortest sub-path is [7, 3, 2], the first right pixel value located on the right side of the first minimum value 2 in the pixel vector is 5, the second left pixel value located on the left side of the first maximum value 7 in the pixel vector is 4, and since the shortest sub-path not only has the first target pixel value greater than the first right pixel value 5 but also has the second target pixel value less than the second left pixel value 4, the process of the above embodiment is adopted, and the finally determined shortest sub-path is [4, 7, 3, 2, 5, 6 ].
The determining module 204 is configured to determine a target pixel corresponding to the shortest sub-array in the pixel matrix.
Any pixel value in the shortest sub-array is necessarily smaller than the number on the left side in the pixel vector and larger than the number on the right side of the pixel vector.
And reducing the pixel vector into a pixel matrix, determining the position of the shortest sub-array in the pixel matrix, and determining the position of the target pixel in the pixel matrix according to the position of the shortest sub-array.
The extracting module 205 is configured to extract the outline of the black, white, and gray scale image according to the target pixel, so as to obtain a target image.
And dividing the boundary point of the contour of the target object by using the position of the target pixel, and taking the obtained image as an image of the target object, namely the target image.
The target object is extracted from the black, white and gray scale image, and can be used by professional and non-professional people, and the extracted target object can also be used as a video title.
In an alternative embodiment, after obtaining the target image, the search module 206 is configured to:
searching in a search server according to the target image to obtain a plurality of candidate search images;
calculating the similarity between each candidate search image and the target image;
obtaining the maximum similarity in the plurality of similarities;
and determining the candidate search image corresponding to the maximum similarity as a target search image.
The search server stores a large number of images in advance, and a plurality of candidate search images are retrieved from the search server in response to a search instruction input by a user. In order to further determine the most similar target search image from the plurality of candidate search images, the size normalization is performed on each candidate search image according to the size of the target image, so that the target image and each candidate search image have the same size, and the similarity is convenient to calculate.
The calculation of the similarity is the prior art, and for example, the similarity between the target image and the candidate search image may be calculated by calculating a euclidean distance or a cosine angle between the target image and the candidate search image. The greater the similarity, the closer the corresponding candidate search image is to the target image. The smaller the similarity, the farther away the corresponding candidate search image is from the target image.
In other embodiments, the retrieval may be performed in the played video according to the target image, for example, each frame of the played video is extracted to obtain a plurality of frame images, then the similarity between each frame image and the target image is calculated, and the frame image with the similarity greater than a preset similarity threshold is used as the target frame image, so that only the target frame image is played. Therefore, the method and the device can improve the picture of the content needing to be watched in the played video watched by the user, and improve the playing efficiency.
According to the image contour extraction device based on artificial intelligence, provided by the invention, the image is processed through OpenCV, and a distortion-free black, white and gray scale image can be obtained, so that the shortest sub-array needing to be sequenced in the pixel matrix corresponding to the black, white and gray scale image is calculated, the shortest sub-array determines the change of the pixel boundary in the black, white and gray scale image, the accuracy rate of determining the boundary is higher, and the extracted contour is more accurate.
EXAMPLE III
The present embodiment provides a computer-readable storage medium, which stores thereon a computer program, which when executed by a processor implements the steps in the above-mentioned artificial intelligence based image contour extraction method embodiment, such as S11-S15 shown in fig. 1:
s11, responding to the contour extraction instruction, and inputting the image to be processed into OpenCV for image processing;
s12, acquiring a black-white-gray scale image output by the OpenCV and acquiring a pixel matrix of the black-white-gray scale image;
s13, calculating the shortest sub-array needing to be sorted in the pixel matrix;
s14, determining a corresponding target pixel of the shortest sub-array in the pixel matrix;
and S15, extracting the outline of the black-white-gray scale image according to the target pixel to obtain a target image.
Alternatively, the computer program, when executed by the processor, implements the functions of the modules/units in the above-mentioned device embodiments, for example, the module 201 and 205 in fig. 2:
the processing module 201 is configured to respond to the contour extraction instruction, and input an image to be processed into OpenCV for image processing;
the obtaining module 202 is configured to obtain a black-white-gray scale image output by the OpenCV, and obtain a pixel matrix of the black-white-gray scale image;
the calculating module 203 is configured to calculate a shortest sub-array to be ordered in the pixel matrix;
the determining module 204 is configured to determine a target pixel corresponding to the shortest sub-array in the pixel matrix;
the extracting module 205 is configured to extract the outline of the black, white, and gray scale image according to the target pixel, so as to obtain a target image.
Example four
Fig. 3 is a schematic structural diagram of an electronic device according to a third embodiment of the present invention. In the preferred embodiment of the present invention, the electronic device 3 comprises a memory 31, at least one processor 32, at least one communication bus 33 and a transceiver 34.
It will be appreciated by those skilled in the art that the configuration of the electronic device shown in fig. 3 does not constitute a limitation of the embodiment of the present invention, and may be a bus-type configuration or a star-type configuration, and the electronic device 3 may include more or less other hardware or software than those shown, or a different arrangement of components.
In some embodiments, the electronic device 3 is a device capable of automatically performing numerical calculation and/or information processing according to instructions set or stored in advance, and the hardware thereof includes but is not limited to a microprocessor, an application specific integrated circuit, a programmable gate array, a digital processor, an embedded device, and the like. The electronic device 3 may also include a client device, which includes, but is not limited to, any electronic product that can interact with a client through a keyboard, a mouse, a remote controller, a touch pad, or a voice control device, for example, a personal computer, a tablet computer, a smart phone, a digital camera, and the like.
It should be noted that the electronic device 3 is only an example, and other existing or future electronic products, such as those that can be adapted to the present invention, should also be included in the scope of the present invention, and are included herein by reference.
In some embodiments, the memory 31 has stored therein a computer program which, when executed by the at least one processor 32, implements all or part of the steps of the artificial intelligence based image contour extraction method as described. The Memory 31 includes a Read-Only Memory (ROM), a Programmable Read-Only Memory (PROM), an Erasable Programmable Read-Only Memory (EPROM), a One-time Programmable Read-Only Memory (OTPROM), an electronically Erasable rewritable Read-Only Memory (Electrically-Erasable Programmable Read-Only Memory (EEPROM)), an optical Read-Only disk (CD-ROM) or other optical disk Memory, a magnetic disk Memory, a tape Memory, or any other medium readable by a computer capable of carrying or storing data.
Further, the computer-readable storage medium may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function, and the like; the storage data area may store data created according to the use of the blockchain node, and the like.
The block chain is a novel application mode of computer technologies such as distributed data storage, point-to-point transmission, a consensus mechanism, an encryption algorithm and the like. A block chain (Blockchain), which is essentially a decentralized database, is a series of data blocks associated by using a cryptographic method, and each data block contains information of a batch of network transactions, so as to verify the validity (anti-counterfeiting) of the information and generate a next block. The blockchain may include a blockchain underlying platform, a platform product service layer, an application service layer, and the like.
In some embodiments, the at least one processor 32 is a Control Unit (Control Unit) of the electronic device 3, connects various components of the electronic device 3 by various interfaces and lines, and executes various functions and processes data of the electronic device 3 by running or executing programs or modules stored in the memory 31 and calling data stored in the memory 31. For example, the at least one processor 32, when executing the computer program stored in the memory, implements all or part of the steps of the artificial intelligence based image contour extraction method described in the embodiments of the present invention; or realize all or part of the functions of the image contour extraction device based on artificial intelligence. The at least one processor 32 may be composed of an integrated circuit, for example, a single packaged integrated circuit, or may be composed of a plurality of integrated circuits packaged with the same or different functions, including one or more Central Processing Units (CPUs), microprocessors, digital Processing chips, graphics processors, and combinations of various control chips.
In some embodiments, the at least one communication bus 33 is arranged to enable connection communication between the memory 31 and the at least one processor 32 or the like.
Although not shown, the electronic device 3 may further include a power supply (such as a battery) for supplying power to each component, and preferably, the power supply may be logically connected to the at least one processor 32 through a power management device, so as to implement functions of managing charging, discharging, and power consumption through the power management device. The power supply may also include any component of one or more dc or ac power sources, recharging devices, power failure detection circuitry, power converters or inverters, power status indicators, and the like. The electronic device 3 may further include various sensors, a bluetooth module, a Wi-Fi module, and the like, which are not described herein again.
The integrated unit implemented in the form of a software functional module may be stored in a computer-readable storage medium. The software functional module is stored in a storage medium and includes several instructions to enable a computer device (which may be a personal computer, an electronic device, or a network device) or a processor (processor) to execute parts of the methods according to the embodiments of the present invention.
In the embodiments provided in the present invention, it should be understood that the disclosed apparatus and method may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the modules is only one logical functional division, and other divisions may be realized in practice.
The modules described as separate parts may or may not be physically separate, and parts displayed as modules may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment.
In addition, functional modules in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, or in a form of hardware plus a software functional module.
It will be evident to those skilled in the art that the invention is not limited to the details of the foregoing illustrative embodiments, and that the present invention may be embodied in other specific forms without departing from the spirit or essential attributes thereof. The present embodiments are therefore to be considered in all respects as illustrative and not restrictive, the scope of the invention being indicated by the appended claims rather than by the foregoing description, and all changes which come within the meaning and range of equivalency of the claims are therefore intended to be embraced therein. Any reference sign in a claim should not be construed as limiting the claim concerned. Furthermore, it is obvious that the word "comprising" does not exclude other elements or that the singular does not exclude the plural. A plurality of units or means recited in the specification may also be implemented by one unit or means through software or hardware. The terms first, second, etc. are used to denote names, but not any particular order.
Finally, it should be noted that the above embodiments are only for illustrating the technical solutions of the present invention and not for limiting, and although the present invention is described in detail with reference to the preferred embodiments, it should be understood by those skilled in the art that modifications or equivalent substitutions may be made on the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention.

Claims (10)

1. An image contour extraction method based on artificial intelligence is characterized by comprising the following steps:
responding to the contour extraction instruction, and inputting the image to be processed into OpenCV for image processing;
acquiring a black, white and gray scale image output by the OpenCV and acquiring a pixel matrix of the black, white and gray scale image;
calculating the shortest sub-array needing to be sequenced in the pixel matrix;
determining a target pixel corresponding to the shortest sub-array in the pixel matrix;
and extracting the outline of the black, white and gray scale image according to the target pixel to obtain a target image.
2. The artificial intelligence based image contour extraction method as claimed in claim 1, wherein said calculating the shortest sub-array to be sorted in the pixel matrix comprises:
initializing a first variable and a second variable;
arranging the pixel matrix into a pixel vector;
traversing the pixel vector from right to left, storing a first traversed pixel value as a first minimum value, continuously traversing the pixel vector to left, updating the currently traversed pixel value to the first minimum value if the currently traversed pixel value is smaller than the first minimum value, and updating the first variable to be a first index position of the first minimum value in the pixel vector if the currently traversed pixel value is larger than the first minimum value;
traversing the pixel vector from left to right, storing the traversed first pixel value as a first maximum value, continuing traversing the pixel vector to the right, if the currently traversed pixel value is greater than the first maximum value, updating the currently traversed pixel value to be the first maximum value, and if the currently traversed pixel value is less than the first maximum value, updating the second variable to be a second index position of the first maximum value in the pixel vector;
and determining the shortest sub-array according to the updated first variable and the second variable.
3. The artificial intelligence based image contour extraction method as claimed in claim 2, wherein said method further comprises:
obtaining a first right pixel value located on the right side of the first minimum value in the pixel vector;
judging whether a first target pixel value larger than the first right pixel value exists in the shortest sub-array or not;
when a first target pixel value larger than the first right pixel value exists in the shortest sub-array, reading a first maximum value in the shortest sub-array;
traversing the pixel vector to the right starting from the first minimum;
if the pixel value of the current traversal is larger than the first maximum value, acquiring a first left pixel value positioned on the left side of the pixel value of the current traversal in the pixel vector;
updating the first variable to a third indexed position of the first left pixel value in the pixel vector.
4. The artificial intelligence based image contour extraction method of claim 3, wherein said determining whether there is a first target pixel value greater than the first right pixel value in the shortest sub-array comprises:
traversing the pixel vector to the left starting from the first minimum value, comparing the traversed pixel value with the first right pixel value;
when the traversed pixel value is larger than the first right pixel value, determining that a first target pixel value larger than the first right pixel value exists in the shortest sub-array;
and when the traversed pixel value is smaller than the first right pixel value, continuing traversing the pixel vector leftwards until the first maximum value is traversed, and when the first maximum value is smaller than the first right pixel value, determining that no first target pixel value larger than the first right pixel value exists in the shortest sub-array.
5. The artificial intelligence based image contour extraction method as claimed in any one of claims 2 to 4, characterized in that said method further comprises:
obtaining a second left pixel value located to the left of the first maximum value in the pixel vector;
judging whether a second target pixel value smaller than the second left pixel value exists in the shortest sub-array or not;
when a second target pixel value smaller than the second left pixel value exists in the shortest sub-array, reading a first minimum value in the shortest sub-array;
traversing the pixel vector to the left starting from the first maximum;
if the pixel value of the current traversal is smaller than the first minimum value, acquiring a second right pixel value positioned on the right side of the pixel value of the current traversal in the pixel vector;
updating the second variable to be a fourth index position of the second right pixel value in the pixel vector.
6. The artificial intelligence based image contour extraction method of claim 5, wherein said determining whether there is a second target pixel value smaller than the second left pixel value in the shortest sub-array comprises:
traversing the pixel vector to the right starting from the first maximum, comparing the traversed pixel value with the second left pixel value;
when the traversed pixel value is smaller than the second left pixel value, determining that a second target pixel value smaller than the second left pixel value exists in the shortest sub-array;
and when the traversed pixel value is larger than the first minimum value, continuing traversing the pixel vector rightwards until the first minimum value is traversed, and when the first minimum value is larger than the second left pixel value, determining that no second target pixel value larger than the second left pixel value exists in the shortest sub-array.
7. The artificial intelligence based image contour extraction method of claim 6, wherein after obtaining the target image, the method further comprises:
searching in a search server according to the target image to obtain a plurality of candidate search images;
calculating the similarity between each candidate search image and the target image;
obtaining the maximum similarity in the plurality of similarities;
and determining the candidate search image corresponding to the maximum similarity as a target search image.
8. An image contour extraction apparatus based on artificial intelligence, the apparatus comprising:
the processing module is used for responding to the contour extraction instruction and inputting the image to be processed into OpenCV for image processing;
an obtaining module, configured to obtain a black-white-gray scale image output by the OpenCV, and obtain a pixel matrix of the black-white-gray scale image;
the calculation module is used for calculating the shortest sub-array needing to be sequenced in the pixel matrix;
the determining module is used for determining a target pixel corresponding to the shortest sub-array in the pixel matrix;
and the extraction module is used for extracting the outline of the black, white and gray scale image according to the target pixel to obtain a target image.
9. An electronic device, characterized in that the electronic device comprises a processor for implementing the artificial intelligence based image contour extraction method according to any one of claims 1 to 7 when executing a computer program stored in a memory.
10. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, implements the artificial intelligence based image contour extraction method according to any one of claims 1 to 7.
CN202110947886.0A 2021-08-18 2021-08-18 Image contour extraction method based on artificial intelligence and related equipment Pending CN113657410A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110947886.0A CN113657410A (en) 2021-08-18 2021-08-18 Image contour extraction method based on artificial intelligence and related equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110947886.0A CN113657410A (en) 2021-08-18 2021-08-18 Image contour extraction method based on artificial intelligence and related equipment

Publications (1)

Publication Number Publication Date
CN113657410A true CN113657410A (en) 2021-11-16

Family

ID=78480892

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110947886.0A Pending CN113657410A (en) 2021-08-18 2021-08-18 Image contour extraction method based on artificial intelligence and related equipment

Country Status (1)

Country Link
CN (1) CN113657410A (en)

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2014236912A (en) * 2013-06-10 2014-12-18 株式会社島津製作所 Image processor and method thereof
CN104268337A (en) * 2014-09-24 2015-01-07 中广核(北京)仿真技术有限公司 Method and system for generating path of simulation support platform image connecting line
CN108898147A (en) * 2018-06-27 2018-11-27 清华大学 A kind of two dimensional image edge straightened method, apparatus based on Corner Detection
CN109492795A (en) * 2018-10-11 2019-03-19 平安科技(深圳)有限公司 Airport boarding service processing method, device, equipment and medium based on AI
CN112380926A (en) * 2020-10-28 2021-02-19 安徽农业大学 Weeding path planning system of field weeding robot
CN112669459A (en) * 2020-12-25 2021-04-16 北京市遥感信息研究所 Satellite image optimal mosaic line generation method based on feature library intelligent decision
CN113159027A (en) * 2021-04-13 2021-07-23 杭州电子科技大学 Seven-segment type digital display instrument identification method based on minimum external rectangle variant
CN113192100A (en) * 2021-05-24 2021-07-30 大连大学 Method for acquiring edge path of key characteristic area of time-sharing overlapped plant image

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2014236912A (en) * 2013-06-10 2014-12-18 株式会社島津製作所 Image processor and method thereof
CN104268337A (en) * 2014-09-24 2015-01-07 中广核(北京)仿真技术有限公司 Method and system for generating path of simulation support platform image connecting line
CN108898147A (en) * 2018-06-27 2018-11-27 清华大学 A kind of two dimensional image edge straightened method, apparatus based on Corner Detection
CN109492795A (en) * 2018-10-11 2019-03-19 平安科技(深圳)有限公司 Airport boarding service processing method, device, equipment and medium based on AI
CN112380926A (en) * 2020-10-28 2021-02-19 安徽农业大学 Weeding path planning system of field weeding robot
CN112669459A (en) * 2020-12-25 2021-04-16 北京市遥感信息研究所 Satellite image optimal mosaic line generation method based on feature library intelligent decision
CN113159027A (en) * 2021-04-13 2021-07-23 杭州电子科技大学 Seven-segment type digital display instrument identification method based on minimum external rectangle variant
CN113192100A (en) * 2021-05-24 2021-07-30 大连大学 Method for acquiring edge path of key characteristic area of time-sharing overlapped plant image

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
BRUNO DA SILVA ET AL: "A Multimode SoC FPGA-Based Acoustic Camera for Wireless Sensor Networks", 《 2018 13TH INTERNATIONAL SYMPOSIUM ON RECONFIGURABLE COMMUNICATION-CENTRIC SYSTEMS-ON-CHIP》, 30 August 2018 (2018-08-30), pages 1 - 8 *
邓祥: "基于双目视觉的清洁机器人障碍检测设计与实现", 《中国优秀硕士学位论文全文数据库 信息科技辑》, 15 February 2017 (2017-02-15), pages 138 - 3859 *

Similar Documents

Publication Publication Date Title
CN108197547B (en) Face pose estimation method, device, terminal and storage medium
CN108229343B (en) Target object key point detection method, deep learning neural network and device
US20210183097A1 (en) Spare Part Identification Using a Locally Learned 3D Landmark Database
CN108765315B (en) Image completion method and device, computer equipment and storage medium
CN114153795B (en) Method and device for intelligently calling electronic archive, electronic equipment and storage medium
US20210166058A1 (en) Image generation method and computing device
CN112100425B (en) Label labeling method and device based on artificial intelligence, electronic equipment and medium
CN113128478B (en) Model training method, pedestrian analysis method, device, equipment and storage medium
CN111695594A (en) Image category identification method and device, computer equipment and medium
CN113705462A (en) Face recognition method and device, electronic equipment and computer readable storage medium
CN111860522A (en) Identity card picture processing method and device, terminal and storage medium
CN113157739A (en) Cross-modal retrieval method and device, electronic equipment and storage medium
CN113591433A (en) Text typesetting method and device, storage medium and computer equipment
CN113704276A (en) Map updating method and device, electronic equipment and computer readable storage medium
CN116936116A (en) Intelligent medical data analysis method and system
CN116453226A (en) Human body posture recognition method and device based on artificial intelligence and related equipment
CN113657410A (en) Image contour extraction method based on artificial intelligence and related equipment
CN113837998B (en) Method and device for automatically adjusting and aligning pictures based on deep learning
CN113609948B (en) Method, device and equipment for detecting video time sequence action
CN115601547A (en) Sample image acquisition method, sample image acquisition device, cargo management method, cargo management device, cargo management equipment and storage medium
CN115272923A (en) Intelligent identification method and system based on big data platform
CN114818685A (en) Keyword extraction method and device, electronic equipment and storage medium
CN114139530A (en) Synonym extraction method and device, electronic equipment and storage medium
US11127158B2 (en) Image indexing and retrieval using local image patches for object three-dimensional pose estimation
CN112825122A (en) Ethnicity judgment method, ethnicity judgment device, ethnicity judgment medium and ethnicity judgment equipment based on two-dimensional face image

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination