WO2020228187A1 - 边缘检测方法、装置、电子设备和计算机可读存储介质 - Google Patents

边缘检测方法、装置、电子设备和计算机可读存储介质 Download PDF

Info

Publication number
WO2020228187A1
WO2020228187A1 PCT/CN2019/103850 CN2019103850W WO2020228187A1 WO 2020228187 A1 WO2020228187 A1 WO 2020228187A1 CN 2019103850 W CN2019103850 W CN 2019103850W WO 2020228187 A1 WO2020228187 A1 WO 2020228187A1
Authority
WO
WIPO (PCT)
Prior art keywords
lines
line
boundary
image
target
Prior art date
Application number
PCT/CN2019/103850
Other languages
English (en)
French (fr)
Inventor
徐青松
李青
Original Assignee
杭州睿琪软件有限公司
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 杭州睿琪软件有限公司 filed Critical 杭州睿琪软件有限公司
Priority to US16/981,293 priority Critical patent/US11636604B2/en
Publication of WO2020228187A1 publication Critical patent/WO2020228187A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/10Segmentation; Edge detection
    • G06T7/13Edge detection
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/10Segmentation; Edge detection
    • G06T7/136Segmentation; Edge detection involving thresholding
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/10Segmentation; Edge detection
    • G06T7/168Segmentation; Edge detection involving transform domain methods
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/10Segmentation; Edge detection
    • G06T7/181Segmentation; Edge detection involving edge growing; involving edge linking
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T2207/00Indexing scheme for image analysis or image enhancement
    • G06T2207/10Image acquisition modality
    • G06T2207/10004Still image; Photographic image
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T2207/00Indexing scheme for image analysis or image enhancement
    • G06T2207/20Special algorithmic details
    • G06T2207/20048Transform domain processing
    • G06T2207/20061Hough transform
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T2207/00Indexing scheme for image analysis or image enhancement
    • G06T2207/20Special algorithmic details
    • G06T2207/20081Training; Learning
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T2207/00Indexing scheme for image analysis or image enhancement
    • G06T2207/20Special algorithmic details
    • G06T2207/20084Artificial neural networks [ANN]
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V30/00Character recognition; Recognising digital ink; Document-oriented image-based pattern recognition
    • G06V30/10Character recognition
    • G06V30/16Image preprocessing
    • G06V30/1607Correcting image deformation, e.g. trapezoidal deformation caused by perspective

Definitions

  • the present invention relates to the field of image processing technology, and in particular to an edge detection method, device, electronic equipment and computer-readable storage medium of an object in an image.
  • the purpose of the present invention is to provide an edge detection method, device, electronic device, and computer-readable storage medium of an object in an image to detect the edge of an object in an image.
  • the specific technical solutions are:
  • the present invention provides an edge detection method of an object in an image.
  • the method includes:
  • Obtaining multiple target lines according to the multiple initial merged lines includes: merging the multiple initial merged lines that are similar among the multiple initial merged lines to obtain at least one target line, and combining the unmerged one Or more of the initial merged lines as one or more of the target lines;
  • the image is processed by a pre-trained boundary line area recognition model to obtain multiple boundary line areas of the object in the image; wherein the boundary line area recognition model is a neural network-based model;
  • the processing the image to obtain a line drawing of the grayscale contour in the image includes:
  • the image is processed by an edge detection algorithm based on OpenCV to obtain a line drawing of the gray contour in the image.
  • combining multiple similar lines in the line drawing to obtain multiple initial combined lines includes:
  • a plurality of groups of the first type lines are obtained from a plurality of the long lines; wherein each group of the first type lines includes at least two successively adjacent long lines, and between any two adjacent long lines The included angles of are all smaller than the second preset threshold;
  • each of the long lines in the group of lines of the first type is sequentially merged to obtain one initial merged line.
  • combining the initial merged lines that are similar among the plurality of initial merged lines to obtain the target line includes:
  • a plurality of groups of second-type lines are obtained from a plurality of said initial merged lines; wherein each group of said second-type lines includes at least two successively adjacent initial merged lines, and any two adjacent ones The angles between the initial merged lines are all less than the third preset threshold;
  • the initial merged lines in the group of lines of the second type are sequentially merged to obtain a target line.
  • the angle ⁇ between the two lines is calculated by the following formula:
  • the boundary matrix is determined in the following manner: redraw a plurality of the initial merged lines and unmerged long lines among the long lines, and redraw
  • the position information of the pixels in all the lines drawn corresponds to the entire image matrix.
  • the values of the pixel positions of these lines in the image matrix are set to the first value, and the values of the pixel positions other than these lines are set to the first value. Two values to form a boundary matrix.
  • determining multiple reference boundary lines from multiple target lines according to the boundary matrix includes:
  • the target line For each of the target lines, the target line is extended, a line matrix is determined according to the extended target line, and then the line matrix is compared with the boundary matrix to calculate that the extended target line belongs to all The number of pixels in the boundary matrix is used as the result of the target line; wherein the line matrix has the same size as the boundary matrix;
  • multiple reference boundary lines are determined from the multiple target lines.
  • determining a target boundary line corresponding to the boundary line region from a plurality of reference boundary lines includes:
  • the boundary line area For each boundary line area, convert the boundary line area into multiple straight lines, calculate the average slope of the multiple straight lines, and then determine whether there are slopes in the multiple reference boundary lines that are different from the average slope. If the matched reference boundary line exists, the reference boundary line is determined as the target boundary line corresponding to the boundary line area.
  • the method further includes:
  • the boundary line area For each boundary line area, if it is determined that there is no reference boundary line with a slope matching the average slope among the multiple reference boundary lines, then for each straight line obtained by the conversion of the boundary line area, the The line matrix formed by the straight line is compared with the boundary matrix, and the number of pixels belonging to the boundary matrix on the straight line is calculated as the score of the straight line; the line with the best score is determined as corresponding to the boundary line area The target boundary line; wherein the line matrix and the boundary matrix have the same size.
  • converting the boundary line region into multiple straight lines includes:
  • the Hough transform is used to convert the boundary line area into multiple straight lines.
  • the line matrix is determined in the following manner: the extended target line or straight line is redrawn, and the position information of the pixel in the redrawn line is corresponding to In the entire image matrix, the value of the pixel point of the line in the image matrix is set to the first value, and the value of the pixel point outside the line is set to the second value, thereby forming a line matrix.
  • the boundary line region recognition model is obtained by training in the following manner:
  • the neural network is trained through the labeled image sample set to obtain the boundary line region recognition model.
  • the method further includes:
  • the present invention provides an edge detection device for objects in an image, the device includes:
  • An obtaining module which is used to process an image to obtain a line drawing of gray contours in the image
  • the first merging module is configured to merge multiple similar lines in the line drawing to obtain multiple initial merged lines, and determine a boundary matrix according to the multiple initial merged lines;
  • the second merging module is configured to obtain multiple target lines based on the multiple initial merged lines, including: merging similar initial merged lines among the multiple initial merged lines to obtain at least one target line , And use one or more of the initial merged lines that are not merged as one or more of the target lines;
  • a first determination module configured to determine multiple reference boundary lines from multiple target lines according to the boundary matrix
  • a recognition module configured to process the image through a pre-trained boundary line region recognition model to obtain multiple boundary line regions of objects in the image; wherein the boundary line region recognition model is a neural network-based model;
  • the second determining module is configured to determine, for each boundary line area, a target boundary line corresponding to the boundary line area from a plurality of reference boundary lines;
  • the third determining module is configured to determine the edge of the object in the image according to the multiple target boundary lines determined by the multiple boundary line regions.
  • the obtaining module is specifically configured to process the image by using an edge detection algorithm based on OpenCV to obtain a line drawing of the gray contour in the image.
  • the first merging module merges multiple similar lines in the line drawing to obtain multiple initial merged lines, including:
  • a plurality of groups of the first type lines are obtained from a plurality of the long lines; wherein each group of the first type lines includes at least two successively adjacent long lines, and between any two adjacent long lines The included angles are less than the preset threshold;
  • each of the long lines in the group of lines of the first type is sequentially merged to obtain one initial merged line.
  • the second merging module merges the initial merged lines that are similar among the plurality of initial merged lines to obtain the target line, specifically: A plurality of groups of second-type lines are obtained from the initial merged lines; wherein each group of the second-type lines includes at least two successively adjacent initial merged lines, and any two adjacent initial merged lines The included angles between are all smaller than the third preset threshold; for each group of second-type lines, the initial merged lines in the group of second-type lines are sequentially merged to obtain a target line.
  • the angle ⁇ between the two lines is calculated by the following formula: among them, Represent the vector of two lines respectively.
  • the boundary matrix is determined by redrawing a plurality of the initial merged lines and the unmerged long lines among the long lines, and redrawing
  • the position information of the pixels in all the lines drawn corresponds to the entire image matrix.
  • the values of the pixel positions of these lines in the image matrix are set to the first value, and the values of the pixel positions other than these lines are set to the first value. Two values to form a boundary matrix.
  • the first determining module includes:
  • the first calculation sub-module is used to extend the target line for each target line, determine a line matrix according to the extended target line, and then compare the line matrix with the boundary matrix to calculate the extension
  • the number of pixels on the target line that belong to the boundary matrix is taken as the result of the target line; wherein the line matrix and the boundary matrix have the same size;
  • the first determining submodule is used for determining multiple reference boundary lines from the multiple target lines according to the performance of each target line.
  • the second determining module includes:
  • the second calculation sub-module is used to calculate the slope of each reference boundary line
  • the second determining sub-module is configured to convert the boundary line area into multiple straight lines for each boundary line area, calculate the average slope of the multiple straight lines, and then determine whether the multiple reference boundary lines are There is a reference boundary line whose slope matches the average slope, and if it exists, the reference boundary line is determined as the target boundary line corresponding to the boundary line area.
  • the second determining submodule is further configured to:
  • the boundary line area For each boundary line area, if it is determined that there is no reference boundary line with a slope matching the average slope among the multiple reference boundary lines, then for each straight line obtained by the conversion of the boundary line area, the The line matrix formed by the straight line is compared with the boundary matrix, and the number of pixels belonging to the boundary matrix on the straight line is calculated as the score of the straight line; the line with the best score is determined as corresponding to the boundary line area The target boundary line; wherein the line matrix and the boundary matrix have the same size.
  • the second determining submodule converts the boundary line area into multiple straight lines, specifically: using Hough transform to convert the boundary line area into multiple lines straight line.
  • the line matrix is determined in the following manner: redraw the extended target line or straight line, and correspond to the position information of the pixel in the redrawn line
  • the value of the pixel point of the line in the image matrix is set to the first value
  • the value of the pixel point outside the line is set to the second value, thereby forming a line matrix.
  • the device further includes: a model training module for training to obtain a boundary line region recognition model in the following manner;
  • the device further includes: a transformation module, configured to obtain multiple intersection points of multiple target boundary lines, The area determined by the target boundary line undergoes projection transformation to obtain a front view of the object in the image.
  • a transformation module configured to obtain multiple intersection points of multiple target boundary lines, The area determined by the target boundary line undergoes projection transformation to obtain a front view of the object in the image.
  • the present invention also provides an electronic device, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory complete mutual communication through the communication bus.
  • the memory is used to store computer programs
  • the processor is configured to implement the steps of the method for detecting the edge of an object in an image as described in the first aspect when executing the program stored in the memory.
  • the present invention also provides a computer-readable storage medium in which a computer program is stored.
  • the computer program is executed by a processor, the image described in the first aspect The steps of the object edge detection method.
  • the method, device, electronic equipment and computer-readable storage medium for edge detection of objects in images provided by the present invention have the following beneficial effects:
  • the lines are merged to obtain the target line.
  • the initial merged line that cannot be merged is directly used as the target line, and then multiple reference boundary lines are determined from the multiple target lines according to the boundary matrix.
  • the pre-trained boundary line area recognition model The image is processed to obtain multiple boundary line areas of the object in the image, so that for each boundary line area, the target boundary line corresponding to the boundary line area can be determined from the multiple reference boundary lines, and then according to the determined multiple target boundaries Lines determine the edges of objects in the image.
  • the invention obtains the reference boundary line according to the image and recognizes the boundary line area in combination with machine learning, thereby jointly determining the target boundary line of the object in the image, realizes the edge detection of the object in the image, and can quickly locate the position of the edge of the object in the image, and Improve the accuracy of edge detection.
  • Fig. 1 is a flowchart of a method for edge detection of an object in an image provided by an embodiment of the present invention
  • FIGS. 2A-2C are diagrams showing examples of images in a specific embodiment of the present invention.
  • 3A-3C are diagrams showing examples of images in another specific embodiment of the present invention.
  • Figure 4 is a comparison diagram of the line merging process
  • Fig. 5 is a structural diagram of a device for edge detection of objects in an image provided by an embodiment of the present invention.
  • Fig. 6 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.
  • embodiments of the present invention provide an edge detection method, device, electronic device, and computer-readable storage medium of an object in an image.
  • the method for detecting the edge of an object in an image of the embodiment of the present invention can be applied to the device for detecting the edge of an object in the image of the embodiment of the present invention, and the device for detecting the edge of the object in the image can be configured on an electronic device.
  • the electronic device may be a personal computer, a mobile terminal, etc.
  • the mobile terminal may be a hardware device with various operating systems such as a mobile phone or a tablet computer.
  • FIG. 1 is a schematic flowchart of an edge detection method of an object in an image according to an embodiment of the present invention. Please refer to Figure 1.
  • An edge detection method of an object in an image may include the following steps:
  • Step S101 processing the image to obtain a line drawing of the gray contour in the image.
  • the image is an image obtained by a user taking a photo of an object
  • the object may be, for example, a business card, an examination paper, a laboratory test form, a document, and the like.
  • the images shown in Fig. 2A and Fig. 3A are respectively the images obtained by photographing the test report and business card.
  • the method of processing the image to obtain the line drawing of the gray-scale contour in the image may be: processing the image by the edge detection algorithm based on OpenCV to obtain the line drawing of the gray-scale contour in the image .
  • OpenCV is an open source computer vision library.
  • Edge detection algorithms based on OpenCV include Sobel, Scarry, Canny, Laplacian, Prewitt, Marr-Hildresh, scharr and many other algorithms.
  • the Canny edge detection algorithm is used in this embodiment.
  • the Canny edge detection algorithm is a multi-stage algorithm, which consists of multiple steps, including: 1. Image noise reduction: smooth the image with a Gaussian filter; 2.
  • Calculate the image gradient Use the first-order partial derivative finite difference to calculate the gradient amplitude and direction; 3. Non-maximum suppression: non-maximum suppression of the gradient amplitude; 4. Threshold screening: use a dual threshold algorithm to detect and connect edges.
  • the line drawing of the gray contour in the image can be obtained.
  • the line drawing shown in Figure 2B and Figure 3B can be obtained respectively.
  • each line is actually a very small line segment.
  • the boundary line of the object in the image is actually divided into a small line segment, so it is necessary to connect similar lines and perform Follow-up processing to get the boundary line of the object.
  • the manifestation of each small line segment in the line drawing is in the form of an array, and each line segment is composed of the coordinate values of the pixels corresponding to the start and end points in the entire line drawing.
  • Step S102 Combine similar lines in the line drawing to obtain multiple initial combined lines, and determine a boundary matrix based on the multiple initial combined lines.
  • Step A Obtain long lines in the line drawing; wherein, the long lines are longer than the first predetermined line. Set threshold lines;
  • Step B Obtain multiple groups of first-type lines from the long lines; wherein, the first-type lines include at least two consecutively adjacent long lines, and any of the two adjacent long lines The angles between the two are smaller than the second preset threshold;
  • Step C For each group of first-type lines, merge each long line in the first-type line in sequence to obtain an initial merged line.
  • the long line in the line drawing refers to a line whose length exceeds a certain threshold in the line drawing, for example, a line whose length exceeds 2 pixels is defined as a long line. Only the long lines in the line drawing are acquired for subsequent merging, and some shorter lines in the line drawing are not considered. This can avoid the interference of lines inside and outside the object when merging the lines, such as internal text and Corresponding lines for graphics, other external objects, etc.
  • the first type of line can be obtained in the following way: first select a long line, and then sequentially determine from the long line whether the angle between two adjacent lines is less than the second preset threshold, if a certain When the angle between a long line and an adjacent line is not less than the second preset threshold, the selected long line and all successively adjacent long lines between the long line can be combined into a group of first For a type of line, then repeat the above process, starting from the adjacent line of a certain long line to determine whether the angle between two adjacent lines is less than the second preset threshold, and so on, until all the long lines are traversed , So as to get multiple groups of first type lines.
  • the preset threshold means that the long lines A and B belong to the same group of lines of the first type, and then continue to determine the angle between the long line B and the adjacent line C, and the angle between the two is also less than the second preset threshold , Which means that the long line C, B, and A belong to the same group of lines of the first type.
  • the angle between the long line C and the adjacent line D, and the angle between the two is also less than the second preset threshold.
  • the long line D and C, B, and A also belong to the same group of lines of the first type.
  • the angle between the long line D and the adjacent line E and the angle between the two is greater than the second preset threshold. It means that the long line E and D, C, B, and A do not belong to the same group of first type lines, and the long lines A, B, C, and D can be used as a group of first type lines.
  • the long lines G, H, I, and J can be obtained as a group of first-type lines.
  • the long lines M, N, and O are also a group of first type lines.
  • a long line arbitrarily first, for example, select a long line D, and the lines adjacent to the long line D have C and E, and then determine the angle between the long lines D and C and The angle between the lines D and E. Since the angle between D and C is less than the second preset threshold, then D and C belong to the same group of lines of the first type, because the angle between D and E is greater than the second With a preset threshold, D and E do not belong to the same group of first-class lines. Then, on the one hand, you can continue to judge the angle between other adjacent lines from the long line C, so as to determine that they belong to the same group of first-class lines.
  • the other lines of the line and the first-type lines of other groups can start from the long line E to determine the angles between other successively adjacent lines to determine the first-type lines of other groups.
  • the long lines A, B, C, D are a group of first-type lines
  • the long lines G, H, I, and J are a group of first-type lines
  • the long lines M, N, O It is also a group of first-class lines.
  • step B the angle ⁇ between the two lines is calculated by the following formula: among them, Represent the vectors of two adjacent lines respectively.
  • the value of the second preset threshold may be set according to actual conditions, for example, set to merge when the included angle ⁇ is less than 15 degrees, that is, the second preset threshold is 15 degrees.
  • Combining the two lines in step C refers to taking the average of the slopes of the two lines, and this average is the slope of the combined line.
  • the merging of two lines is calculated based on the array form of the two lines, so as to calculate the coordinate values of the pixels corresponding to the start and end points of the merged line in the entire line drawing, and then according to the calculated coordinate values
  • An array of merged lines is formed and stored. Combine the long lines in each group of first type lines in sequence.
  • the boundary matrix is determined in the following manner: redrawing a plurality of the initial merged lines and the unmerged lines in the long lines, and corresponding the position information of the pixels in all the redrawn lines to the entire image
  • the matrix that is, the image represented in the form of a matrix
  • the values of the pixel positions of these lines in the image matrix are set to the first value
  • the values of the pixel points outside these lines are set to the second value, thereby forming a boundary matrix.
  • the boundary matrix may be a matrix with the same size as the image matrix. For example, if the size of the image is 1024 ⁇ 1024 pixels, the image matrix is a 1024 ⁇ 1024 matrix, and the boundary matrix is also a 1024 ⁇ 1024 matrix.
  • the multiple initial merged lines and the unmerged lines in the long lines are redrawn according to a certain line width (for example, the line width is 2), and the pixel points of the redrawn lines correspond to the positions in the matrix.
  • the boundary matrix is filled with values.
  • the positions of the pixels on the lines corresponding to the matrix are set to the first value, such as 255, and the positions of the pixels without lines corresponding to the matrix are set to the second value, such as 0, to form the whole
  • the super matrix of the picture is the boundary matrix. It should be noted that since the multiple initial merged lines and the unmerged lines in the long lines are all stored in the form of arrays, they need to be formed as actual line data when determining the boundary matrix.
  • the line is redrawn, for example, with a line width of 2, so as to obtain the coordinate value of the pixel point corresponding to each point on each line, and then fill in the value in the boundary matrix according to the obtained coordinate value, for example,
  • the value of the position corresponding to the coordinate value in the boundary matrix is set to 255, and the value of the remaining positions is set to 0.
  • the boundary matrix is a 10 ⁇ 10 matrix, where all positions with a value of 255 in the boundary matrix are connected to form multiple initial merged lines and unmerged lines among the long lines.
  • Step S103 Combine similar lines among the multiple initial merged lines to obtain a target line, and use the unmerged initial merged line as the target line.
  • step S102 the initial merged line after the merge is a plurality of longer lines.
  • step S103 according to the merging rule in step S102, it is possible to continue to determine whether there are similar lines in the multiple initial merged lines, so that the similar lines are merged again to obtain multiple target lines, and the initial merged lines that cannot be merged are also used as the target. line.
  • Step a Obtain multiple sets of second-type lines from the multiple initial merged lines; wherein, The second type of lines includes at least two successively adjacent initial merged lines, and the angle between any two adjacent initial merged lines is less than the third preset threshold; step b: for each group of second type lines, The initial merged lines in the second type of lines are merged in sequence to obtain a target line.
  • the third preset threshold may be the same as or different from the second preset threshold, which is not limited in this embodiment, for example, the third preset threshold is set to an angle of 10 degrees.
  • the initial merged line As shown in Figure 4 before and after the line merging, after the above steps of merging the initial merged lines 1, 2, and 3, since the angle between the initial merged lines 1 and 2 is smaller than the third preset threshold, the initial merged line The angle between 3 and initial 2 is greater than the third preset threshold. Therefore, the initial merged lines 1 and 2 can be further merged into the target line 12, and the initial merged line 3 cannot be merged, and the initial merged line 3 is directly used as a target line.
  • multiple target lines have been obtained.
  • the corresponding lines of internal text and graphics, and other external objects are merged.
  • these interference lines will be removed according to subsequent processing (specifically through the processing of step S104 to step S105) and rules.
  • Step S104 according to the boundary matrix, determine multiple reference boundary lines from the multiple target lines.
  • determining a plurality of reference boundary lines from the plurality of target lines according to the boundary matrix includes: first, for each target line, the target line is extended, and the target line is extended according to the extended target line. Determine a line matrix, and then compare the line matrix with the boundary matrix, and calculate the number of pixels belonging to the boundary matrix on the extended target line as the result of the target line.
  • the line matrix and the boundary matrix The size of the matrix is the same; then, according to the performance of each target line, multiple reference boundary lines are determined from the multiple target lines.
  • the line matrix can be determined in the following manner: the extended target line is redrawn, the position information of the pixel points in the redrawn line is mapped to the entire image matrix, and the pixel point of the line in the image matrix is located The value of the position is set to the first value, and the value of the position of the pixel points other than the line is set to the second value, thereby forming a line matrix.
  • the formation of the line matrix is similar to the boundary matrix, and will not be repeated here.
  • the target line is stored in the form of an array, that is, the coordinate values of its starting point and end point are stored.
  • the extended target line is stored as the extended target line
  • the coordinate values of the start and end points form an array, so when redrawing the extended target line, it is also redrawn according to the same line width, for example, the line width is 2, so as to obtain the corresponding points on the extended target line
  • the coordinate values of the pixels are then filled in the line matrix according to the coordinate values, that is, the value of the position corresponding to the coordinate value in the line matrix is set to 255, and the value of the remaining positions is set to 0.
  • the merged target line is extended, and it is determined that the pixel points thereon fall into the initial merged line in step S102 and the target line with the largest number of unmerged lines among the long lines as the reference boundary line.
  • judge how many pixels belong to the boundary matrix, and calculate a result specifically: extend the target line, the line obtained after the target line is extended also forms a line according to the formation of the boundary matrix Matrix, compare the line matrix with the boundary matrix to determine how many pixels fall into the boundary matrix, that is, determine how many pixels at the same position in the two matrices have the same first value, such as 255, to calculate the result.
  • the multiple target lines with the best performance are determined from the multiple target lines as the reference boundary line.
  • the line matrix formed by an extended target line is as follows. By comparing the line matrix with the above boundary matrix, it can be seen that 7 pixels on the extended target line fall into the boundary matrix, thereby obtaining the target Line grades.
  • step S105 the image is processed by a pre-trained boundary line region recognition model to obtain multiple boundary line regions of the object in the image.
  • the boundary line area recognition model is a neural network-based model.
  • the boundary line region recognition model is established through machine learning training.
  • This model can be a neural network-based model.
  • the boundary line region recognition model can be obtained by training in the following process: Annotation process to annotate the boundary area, inner area and outer area of the object in each image sample; and through the image sample set after the annotation processing, the neural network is trained to obtain the boundary line area recognition model.
  • the boundary line region recognition model established through machine learning training recognizes the image (i.e., the original image), and can identify the boundary line area, the internal area (i.e. the area where the object is located) and the external area (i.e. the object’s Outer area) 3 parts, so as to obtain multiple (for example, 4) edge contour maps (ie, the boundary line area of the object in the image) of the original image.
  • the edge contour is relatively thick.
  • the model established through machine learning training recognizes the boundary line area of the object in the image, and in the subsequent step S106, the boundary line area is used to determine the target boundary from the multiple reference boundary lines determined in step S104 Lines, lines that are misidentified in steps S102 and S103, such as lines falling in the middle of a business card or document, lines in the middle of a table, etc., can be removed.
  • Step S106 For each boundary line area, determine a target boundary line corresponding to the boundary line area from a plurality of reference boundary lines.
  • determining a target boundary line corresponding to the boundary line area from a plurality of reference boundary lines may include: firstly, calculating the slope of each reference boundary line; Then, for each of the boundary line areas, the boundary line area is converted into multiple straight lines, and the average slope of the multiple straight lines is calculated, and then it is judged whether there is a slope and the average in the multiple reference boundary lines. If there is a reference boundary line matching the slope, the reference boundary line is determined as the target boundary line corresponding to the boundary line area.
  • the boundary line area can be converted into multiple straight lines by using the Hough transform, of course, other methods can also be used for the conversion, which is not limited in this embodiment.
  • the edge contour in the boundary line area is relatively thick.
  • the Hough transform can be used to convert the boundary line area into multiple straight lines. These lines have approximate slopes to obtain the average slope. Then compare with the slope of each reference boundary line to determine whether there is a reference boundary line whose slope matches the average slope among the multiple reference boundary lines, that is, find the most approximate reference boundary line from the multiple reference boundary lines, As the target boundary line corresponding to the boundary line area.
  • a comparison threshold is set.
  • the slope of a reference boundary line is When the absolute value of the difference with the average slope is less than the comparison threshold, it is determined that the slope of the reference boundary line is a reference boundary line matching the average slope, and then it is determined that the reference boundary line is a target boundary line corresponding to the boundary line area.
  • the following processing is performed: convert the boundary line region to obtain Compare each line matrix formed by the line with the boundary matrix, and calculate the number of pixels on the line that belong to the boundary matrix as the score of the line; determine the line with the best score as The target boundary line corresponding to the boundary line area. If there are multiple lines with the best results, the first line among them will be the best boundary line according to the sorting algorithm.
  • the line matrix is determined in the following manner: the straight line is redrawn, the position information of the pixel points in the redrawn line is corresponded to the entire image matrix, and the value of the pixel point of the line in the image matrix is set to The first value and the value of the pixel point other than the line are set to the second value, thereby forming a line matrix.
  • the formation of the line matrix is similar to the boundary matrix, and will not be repeated here.
  • the multiple lines obtained by the Hough transform are formed into a corresponding line matrix according to the matrix formation method described in steps S102 and S104, and judge Which line of pixels has the best performance in the boundary matrix is considered to be the target boundary line corresponding to the boundary line area.
  • the method of comparing the line matrix formed by the straight line with the boundary matrix to calculate the score of the straight line can refer to the related description in step S104, which will not be repeated here.
  • the target boundary line obtained after the above processing is the four longer lines shown in Figure 2B; the image shown in Figure 3A, the target boundary line obtained after the above processing is Figure 3B The four longer lines shown in.
  • Step S107 Determine the edge of the object in the image according to the determined multiple target boundary lines.
  • each target boundary line corresponds to a boundary line area of the object in the image
  • the multiple target boundary lines constitute the edge of the object in the image.
  • the edge of the object in the image is composed of the four longer lines in Figure 2B, namely the target boundary lines a1, a2, a3, and a4; in the image shown in Figure 3A, the edge of the object in the image is composed of
  • the four longer lines in FIG. 3B are composed of target boundary lines b1, b2, b3, and b4.
  • multiple intersection points of multiple target boundary lines can also be obtained, and the multiple intersection points and regions determined by multiple target boundary lines are projected and transformed to obtain the front view of the object in the image Figure. Every two adjacent target boundary lines intersect to obtain an intersection point, and each intersection point and each target boundary line jointly define the area where the object in the image is located.
  • Projective transformation is to project the picture to a new viewing plane (Viewing Plane), also called Projective Mapping. Because the real shape of the object has changed in the image obtained by taking pictures, that is, geometric distortion has occurred. In the image shown in Fig. 2A, the shape of the test sheet is originally rectangular, but the shape of the test sheet in the image has changed, becoming a parallelogram. Therefore, the projective transformation of the area where the object is in the image can transform the area where the object is in the image from a parallelogram to a square, that is, the area where the object is in the image is corrected to remove the influence of geometric distortion, and the front view of the object in the image is obtained. .
  • the projection transformation is to process the pixels to obtain the front view according to the space projection conversion coordinates, which will not be repeated here.
  • FIG. 2A the front view of the test sheet of the object in the finally obtained image is shown in FIG. 2C;
  • FIG. 3A the front view of the object business card in the finally obtained image is shown in FIG.
  • this embodiment first obtains a line drawing of the gray contour in the image, merges similar lines in the line drawing to obtain multiple initial merged lines, and determines a boundary matrix based on the multiple initial merged lines, and continues to combine The similar lines in the multiple initial merged lines are merged to obtain the target line.
  • the initial merged line that cannot be merged is directly used as the target line, and then multiple reference boundary lines are determined from the multiple target lines according to the boundary matrix.
  • the trained boundary line area recognition model processes the image to obtain multiple boundary line areas of the object in the image, so that for each boundary line area, the target boundary line corresponding to the boundary line area can be determined from multiple reference boundary lines. Then, the edge of the object in the image is determined according to the determined multiple target boundary lines.
  • the reference boundary line is obtained from the image, combined with machine learning to identify the boundary line area, thereby jointly determining the target boundary line of the object in the image, and realizes the edge detection of the object in the image, and can quickly locate the position of the edge of the object in the image. And improve the accuracy of edge detection.
  • an embodiment of the present invention also provides an edge detection device for an object in an image.
  • FIG. 5 is a schematic structural diagram of an edge detection device for an object in an image provided by an embodiment of the present invention. Please refer to FIG. 5, an edge detection device of an object in an image includes:
  • the obtaining module 201 is used to process the image to obtain the line drawing of the gray contour in the image;
  • the first merging module 202 is configured to merge similar lines in the line drawing to obtain multiple initial merged lines, and determine a boundary matrix according to the multiple initial merged lines;
  • the second merging module 203 is configured to merge similar lines among the multiple initial merged lines to obtain a target line, and use the unmerged initial merged line as the target line;
  • the first determining module 204 is configured to determine multiple reference boundary lines from the multiple target lines according to the boundary matrix
  • the recognition module 205 is configured to process the image through a pre-trained boundary line area recognition model to obtain multiple boundary line areas of the object in the image; wherein the boundary line area recognition model is a neural network-based model ;
  • the second determining module 206 is configured to determine, for each boundary line area, a target boundary line corresponding to the boundary line area from a plurality of reference boundary lines;
  • the third determining module 207 is configured to determine the edge of the object in the image according to the determined multiple target boundary lines.
  • the obtaining module 201 is specifically configured to process the image by using an edge detection algorithm based on OpenCV to obtain a line drawing of the gray contour in the image.
  • the first merging module 202 merges similar lines in the line drawing to obtain multiple initial merged lines, specifically: acquiring long lines in the line drawing, where the long lines are A line whose length exceeds a first preset threshold; and a plurality of groups of lines of the first type are obtained from the long lines, wherein the line of the first type includes at least two successively adjacent long lines, and any two adjacent long lines The angles between the lines are all smaller than the second preset threshold; for each group of first-type lines, each long line in the first-type line is sequentially merged to obtain an initial merged line.
  • the second merging module 203 merges similar lines in the plurality of initial merged lines to obtain a target line, specifically: acquiring multiple sets of second-type lines from the plurality of initial merged lines; wherein The second type line includes at least two successively adjacent initial merged lines, and the angle between any two adjacent initial merged lines is less than a third preset threshold; for each group of second type lines, The initial merged lines in the second type of lines are merged in sequence to obtain a target line.
  • the angle ⁇ between the two lines is calculated by the following formula: among them, Represent the vector of two lines respectively.
  • the boundary matrix is determined in the following manner: redrawing a plurality of the initial merged lines and the unmerged lines in the long lines, and corresponding the position information of the pixels in all the redrawn lines to In the entire image matrix, the values of the positions of the pixels of these lines in the image matrix are set to the first value, and the values of the positions of the pixels other than these lines are set to the second value, thereby forming a boundary matrix.
  • the first determining module 204 includes:
  • the first calculation sub-module is used to extend the target line for each target line, determine a line matrix according to the extended target line, and then compare the line matrix with the boundary matrix to calculate the extension
  • the number of pixels on the target line that belong to the boundary matrix is taken as the result of the target line; wherein the line matrix and the boundary matrix have the same size;
  • the first determining submodule is used for determining multiple reference boundary lines from the multiple target lines according to the performance of each target line.
  • the second determining module 206 includes:
  • the second calculation sub-module is used to calculate the slope of each reference boundary line
  • the second determining sub-module is configured to convert the boundary line area into multiple straight lines for each boundary line area, calculate the average slope of the multiple straight lines, and then determine whether the multiple reference boundary lines are There is a reference boundary line whose slope matches the average slope, and if it exists, the reference boundary line is determined as the target boundary line corresponding to the boundary line area.
  • the second determining submodule is further configured to: for each of the boundary line regions, if it is determined that there is no reference boundary line whose slope matches the average slope among the plurality of reference boundary lines , For each straight line obtained by the conversion of the boundary line area, the line matrix formed by the straight line is compared with the boundary matrix, and the number of pixels on the line belonging to the boundary matrix is calculated as the result of the line ; Determine the best-performing line as the target boundary line corresponding to the boundary line area; wherein the line matrix and the boundary matrix have the same size.
  • the second determining submodule converts the boundary line area into multiple straight lines, specifically: converting the boundary line area into multiple straight lines using Hough transform.
  • the line matrix is determined in the following manner: the extended target line or straight line is redrawn, the position information of the pixel points in the redrawn line is mapped to the entire image matrix, and the line in the image matrix The value of the position of the pixel is set to the first value, and the value of the position of the pixel other than the line is set to the second value, thereby forming a line matrix.
  • the device further includes: a model training module, configured to train to obtain a boundary line region recognition model in the following manner;
  • the device further includes: a transformation module, configured to obtain multiple intersection points of multiple target boundary lines, and perform projective transformation on multiple intersection points and regions determined by multiple target boundary lines to obtain The front view of the object in the image.
  • a transformation module configured to obtain multiple intersection points of multiple target boundary lines, and perform projective transformation on multiple intersection points and regions determined by multiple target boundary lines to obtain The front view of the object in the image.
  • this embodiment first obtains a line drawing of the gray contour in the image, merges similar lines in the line drawing to obtain multiple initial merged lines, and determines a boundary matrix based on the multiple initial merged lines, and continues to combine The similar lines in the multiple initial merged lines are merged to obtain the target line.
  • the initial merged line that cannot be merged is directly used as the target line, and then multiple reference boundary lines are determined from the multiple target lines according to the boundary matrix.
  • the trained boundary line area recognition model processes the image to obtain multiple boundary line areas of the object in the image, so that for each boundary line area, the target boundary line corresponding to the boundary line area can be determined from multiple reference boundary lines. Then, the edge of the object in the image is determined according to the determined multiple target boundary lines.
  • the reference boundary line is obtained from the image, combined with machine learning to identify the boundary line area, thereby jointly determining the target boundary line of the object in the image, and realizes the edge detection of the object in the image, and can quickly locate the position of the edge of the object in the image. And improve the accuracy of edge detection.
  • FIG. 6 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.
  • an electronic device includes a processor 301, a communication interface 302, a memory 303, and a communication bus 304.
  • the processor 301, the communication interface 302, and the memory 303 communicate with each other through the communication bus 304, and the memory 303 uses
  • the processor 301 is used to execute the programs stored in the memory 303, the following steps are implemented:
  • the image is processed by a pre-trained boundary line region recognition model to obtain multiple boundary line regions of the object in the image; wherein, the boundary line region recognition model is used to analyze the neural network through image samples marked with boundary line regions.
  • Network model obtained through training;
  • the edge of the object in the image is determined according to the determined multiple target boundary lines.
  • this embodiment first obtains a line drawing of the gray contour in the image, merges similar lines in the line drawing to obtain multiple initial merged lines, and determines a boundary matrix based on the multiple initial merged lines, and continues to combine The similar lines in the multiple initial merged lines are merged to obtain the target line.
  • the initial merged line that cannot be merged is directly used as the target line, and then multiple reference boundary lines are determined from the multiple target lines according to the boundary matrix.
  • the trained boundary line area recognition model processes the image to obtain multiple boundary line areas of the object in the image, so that for each boundary line area, the target boundary line corresponding to the boundary line area can be determined from multiple reference boundary lines. Then, the edge of the object in the image is determined according to the determined multiple target boundary lines.
  • the reference boundary line is obtained from the image, combined with machine learning to identify the boundary line area, thereby jointly determining the target boundary line of the object in the image, and realizes the edge detection of the object in the image, and can quickly locate the position of the edge of the object in the image. And improve the accuracy of edge detection.
  • the electronic device may be a computing device such as a desktop computer, a notebook, a palmtop computer, and a cloud server.
  • the communication bus mentioned in the above electronic device may be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus.
  • PCI Peripheral Component Interconnect
  • EISA Extended Industry Standard Architecture
  • the communication bus can be divided into address bus, data bus, control bus and so on. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
  • the communication interface is used for communication between the aforementioned electronic device and other devices.
  • the memory may include random access memory (Random Access Memory, RAM), and may also include non-volatile memory (Non-Volatile Memory, NVM), such as at least one disk storage.
  • NVM non-Volatile Memory
  • the memory may also be at least one storage device located far away from the foregoing processor.
  • the above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (Network Processor, NP), etc.; it can also be a digital signal processor (Digital Signal Processing, DSP), a dedicated integrated Circuit (Application Specific Integrated Circuit, ASIC), Field-Programmable Gate Array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components.
  • the general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
  • the processor is the control center of the electronic device, and various interfaces and lines are used to connect various parts of the entire electronic device.
  • An embodiment of the present invention provides a computer-readable storage medium in which a computer program is stored, and when the computer program is executed by a processor, the following steps can be implemented:
  • the image is processed by a pre-trained boundary line area recognition model to obtain multiple boundary line areas of the object in the image; wherein the boundary line area recognition model is a neural network-based model;
  • the edge of the object in the image is determined according to the determined multiple target boundary lines.
  • this embodiment first obtains a line drawing of the gray contour in the image, merges similar lines in the line drawing to obtain multiple initial merged lines, and determines a boundary matrix based on the multiple initial merged lines, and continues to combine The similar lines in the multiple initial merged lines are merged to obtain the target line.
  • the initial merged line that cannot be merged is directly used as the target line, and then multiple reference boundary lines are determined from the multiple target lines according to the boundary matrix.
  • the trained boundary line area recognition model processes the image to obtain multiple boundary line areas of the object in the image, so that for each boundary line area, the target boundary line corresponding to the boundary line area can be determined from multiple reference boundary lines. Then, the edge of the object in the image is determined according to the determined multiple target boundary lines.
  • the reference boundary line is obtained from the image, combined with machine learning to identify the boundary line area, thereby jointly determining the target boundary line of the object in the image, and realizes the edge detection of the object in the image, and can quickly locate the position of the edge of the object in the image. And improve the accuracy of edge detection.
  • the readable storage medium may be a tangible device that can hold and store instructions used by the instruction execution device, for example, but not limited to, an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or the foregoing Any suitable combination of.
  • readable storage media include: portable computer disks, hard disks, random access memory (RAM), read only memory (ROM), erasable programmable read only memory (EPROM or Flash memory), static random access memory (SRAM), portable compact disk read-only memory (CD-ROM), digital versatile disk (DVD), memory stick, floppy disk, mechanical coding device, such as a punch with instructions stored on it The protruding structure in the card or the groove, and any suitable combination of the above.
  • the computer program described here can be downloaded from a readable storage medium to each computing/processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and/or a wireless network.
  • the network may include copper transmission cables, optical fiber transmission, wireless transmission, routers, firewalls, switches, gateway computers, and/or edge servers.
  • the network adapter card or network interface in each computing/processing device receives the computer program from the network and forwards the computer program for storage in a readable storage medium in each computing/processing device.
  • the computer program used to perform the operations of the present invention may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, status setting data, or any of one or more programming languages. Source code or object code written in combination.
  • the programming language includes object-oriented programming languages such as Smalltalk, C++, etc., and conventional procedural programming languages such as "C" language or similar programming languages.
  • the computer program may be executed entirely on the user's computer, partly on the user's computer, executed as an independent software package, partly on the user's computer and partly executed on a remote computer, or entirely executed on the remote computer or server .
  • the remote computer can be connected to the user's computer through any kind of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computer (for example, using an Internet service provider to access the Internet connection).
  • LAN local area network
  • WAN wide area network
  • an electronic circuit such as a programmable logic circuit, a field programmable gate array (FPGA), or a programmable logic array (PLA), can be customized by using the status information of the computer program. Read the program instructions to realize various aspects of the present invention.
  • each block of the flowchart and/or block diagram and the combination of each block in the flowchart and/or block diagram can be implemented by a computer program.
  • These computer programs can be provided to the processors of general-purpose computers, special-purpose computers, or other programmable data processing devices to produce a machine that, when executed by the processors of the computer or other programmable data processing devices, produces A device that implements the functions/actions specified in one or more blocks in the flowchart and/or block diagram. It is also possible to store these computer programs in a readable storage medium.

Abstract

本发明提供了一种图像中物体的边缘检测方法、装置、电子设备和计算机可读存储介质,方法包括:对图像进行处理,获得图像中灰度轮廓的线条图;将线条图中相似的线条进行合并,得到多条初始合并线条,并根据多条初始合并线条确定一边界矩阵;将多条初始合并线条中相似的线条进行合并得到目标线条,并且将未合并的初始合并线条也作为目标线条;根据边界矩阵,从多条目标线条中确定多条参考边界线;通过预先训练的边界线区域识别模型对图像进行处理,得到图像中物体的多个边界线区域;针对每一边界线区域,从多条参考边界线中确定与该边界线区域对应的目标边界线;根据确定的多条目标边界线确定图像中物体的边缘。由此可以检测图像中物体的边缘。

Description

边缘检测方法、装置、电子设备和计算机可读存储介质 技术领域
本发明涉及图像处理技术领域,尤其涉及一种图像中物体的边缘检测方法、装置、电子设备和计算机可读存储介质。
背景技术
目前,人们经常对物体进行拍照,如对名片、试卷、化验单、文档等物体拍照,并希望对拍照得到的图像进行相应处理以获得图像中物体的信息。然而,拍照所得的图像中不仅包含物体,同时还不可避免地包含物体所在的外部环境。而外部环境区域对于识别图像中物体的信息而言是多余的,因此,在对图像进行处理以获得图像中物体的信息时,需要从图像中检测物体的边缘,以便根据物体的边缘将物体从图像中提取出来。而如何检测图像中物体的边缘是一件亟待解决的问题。
发明内容
本发明的目的在于提供一种图像中物体的边缘检测方法、装置、电子设备和计算机可读存储介质,以检测图像中物体的边缘。具体技术方案为:
第一方面,本发明提供了一种图像中物体的边缘检测方法,方法包括:
对图像进行处理,获得所述图像中灰度轮廓的线条图;
将所述线条图中相似的多条线条进行合并,得到多条初始合并线条,并根据多条所述初始合并线条确定一边界矩阵;
根据多条所述初始合并线条得到多条目标线条,包括:将多条所述初始合并线条中相似的多条所述初始合并线条进行合并得到至少一条所述目标线条,并且将未合并的一条或多条所述初始合并线条作为一条或多条所述目标线条;
根据所述边界矩阵,从多条所述目标线条中确定多条参考边界线;
通过预先训练的边界线区域识别模型对所述图像进行处理,得到所述图像中物体的多个边界线区域;其中,所述边界线区域识别模型是基于神经网 络的模型;
针对每一所述边界线区域,从多条所述参考边界线中确定与该边界线区域对应的一条目标边界线;
根据多个所述边界线区域确定的多条所述目标边界线确定所述图像中物体的边缘。
可选的,在所述图像中物体的边缘检测方法中,所述对图像进行处理,获得所述图像中灰度轮廓的线条图,包括:
通过基于OpenCV的边缘检测算法对图像进行处理,获得所述图像中灰度轮廓的线条图。
可选的,在所述图像中物体的边缘检测方法中,将所述线条图中相似的多条线条进行合并,得到多条初始合并线条,包括:
获取所述线条图中的多个长线条;其中,所述长线条为长度超过第一预设阈值的线条;
从多个所述长线条中获取多组第一类线条;其中,每组所述第一类线条包括至少两个依次相邻的长线条,且任意相邻的两个所述长线条之间的夹角均小于第二预设阈值;
针对每一组第一类线条,将该组第一类线条中的各个所述长线条依次进行合并得到一条所述初始合并线条。
可选的,在所述图像中物体的边缘检测方法中,将多条所述初始合并线条中相似的所述初始合并线条进行合并得到目标线条,包括:
从多条所述初始合并线条中获取多组第二类线条;其中,每组所述第二类线条包括至少两个依次相邻的所述初始合并线条,且任意相邻的两个所述初始合并线条之间的夹角均小于第三预设阈值;
针对每一组第二类线条,将该组第二类线条中的各个初始合并线条依次进行合并得到一条目标线条。
可选的,在所述图像中物体的边缘检测方法中,两条线条的夹角θ通过以下公式计算:
Figure PCTCN2019103850-appb-000001
其中,
Figure PCTCN2019103850-appb-000002
分别表示两条线条的向量。
可选的,在所述图像中物体的边缘检测方法中,所述边界矩阵按照以下方式确定:对多条所述初始合并线条以及所述长线条中未合并的长线条进行重新绘制,将重新绘制的所有线条中的像素点的位置信息对应到整个图像矩阵中,将图像矩阵中这些线条的像素点所在位置的值设置为第一数值、这些线条以外的像素点所在位置的值设置为第二数值,从而形成边界矩阵。
可选的,在所述图像中物体的边缘检测方法中,根据所述边界矩阵,从多条所述目标线条中确定多条参考边界线,包括:
针对每一条所述目标线条,将该目标线条进行延长,根据延长后的该目标线条确定一线条矩阵,然后将该线条矩阵与所述边界矩阵进行对比,计算延长后的该目标线条上属于所述边界矩阵的像素点的个数,作为该目标线条的成绩;其中,所述线条矩阵与所述边界矩阵的大小相同;
根据各个目标线条的成绩,从多条所述目标线条中确定多条参考边界线。
可选的,所述图像中物体的边缘检测方法中,针对每一所述边界线区域,从多条所述参考边界线中确定与该边界线区域相对应的一条目标边界线,包括:
计算每一条所述参考边界线的斜率;
针对每一个所述边界线区域,将该边界线区域转换为多条直线,并计算所述多条直线的平均斜率,再判断多条所述参考边界线中是否存在斜率与所述平均斜率相匹配的参考边界线,如果存在,将该参考边界线确定为与该边界线区域相对应的目标边界线。
可选的,在所述图像中物体的边缘检测方法中,所述方法还包括:
针对每一个所述边界线区域,如果判断出多条所述参考边界线中不存在斜率与所述平均斜率相匹配的参考边界线,则针对该边界线区域转换得到的每一条直线,将该直线形成的线条矩阵与所述边界矩阵进行对比,计算该直线上属于所述边界矩阵的像素点的个数,作为该直线的成绩;将成绩最好的直线确定为与该边界线区域相对应的目标边界线;其中,所述线条矩阵与所述边界矩阵的大小相同。
可选的,在所述图像中物体的边缘检测方法中,将该边界线区域转换为 多条直线,包括:
利用霍夫变换将该边界线区域转换为多条直线。
可选的,在所述图像中物体的边缘检测方法中,所述线条矩阵按照以下方式确定:对延长后的目标线条或直线进行重新绘制,将重新绘制的线条中的像素点的位置信息对应到整个图像矩阵中,将图像矩阵中线条的像素点所在位置的值设置为第一数值、线条以外的像素点所在位置的值设置为第二数值,从而形成线条矩阵。
可选的,在所述图像中物体的边缘检测方法中,所述边界线区域识别模型按照以下方式训练得到:
对图像样本集中的每个图像样本进行标注处理,以标注出每个图像样本中物体的边界线区域、内部区域和外部区域;
通过经过标注处理的图像样本集,对神经网络进行训练,以得到所述边界线区域识别模型。
可选的,在所述图像中物体的边缘检测方法中,所述方法还包括:
获得多条所述目标边界线的多个交点,对多个所述交点和多条所述目标边界线确定的区域进行投影变换,得到所述图像中的所述物体的正视图。
第二方面,本发明提供了一种图像中物体的边缘检测装置,装置包括:
获得模块,用于对图像进行处理,获得所述图像中灰度轮廓的线条图;
第一合并模块,用于将所述线条图中相似的多条线条进行合并,得到多条初始合并线条,并根据多条所述初始合并线条确定一边界矩阵;
第二合并模块,用于根据多条所述初始合并线条得到多条目标线条,包括:将多条所述初始合并线条中相似的多条所述初始合并线条进行合并得到至少一条所述目标线条,并且将未合并的一条或多条所述初始合并线条也作为一条或多条的所述目标线条;
第一确定模块,用于根据所述边界矩阵,从多条所述目标线条中确定多条参考边界线;
识别模块,用于通过预先训练的边界线区域识别模型对所述图像进行处理,得到所述图像中物体的多个边界线区域;其中,所述边界线区域识别模 型是基于神经网络的模型;
第二确定模块,用于针对每一所述边界线区域,从多条所述参考边界线中确定与该边界线区域对应的一条目标边界线;
第三确定模块,用于根据多个所述边界线区域确定的多条所述目标边界线确定所述图像中物体的边缘。
可选的,在所述图像中物体的边缘检测装置中,所述获得模块,具体用于:通过基于OpenCV的边缘检测算法对图像进行处理,获得所述图像中灰度轮廓的线条图。
可选的,在所述图像中物体的边缘检测装置中,所述第一合并模块将所述线条图中相似的多条线条进行合并,得到多条初始合并线条,包括:
获取所述线条图中的多个长线条;其中,所述长线条为长度超过第一预设阈值的线条;
从多个所述长线条中获取多组第一类线条;其中,每组所述第一类线条包括至少两个依次相邻的长线条,且任意相邻的两个所述长线条之间的夹角均小于预设阈值;
针对每一组第一类线条,将该组第一类线条中的各个所述长线条依次进行合并得到一条所述初始合并线条。
可选的,在所述图像中物体的边缘检测装置中,所述第二合并模块将多条所述初始合并线条中相似的所述初始合并线条进行合并得到目标线条,具体为:从多条所述初始合并线条中获取多组第二类线条;其中,每组所述第二类线条包括至少两个依次相邻的所述初始合并线条,且任意相邻的两个所述初始合并线条之间的夹角均小于第三预设阈值;针对每一组第二类线条,将该组第二类线条中的各个初始合并线条依次进行合并得到一条目标线条。
可选的,在所述图像中物体的边缘检测装置中,两条线条的夹角θ通过以下公式计算:
Figure PCTCN2019103850-appb-000003
其中,
Figure PCTCN2019103850-appb-000004
分别表示两条线条的向量。
可选的,在所述图像中物体的边缘检测装置中,所述边界矩阵通过以下方式确定:对多条所述初始合并线条以及所述长线条中未合并的长线条进行重新绘制,将重新绘制的所有线条中的像素点的位置信息对应到整个图像矩 阵中,将图像矩阵中这些线条的像素点所在位置的值设置为第一数值、这些线条以外的像素点所在位置的值设置为第二数值,从而形成边界矩阵。
可选的,在所述图像中物体的边缘检测装置中,所述第一确定模块,包括:
第一计算子模块,用于针对每一条所述目标线条,将该目标线条进行延长,根据延长后的该目标线条确定一线条矩阵,然后将该线条矩阵与所述边界矩阵进行对比,计算延长后的该目标线条上属于所述边界矩阵的像素点的个数,作为该目标线条的成绩;其中,所述线条矩阵与所述边界矩阵的大小相同;
第一确定子模块,用于根据各个目标线条的成绩,从多条所述目标线条中确定多条参考边界线。
可选的,在所述图像中物体的边缘检测装置中,所述第二确定模块,包括:
第二计算子模块,用于计算每一条所述参考边界线的斜率;
第二确定子模块,用于针对每一个所述边界线区域,将该边界线区域转换为多条直线,并计算所述多条直线的平均斜率,再判断多条所述参考边界线中是否存在斜率与所述平均斜率相匹配的参考边界线,如果存在,将该参考边界线确定为与该边界线区域相对应的目标边界线。
可选的,在所述图像中物体的边缘检测装置中,所述第二确定子模块,还用于:
针对每一个所述边界线区域,如果判断出多条所述参考边界线中不存在斜率与所述平均斜率相匹配的参考边界线,则针对该边界线区域转换得到的每一条直线,将该直线形成的线条矩阵与所述边界矩阵进行对比,计算该直线上属于所述边界矩阵的像素点的个数,作为该直线的成绩;将成绩最好的直线确定为与该边界线区域相对应的目标边界线;其中,所述线条矩阵与所述边界矩阵的大小相同。
可选的,在所述图像中物体的边缘检测装置中,所述第二确定子模块将该边界线区域转换为多条直线,具体为:利用霍夫变换将该边界线区域转换 为多条直线。
可选的,在所述图像中物体的边缘检测装置中,所述线条矩阵按照以下方式确定:对延长后的目标线条或直线进行重新绘制,将重新绘制的线条中的像素点的位置信息对应到整个图像矩阵中,将图像矩阵中线条的像素点所在位置的值设置为第一数值、线条以外的像素点所在位置的值设置为第二数值,从而形成线条矩阵。
可选的,在所述图像中物体的边缘检测装置中,所述装置还包括:模型训练模块,用于按照以下方式训练得到边界线区域识别模型;
对图像样本集中的每个图像样本进行标注处理,以标注出每个图像样本中物体的边界线区域、内部区域和外部区域;通过经过标注处理的图像样本集,对神经网络进行训练,以得到所述边界线区域识别模型。
可选的,在所述图像中物体的边缘检测装置中,所述装置还包括:变换模块,用于获得多条所述目标边界线的多个交点,对多个所述交点和多条所述目标边界线确定的区域进行投影变换,得到所述图像中的所述物体的正视图。
第三方面,本发明还提供了一种电子设备,包括处理器、通信接口、存储器和通信总线,其中,所述处理器、所述通信接口和所述存储器通过所述通信总线完成相互间的通信;
所述存储器,用于存放计算机程序;
所述处理器,用于执行所述存储器上所存放的程序时,实现上述第一方面所述的图像中物体的边缘检测方法的步骤。
第四方面,本发明还提供了一种计算机可读存储介质,所述计算机可读存储介质内存储有计算机程序,所述计算机程序被处理器执行时实现上述第一方面述所述的图像中物体的边缘检测方法的步骤。
与现有技术相比,本发明提供的一种图像中物体的边缘检测方法、装置、电子设备和计算机可读存储介质具有如下有益效果:
首先获得图像中灰度轮廓的线条图,将线条图中相似的线条进行合并得到多条初始合并线条,并根据多条初始合并线条确定一边界矩阵,并且继续 将多条初始合并线条中相似的线条进行合并得到目标线条,同时将不能合并的初始合并线条也直接作为目标线条,然后根据边界矩阵从多条目标线条中确定多条参考边界线,同时还通过预先训练的边界线区域识别模型对图像进行处理,得到图像中物体的多个边界线区域,从而可以针对每一边界线区域,从多条参考边界线中确定与该边界线区域对应的目标边界线,进而根据确定的多条目标边界线确定图像中物体的边缘。本发明通过根据图像获得参考边界线,结合机器学习识别边界线区域,从而共同确定图像中物体的目标边界线,实现了对图像中物体的边缘检测,能够快速定位图像中物体边缘的位置,并且提高边缘检测的准确性。
附图说明
为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他附图。
图1是本发明一实施例提供的图像中物体的边缘检测方法的流程图;
图2A-图2C是本发明一具体实施例中图像的示例图;
图3A-图3C是本发明另一具体实施例中图像的示例图;
图4是线条合并过程的对照示意图;
图5是本发明一实施例提供的图像中物体的边缘检测装置的结构图;
图6是本发明一实施例提供的一种电子设备的结构示意图。
具体实施方式
以下结合附图和具体实施例对本发明提出的一种图像中物体的边缘检测方法、装置、电子设备及计算机可读存储介质作进一步详细说明。根据权利要求书和下面说明,本发明的优点和特征将更清楚。需说明的是,附图均采用非常简化的形式且均使用非精准的比例,仅用以方便、明晰地辅助说明本发明实施例的目的。此外,需要说明的是,本文的框图和/或流程图中的每个 方框、以及框图和/或流程图中的方框的组合,可以用执行规定的功能或动作的专用的基于硬件的系统来实现,或者可以用专用硬件与计算机程序指令的组合来实现。对于本领域技术人员来说公知的是,通过硬件方式实现、通过软件方式实现以及通过软件和硬件结合的方式实现都是等价的。
为了使本发明的目的、特征和优点能够更加明显易懂,请参阅附图1至6。须知,本说明书所附图式所绘示的结构、比例、大小等,均仅用以配合说明书所揭示的内容,以供熟悉此技术的人士了解与阅读,并非用以限定本发明实施的限定条件,故不具技术上的实质意义,任何结构的修饰、比例关系的改变或大小的调整,在不影响本发明所能产生的功效及所能达成的目的下,均应仍落在本发明所揭示的技术内容能涵盖的范围内。
为解决现有技术的问题,本发明实施例提供了一种图像中物体的边缘检测方法、装置、电子设备及计算机可读存储介质。
需要说明的是,本发明实施例的图像中物体的边缘检测方法可应用于本发明实施例的图像中物体的边缘检测装置,该图像中物体的边缘检测装置可被配置于电子设备上。其中,该电子设备可以是个人计算机、移动终端等,该移动终端可以是手机、平板电脑等具有各种操作系统的硬件设备。
图1是本发明一实施例提供的一种图像中物体的边缘检测方法的流程示意图。请参考图1,一种图像中物体的边缘检测方法可以包括如下步骤:
步骤S101,对图像进行处理,获得所述图像中灰度轮廓的线条图。
其中,所述图像为用户对某一物体进行拍照所得的图像,物体例如可以是名片、试卷、化验单、文档等。如图2A、图3A所示的图像,其分别是对化验单和名片进行拍照所得的图像。
具体的,对图像进行处理,获得所述图像中灰度轮廓的线条图的方式,可以为:通过基于OpenCV的边缘检测算法对所述图像进行处理,获得所述图像中灰度轮廓的线条图。OpenCV为一种开源计算机视觉库,基于OpenCV的边缘检测算法包括Sobel、Scarry、Canny、Laplacian、Prewitt、Marr-Hildresh、scharr等多种算法。其中,本实施例中采用Canny边缘检测算法,Canny边缘检测算法是一个多阶段的算法,即由多个步骤构成,包括:1、 图像降噪:用高斯滤波器平滑图像;2、计算图像梯度:用一阶偏导有限差分计算梯度幅值和方向;3、非极大值抑制:对梯度幅值进行非极大值抑制;4、阈值筛选:用双阈值算法检测和连接边缘。
通过上述算法处理后,可得到所述图像中灰度轮廓的线条图,例如对图2A、图3A所示的图像通过上述算法处理后,分别得到如图2B、图3B所示的线条图,在线条图中,各个线条实际上是一段一段很小的线段,其中,图像中物体的边界线线条实际上也被分为一段一段很小的线段,因此需要将相似的线条连接起来,并进行后续处理以得到物体的边界线线条。在实际应用中,线条图中各个小线段的表现形式是数组的形式,每个线段都是由起点和终点对应的像素点在整个线条图中的坐标值组成。
步骤S102,将所述线条图中相似的线条进行合并,得到多条初始合并线条,并根据多条所述初始合并线条确定一边界矩阵。
具体的,按照以下方式将所述线条图中相似的线条进行合并,得到多条初始合并线条:步骤A:获取所述线条图中的长线条;其中,所述长线条为长度超过第一预设阈值的线条;步骤B:从所述长线条中获取多组第一类线条;其中,所述第一类线条包括至少两个依次相邻的长线条,且任意相邻的两长线条之间的夹角均小于第二预设阈值;步骤C:针对每一组第一类线条,将该组第一类线条中的各个长线条依次进行合并得到一条初始合并线条。
在步骤A中,所述线条图中的长线条指的是所述线条图中长度超过一定阈值的线条,例如将长度超过2个像素的线条定义为长线条。仅获取所述线条图中的长线条进行后续合并处理,而不考虑所述线条图中的一些较短的线条,这样可以在合并线条时避免物体内部和外部的线条干扰,例如内部的文字和图形、外部的其它物体等的对应的线条。
对于步骤B,可以通过以下方式获取第一类线条:首先选择一个长线条,然后从该长线条开始依次判断两条相邻线条之间的夹角是否小于第二预设阈值,若判断出某一长线条与相邻线条之间的夹角不小于第二预设阈值时,则可以将所选择的长线条以及到该某一长线条之间的所有依次相邻的长线条组成一组第一类线条,接着再重复上述过程,从该某一长线条的相邻线条开始 依次判断两条相邻线条之间的夹角是否小于第二预设阈值,依次类推,直到遍历完所有长线条,从而得到多组第一类线条。
下面以图4为例,对上述过程进行说明。在一个实施例中,例如首先选择第一个长线条A,判断该长线条A与相邻线条B之间的夹角是否小于第二预设阈值,二者之间的夹角是小于第二预设阈值的,表示长线条A、B是属于同一组第一类线条的,再继续判断长线条B与相邻线条C的夹角,二者之间的夹角也是小于第二预设阈值的,表示长线条C与B、A也是属于同一组第一类线条的,继续判断长线条C与相邻线条D的夹角,二者之间的夹角也是小于第二预设阈值的,表示长线条D与C、B、A也是属于同一组第一类线条的,继续判断长线条D与相邻线条E的夹角,二者之间的夹角是大于第二预设阈值的,表示长线条E与D、C、B、A不属于同一组第一类线条,进而可以将长线条A、B、C、D作为一组第一类线条。然后,再从长线条E开始依次判断两条相邻线条之间的夹角是否小于第二预设阈值,同样的方式可以得到长线条G、H、I、J为一组第一类线条,长线条M、N、O也为一组第一类线条。
在另一个实施例中,也可以首先任意选择一个长线条,例如选择长线条D,与该长线条D相邻的线条有C和E,则分别判断长线条D、C之间的夹角以及线条D、E之间的夹角,由于D、C之间的夹角小于第二预设阈值,则D、C属于同一组第一类线条,由于D、E之间的夹角大于第二预设阈值,则D、E不属于同一组第一类线条,然后一方面可以继续从长线条C开始判断依次相邻的其它线条之间的夹角,从而确定与D属于同一组第一类线条的其它线条、以及其他组的第一类线条,另一方面可以从长线条E开始判断依次相邻的其它线条之间的夹角,从而确定其他组的第一类线条。以此类推,最终也可确定出长线条A、B、C、D为一组第一类线条,长线条G、H、I、J为一组第一类线条,长线条M、N、O也为一组第一类线条。
在步骤B中,两条线条的夹角θ通过以下公式计算:
Figure PCTCN2019103850-appb-000005
其中,
Figure PCTCN2019103850-appb-000006
分别表示相邻两条线条的向量。其中,所述第二预设阈值的数值可以根据实际情况进行设置,例如设置为夹角θ小于15度时进行合并,即第 二预设阈值为15°。
在步骤C中将两个线条合并,指的是将两个线条的斜率取平均值,此平均值为合并后线条的斜率。在实际应用中,两个线条合并是根据两个线条的数组形式进行计算,从而计算得到合并后线条的起点和终点对应的像素点在整个线条图中的坐标值,进而根据计算得到的坐标值形成合并后线条的数组并进行存储。将每一组第一类线条中的各个长线条依次进行合并,举例而言,将图4中第一组第一类线条A、B、C、D依次合并,可以是先将长线条A与B合并,合并后得到的新线条再与长线条C合并,与长线条C合并后的得到的新线条再与长线条D合并,从而得到初始合并线条1。同理,对第二组第一类线条经过合并后得到初始合并线条2,对第三组第一类线条经过合并后得到初始合并线条3。经过上述合并后,长线条中还有E、F、K、L没有被合并。
另外,所述边界矩阵通过以下方式确定:对多条所述初始合并线条以及所述长线条中未合并的线条进行重新绘制,将重新绘制的所有线条中的像素点的位置信息对应到整个图像矩阵中,即以矩阵形式表现的图像,将图像矩阵中这些线条的像素点所在位置的值设置第一数值、这些线条以外的像素点所在位置的值设置为第二数值,从而形成边界矩阵。具体而言,所述边界矩阵可以是一个与图像矩阵大小相同的矩阵,例如图像的大小为1024×1024像素,则图像矩阵为1024×1024的矩阵,那么边界矩阵也就是一个1024×1024的矩阵,将多条所述初始合并线条以及所述长线条中未合并的线条按照一定的线宽(如线宽为2)重新绘制,根据重新绘制的线条的像素点对应到矩阵中的位置来对边界矩阵进行值的填充,线条上像素点对应到矩阵中的位置都设定为第一数值例如255,没有线条的像素点对应到矩阵中的位置设定为第二数值例如0,从而形成整个图片的超大矩阵即边界矩阵。需要说明的是,由于多条所述初始合并线条以及所述长线条中未合并的线条均是以数组的形式存储的,因此在确定所述边界矩阵时需要将其形成为实际线条数据,因此将线条重新绘制例如按照线宽为2进行重新绘制,从而获得每个线条上各个点对应的像素点的坐标值,进而根据所获得的坐标值对所述边界矩阵中进行值的填充,例如将所述边界矩阵中与坐标值相对应的位置的值设为255,其余位置的 值设为0。
下面示例性的提供一个边界矩阵,该边界矩阵为10×10矩阵,其中该边界矩阵中所有值为255的位置连接起来即为多条初始合并线条以及长线条中未合并的线条。
Figure PCTCN2019103850-appb-000007
步骤S103,将多条所述初始合并线条中相似的线条进行合并得到目标线条,并且将未合并的所述初始合并线条也作为目标线条。
在步骤S102中,合并后的初始合并线条为多条较长的线条。步骤S103可以根据上述步骤S102中的合并规则,继续判断多条初始合并线条中是否存在相似的线条从而将相似线条再次进行合并得到多条目标线条,同时将不能进行合并的初始合并线条也作为目标线条。
其中,将多条所述初始合并线条中相似的线条进行合并得到目标线条的具体的合并步骤如下:步骤a:从多条所述初始合并线条中获取多组第二类线条;其中,所述第二类线条包括至少两个依次相邻的初始合并线条,且任意相邻的两初始合并线条之间的夹角均小于第三预设阈值;步骤b:针对每一组第二类线条,将该组第二类线条中的各个初始合并线条依次进行合并得到一条目标线条。
上述对初始合并线条进行合并的步骤的原理,与步骤S102中对线条图中线条进行合并的原理相同,可以参见步骤S102中的相关描述,在此不做赘述。其中,所述第三预设阈值可以和所述第二预设阈值相同,也可以不同,本实施例对此不做限定,例如将所述第三预设阈值设置为夹角10度。如图4所示的线条合并前后对照图,通过上述对初始合并线条1、2、3进行合并的步骤 后,由于初始合并线条1和2的夹角小于第三预设阈值,而初始合并线条3与初始2的夹角大于第三预设阈值,因此,初始合并线条1、2可以进一步合并为目标线条12,初始合并线条3不能合并则将初始合并线条3直接作为一个目标线条。
至此获得了多条目标线条,在多条目标线条中不仅存在参考边界线,还存在一些较长的干扰线条,例如,内部的文字和图形、外部的其它物体等的对应的线条经过合并处理后得到的较长线条,这些干扰线条会根据后续的处理(具体通过步骤S104-步骤S105的处理)及规则进行去除。
步骤S104,根据所述边界矩阵,从多条所述目标线条中确定多条参考边界线。
具体的,根据所述边界矩阵,从多条所述目标线条中确定多条参考边界线,包括:首先,针对每一条所述目标线条,将该目标线条进行延长,根据延长后的该目标线条确定一线条矩阵,然后将该线条矩阵与所述边界矩阵进行对比,计算延长后的该目标线条上属于所述边界矩阵的像素点的个数,作为该目标线条的成绩,其中线条矩阵与边界矩阵的大小相同;然后,根据各个目标线条的成绩,从多条所述目标线条中确定多条参考边界线。
其中,所述线条矩阵可以按照以下方式确定:对延长后的目标线条进行重新绘制,将重新绘制的线条中的像素点的位置信息对应到整个图像矩阵中,将图像矩阵中线条的像素点所在位置的值设置为第一数值、线条以外的像素点所在位置的值设置为第二数值,从而形成线条矩阵。所述线条矩阵的形成方式与所述边界矩阵类似,在此不做赘述。需要说明的是,所述目标线条是以数组的形式存储的,即存储其起点和终点的坐标值,对目标线条进行延长后,延长后的目标线条在存储时是以延长后的目标线条的起点和终点的坐标值形成数组的,因此在对延长后的目标线条进行重新绘制时,也是按照相同的线宽例如线宽为2进行重新绘制,从而获得延长后的目标线条上各个点对应的像素点的坐标值,进而根据坐标值对线条矩阵进行值的填充,即将线条矩阵中与坐标值相对应的位置的值设为255,其余位置的值设为0。
将合并后的目标线条进行延长,判断其上的像素点落入步骤S102中初始 合并线条和所述长线条中未合并的线条上最多的目标线条作为参考边界线。针对每一条目标线条,判断上有多少像素点是属于边界矩阵的,计算一个成绩,具体为:将该目标线条进行延长,该目标线条延长后所得的线条也按照边界矩阵的形成方式形成一线条矩阵,将该线条矩阵与边界矩阵进行对比来判断有多少像素点落入到边界矩阵里面,即判断两个矩阵中有多少相同位置的像素点具有相同的第一数值例如255,从而计算成绩。这时成绩最好的线条可能还是有较多条,因此,根据各个目标线条的成绩,从多条目标线条中确定成绩最好的多条目标线条作为参考边界线。
例如,一条延长后的目标线条形成的线条矩阵如下,通过将该线条矩阵与上述的边界矩阵进行对比可知延长后的该目标线条上有7个像素点落入到边界矩阵里面,从而得到该目标线条的成绩。
Figure PCTCN2019103850-appb-000008
步骤S105,通过预先训练的边界线区域识别模型对所述图像进行处理,得到所述图像中物体的多个边界线区域。其中,所述边界线区域识别模型是基于神经网络的模型。
首先,通过机器学习训练来建立所述边界线区域识别模型,此模型可以为基于神经网络的模型,所述边界线区域识别模型可以通过如下过程训练得到:对图像样本集中的每个图像样本进行标注处理,以标注出每个图像样本中物体的边界线区域、内部区域和外部区域;以及通过经过标注处理的图像样本集,对神经网络进行训练,以得到边界线区域识别模型。
通过机器学习训练建立的所述边界线区域识别模型识别所述图像(即原始图像),可以识别出所述图像中的边界线区域、内部区域(即物体所在区域) 和外部区域(即物体的外部区域)3个部分,从而获取原始图像的多张(如4张)各个方向的边缘轮廓图(即图像中物体边界线区域),此时边缘轮廓较粗。
可以理解的是,通过机器学习训练建立的模型来识别出所述图像中物体的边界线区域,并在后续步骤S106中通过边界线区域从步骤S104所确定的多个参考边界线中确定目标边界线,可以去除步骤S102和S103中误识别的线条,例如落入名片或者文档中间的线条、表格中间的线条等。
步骤S106,针对每一所述边界线区域,从多条所述参考边界线中确定与该边界线区域对应的目标边界线。
具体的,针对每一所述边界线区域,从多条所述参考边界线中确定与该边界线区域相对应的目标边界线,可以包括:首先,计算每一条所述参考边界线的斜率;然后,针对每一个所述边界线区域,将该边界线区域转换为多条直线,并计算所述多条直线的平均斜率,再判断多条所述参考边界线中是否存在斜率与所述平均斜率相匹配的参考边界线,如果存在,将该参考边界线确定为与该边界线区域相对应的目标边界线。其中,可以利用霍夫变换将该边界线区域转换为多条直线,当然也可以采用其它方式进行转换,本实施例对此不做限定。
本实施例中,所述边界线区域中的边缘轮廓较粗,针对每一边界线区域,可以利用霍夫变换将边界线区域转换为多条直线,这些线条具有近似的斜率,求得平均斜率,然后和每一条参考边界线的斜率进行比较,判断多条参考边界线中是否存在斜率与所述平均斜率相匹配的参考边界线,即从多条参考边界线中找到最为近似的参考边界线,作为与该边界线区域相对应的目标边界线。
由于所确定的目标边界线的斜率与平均斜率的差距不能太大,因此在将平均斜率与每一参考边界线的斜率进行比较时,会设定一个比较阈值,当某一参考边界线的斜率与平均斜率之差的绝对值小于此比较阈值时,判定该参考边界线的斜率是与平均斜率相匹配的参考边界线,进而判定该参考边界线是与边界线区域相对应的目标边界线。
进一步的,针对每一个所述边界线区域,如果判断出多条所述参考边界 线中不存在斜率与所述平均斜率相匹配的参考边界线,则进行如下处理:针对该边界线区域转换得到的每一条直线,将该直线形成的线条矩阵与所述边界矩阵进行对比,计算该直线上属于所述边界矩阵的像素点的个数,作为该直线的成绩;将成绩最好的直线确定为与该边界线区域相对应的目标边界线。如果成绩最好的直线有多条,则根据排序算法将其中最先出现的一条直线作为最佳边界线。其中,所述线条矩阵按照以下方式确定:对直线进行重新绘制,将重新绘制的线条中的像素点的位置信息对应到整个图像矩阵中,将图像矩阵中线条的像素点所在位置的值设置为第一数值、线条以外的像素点所在位置的值设置为第二数值,从而形成线条矩阵。所述线条矩阵的形成方式与所述边界矩阵类似,在此不做赘述。
如果不能从参考边界线中找到与某一边界线区域相对应的目标边界线,则对霍夫变换获取的多条直线按照步骤S102和S104中所述的形成矩阵的方式形成对应的线条矩阵,判断哪条直线的像素点落入边界矩阵里面的成绩最好,则认为是该边界线区域相对应的目标边界线。将直线形成的线条矩阵与边界矩阵进行对比来计算直线的成绩的方式可以参照步骤S104中的相关描述,在此不做赘述。
如图2A所示的图像,通过上述处理后得到的目标边界线为图2B中所示的四个较长线条;如图3A所示的图像,通过上述处理后得到的目标边界线为图3B中所示的四个较长线条。
步骤S107,根据确定的多条所述目标边界线确定所述图像中物体的边缘。
在确定多条目标边界线后,由于每条目标边界线均对应图像中物体的一个边界线区域,因此多条目标边界线构成了图像中物体的边缘。如图2A所示的图像,图像中物体的边缘由图2B中的四个较长线条即目标边界线a1、a2、a3、a4构成;如图3A所示的图像,图像中物体的边缘由图3B中的四个较长线条即目标边界线b1、b2、b3、b4构成。
进一步的,还可以获得多条所述目标边界线的多个交点,对多个所述交点和多条所述目标边界线确定的区域进行投影变换,得到所述图像中的所述物体的正视图。每两条相邻的目标边界线相交得到一个交点,各个交点和各 个目标边界线共同限定了图像中物体所在的区域。
投影变换(Perspective Transformation)是将图片投影到一个新的视平面(Viewing Plane),也称作投影映射(Projective Mapping)。由于拍照所得的图像中,物体的真实形状在图像中发生了变化,即产生了几何畸变。如图2A所示的图像,化验单的形状本来为矩形,但是图像中化验单的形状发生了变化,变为了平行四边形。因此,对图像中物体所在的区域进行投影变换,可以将图像中物体所在区域由平行四边形变换为正方形,即将图像中物体所在的区域转正,从而去除几何畸变的影响,得到图像中物体的正视图。其中,投影变换是根据空间投影换算坐标来将像素进行处理获取正视图的,在此不做赘述。如图2A所示的图像,最终获取的图像中物体化验单的正视图如图2C所示;如图3A所示的图像,最终获取的图像中物体名片的正视图如图3C所示。
综上所述,本实施例首先获得图像中灰度轮廓的线条图,将线条图中相似的线条进行合并得到多条初始合并线条,并根据多条初始合并线条确定一边界矩阵,并且继续将多条初始合并线条中相似的线条进行合并得到目标线条,同时将不能合并的初始合并线条也直接作为目标线条,然后根据边界矩阵从多条目标线条中确定多条参考边界线,同时还通过预先训练的边界线区域识别模型对图像进行处理,得到图像中物体的多个边界线区域,从而可以针对每一边界线区域,从多条参考边界线中确定与该边界线区域对应的目标边界线,进而根据确定的多条目标边界线确定图像中物体的边缘。本实施例通过根据图像获得参考边界线,结合机器学习识别边界线区域,从而共同确定图像中物体的目标边界线,实现了对图像中物体的边缘检测,能够快速定位图像中物体边缘的位置,并且提高边缘检测的准确性。
相应于上述方法实施例,本发明一实施例还提供了一种图像中物体的边缘检测装置,图5是本发明一实施例提供的一种图像中物体的边缘检测装置的结构示意图。请参考图5,一种图像中物体的边缘检测装置包括:
获得模块201,用于对图像进行处理,获得图像中灰度轮廓的线条图;
第一合并模块202,用于将所述线条图中相似的线条进行合并,得到多条初始合并线条,并根据多条所述初始合并线条确定一边界矩阵;
第二合并模块203,用于将多条所述初始合并线条中相似的线条进行合并得到目标线条,并且将未合并的所述初始合并线条也作为目标线条;
第一确定模块204,用于根据所述边界矩阵,从多条所述目标线条中确定多条参考边界线;
识别模块205,用于通过预先训练的边界线区域识别模型对所述图像进行处理,得到所述图像中物体的多个边界线区域;其中,所述边界线区域识别模型是基于神经网络的模型;
第二确定模块206,用于针对每一所述边界线区域,从多条所述参考边界线中确定与该边界线区域对应的目标边界线;
第三确定模块207,用于根据确定的多条所述目标边界线确定所述图像中物体的边缘。
可选的,所述获得模块201,具体用于:通过基于OpenCV的边缘检测算法对图像进行处理,获得所述图像中灰度轮廓的线条图。
可选的,所述第一合并模块202将所述线条图中相似的线条进行合并,得到多条初始合并线条,具体为:获取所述线条图中的长线条,其中,所述长线条为长度超过第一预设阈值的线条;从所述长线条中获取多组第一类线条,其中,所述第一类线条包括至少两个依次相邻的长线条,且任意相邻的两长线条之间的夹角均小于第二预设阈值;针对每一组第一类线条,将该组第一类线条中的各个长线条依次进行合并得到一条初始合并线条。
可选的,所述第二合并模块203将多条所述初始合并线条中相似的线条进行合并得到目标线条,具体为:从多条所述初始合并线条中获取多组第二类线条;其中,所述第二类线条包括至少两个依次相邻的初始合并线条,且任意相邻的两初始合并线条之间的夹角均小于第三预设阈值;针对每一组第二类线条,将该组第二类线条中的各个初始合并线条依次进行合并得到一条目标线条。
可选的,两条线条的夹角θ通过以下公式计算:
Figure PCTCN2019103850-appb-000009
其中,
Figure PCTCN2019103850-appb-000010
分别表示两条线条的向量。
可选的,所述边界矩阵通过以下方式确定:对多条所述初始合并线条以 及所述长线条中未合并的线条进行重新绘制,将重新绘制的所有线条中的像素点的位置信息对应到整个图像矩阵中,将图像矩阵中这些线条的像素点所在位置的值设置第一数值、这些线条以外的像素点所在位置的值设置为第二数值,从而形成边界矩阵。
可选的,所述第一确定模块204,包括:
第一计算子模块,用于针对每一条所述目标线条,将该目标线条进行延长,根据延长后的该目标线条确定一线条矩阵,然后将该线条矩阵与所述边界矩阵进行对比,计算延长后的该目标线条上属于所述边界矩阵的像素点的个数,作为该目标线条的成绩;其中,所述线条矩阵与所述边界矩阵的大小相同;
第一确定子模块,用于根据各个目标线条的成绩,从多条所述目标线条中确定多条参考边界线。
可选的,所述第二确定模块206,包括:
第二计算子模块,用于计算每一条所述参考边界线的斜率;
第二确定子模块,用于针对每一个所述边界线区域,将该边界线区域转换为多条直线,并计算所述多条直线的平均斜率,再判断多条所述参考边界线中是否存在斜率与所述平均斜率相匹配的参考边界线,如果存在,将该参考边界线确定为与该边界线区域相对应的目标边界线。
可选的,所述第二确定子模块,还用于:针对每一个所述边界线区域,如果判断出多条所述参考边界线中不存在斜率与所述平均斜率相匹配的参考边界线,则针对该边界线区域转换得到的每一条直线,将该直线形成的线条矩阵与所述边界矩阵进行对比,计算该直线上属于所述边界矩阵的像素点的个数,作为该直线的成绩;将成绩最好的直线确定为与该边界线区域相对应的目标边界线;其中,所述线条矩阵与所述边界矩阵的大小相同。
可选的,所述第二确定子模块将该边界线区域转换为多条直线,具体为:利用霍夫变换将该边界线区域转换为多条直线。
可选的,所述线条矩阵按照以下方式确定:对延长后的目标线条或直线进行重新绘制,将重新绘制的线条中的像素点的位置信息对应到整个图像矩 阵中,将图像矩阵中线条的像素点所在位置的值设置为第一数值、线条以外的像素点所在位置的值设置为第二数值,从而形成线条矩阵。
可选的,所述装置还包括:模型训练模块,用于按照以下方式训练得到边界线区域识别模型;
对图像样本集中的每个图像样本进行标注处理,以标注出每个图像样本中物体的边界线区域、内部区域和外部区域;通过经过标注处理的图像样本集,对神经网络进行训练,以得到所述边界线区域识别模型。
可选的,所述装置还包括:变换模块,用于获得多条所述目标边界线的多个交点,对多个所述交点和多条所述目标边界线确定的区域进行投影变换,得到所述图像中的所述物体的正视图。
综上所述,本实施例首先获得图像中灰度轮廓的线条图,将线条图中相似的线条进行合并得到多条初始合并线条,并根据多条初始合并线条确定一边界矩阵,并且继续将多条初始合并线条中相似的线条进行合并得到目标线条,同时将不能合并的初始合并线条也直接作为目标线条,然后根据边界矩阵从多条目标线条中确定多条参考边界线,同时还通过预先训练的边界线区域识别模型对图像进行处理,得到图像中物体的多个边界线区域,从而可以针对每一边界线区域,从多条参考边界线中确定与该边界线区域对应的目标边界线,进而根据确定的多条目标边界线确定图像中物体的边缘。本实施例通过根据图像获得参考边界线,结合机器学习识别边界线区域,从而共同确定图像中物体的目标边界线,实现了对图像中物体的边缘检测,能够快速定位图像中物体边缘的位置,并且提高边缘检测的准确性。
本发明一实施例还提供了一种电子设备,图6是本发明一实施例提供的一种电子设备的结构示意图。请参考图6,一种电子设备包括处理器301、通信接口302、存储器303和通信总线304,其中,处理器301,通信接口302,存储器303通过通信总线304完成相互间的通信,存储器303用于存放计算机程序,处理器301用于执行存储器303上所存放的程序时,实现如下步骤:
对图像进行处理,获得所述图像中灰度轮廓的线条图;
获取所述线条图中的长线条,将所述长线条中相似的线条进行合并,得 到多条初始合并线条,并根据多条所述初始合并线条以及所述长线条中未合并的线条确定一边界矩阵;
将多条所述初始合并线条中相似的线条进行合并,得到多条目标线条;
根据所述边界矩阵,从多条所述目标线条中确定多条参考边界线;
通过预先训练的边界线区域识别模型对所述图像进行处理,得到所述图像中物体的多个边界线区域;其中,所述边界线区域识别模型是通过标注有边界线区域的图像样本对神经网络模型进行训练得到的;
针对每一所述边界线区域,从多条所述参考边界线中确定与该边界线区域对应的目标边界线;
根据确定的多条所述目标边界线确定所述图像中物体的边缘。
关于该方法各个步骤的具体实现以及相关解释内容可以参见上述图1所示的方法实施例,在此不做赘述。另外,处理器301执行存储器303上所存放的程序而实现的图像中物体的边缘检测方法的其他实现方式,与前述方法实施例部分所提及的实现方式相同,这里也不再赘述。
综上所述,本实施例首先获得图像中灰度轮廓的线条图,将线条图中相似的线条进行合并得到多条初始合并线条,并根据多条初始合并线条确定一边界矩阵,并且继续将多条初始合并线条中相似的线条进行合并得到目标线条,同时将不能合并的初始合并线条也直接作为目标线条,然后根据边界矩阵从多条目标线条中确定多条参考边界线,同时还通过预先训练的边界线区域识别模型对图像进行处理,得到图像中物体的多个边界线区域,从而可以针对每一边界线区域,从多条参考边界线中确定与该边界线区域对应的目标边界线,进而根据确定的多条目标边界线确定图像中物体的边缘。本实施例通过根据图像获得参考边界线,结合机器学习识别边界线区域,从而共同确定图像中物体的目标边界线,实现了对图像中物体的边缘检测,能够快速定位图像中物体边缘的位置,并且提高边缘检测的准确性。
所述电子设备可以是桌上型计算机、笔记本、掌上电脑及云端服务器等计算设备。上述电子设备提到的通信总线可以是外设部件互连标准(Peripheral Component Interconnect,PCI)总线或扩展工业标准结构(Extended Industry  Standard Architecture,EISA)总线等。该通信总线可以分为地址总线、数据总线、控制总线等。为便于表示,图中仅用一条粗线表示,但并不表示仅有一根总线或一种类型的总线。
通信接口用于上述电子设备与其他设备之间的通信。存储器可以包括随机存取存储器(Random Access Memory,RAM),也可以包括非易失性存储器(Non-Volatile Memory,NVM),例如至少一个磁盘存储器。可选的,存储器还可以是至少一个位于远离前述处理器的存储装置。
上述的处理器可以是通用处理器,包括中央处理器(Central Processing Unit,CPU)、网络处理器(Network Processor,NP)等;还可以是数字信号处理器(Digital Signal Processing,DSP)、专用集成电路(Application Specific Integrated Circuit,ASIC)、现场可编程门阵列(Field-Programmable Gate Array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等,所述处理器是所述电子设备的控制中心,利用各种接口和线路连接整个电子设备的各个部分。
本发明一实施例提供了一种计算机可读存储介质,该计算机可读存储介质内存储有计算机程序,该计算机程序被处理器执行时能实现如下步骤:
对图像进行处理,获得所述图像中灰度轮廓的线条图;
获取所述线条图中的长线条,将所述线条图中相似的线条进行合并,得到多条初始合并线条,并根据多条所述初始合并线条确定一边界矩阵;
将多条所述初始合并线条中相似的线条进行合并,得到多条目标线条;
根据所述边界矩阵,从多条所述目标线条中确定多条参考边界线;
通过预先训练的边界线区域识别模型对所述图像进行处理,得到所述图像中物体的多个边界线区域;其中,所述边界线区域识别模型是基于神经网络的模型;
针对每一所述边界线区域,从多条所述参考边界线中确定与该边界线区域对应的目标边界线;
根据确定的多条所述目标边界线确定所述图像中物体的边缘。
需要说明的是,上述计算机程序被处理器执行时实现的图像中物体的边缘检测方法的其他实施例,与前述方法部分提及的图像中物体的边缘检测方法的实施例相同,在此不再赘述。
综上所述,本实施例首先获得图像中灰度轮廓的线条图,将线条图中相似的线条进行合并得到多条初始合并线条,并根据多条初始合并线条确定一边界矩阵,并且继续将多条初始合并线条中相似的线条进行合并得到目标线条,同时将不能合并的初始合并线条也直接作为目标线条,然后根据边界矩阵从多条目标线条中确定多条参考边界线,同时还通过预先训练的边界线区域识别模型对图像进行处理,得到图像中物体的多个边界线区域,从而可以针对每一边界线区域,从多条参考边界线中确定与该边界线区域对应的目标边界线,进而根据确定的多条目标边界线确定图像中物体的边缘。本实施例通过根据图像获得参考边界线,结合机器学习识别边界线区域,从而共同确定图像中物体的目标边界线,实现了对图像中物体的边缘检测,能够快速定位图像中物体边缘的位置,并且提高边缘检测的准确性。
所述可读存储介质可以是可以保持和存储由指令执行设备使用的指令的有形设备,例如可以是但不限于电存储设备、磁存储设备、光存储设备、电磁存储设备、半导体存储设备或者上述的任意合适的组合。可读存储介质的更具体的例子(非穷举的列表)包括:便携式计算机盘、硬盘、随机存取存储器(RAM)、只读存储器(ROM)、可擦式可编程只读存储器(EPROM或闪存)、静态随机存取存储器(SRAM)、便携式压缩盘只读存储器(CD-ROM)、数字多功能盘(DVD)、记忆棒、软盘、机械编码设备、例如其上存储有指令的打孔卡或凹槽内凸起结构、以及上述的任意合适的组合。这里所描述的计算机程序可以从可读存储介质下载到各个计算/处理设备,或者通过网络、例如因特网、局域网、广域网和/或无线网下载到外部计算机或外部存储设备。网络可以包括铜传输电缆、光纤传输、无线传输、路由器、防火墙、交换机、网关计算机和/或边缘服务器。每个计算/处理设备中的网络适配卡或者网络接口从网络接收所述计算机程序,并转发该计算机程序,以供存储在各个计算/处理设备中的可读存储介质中。用于执行本发明操作的计算机程序可以是汇编指令、 指令集架构(ISA)指令、机器指令、机器相关指令、微代码、固件指令、状态设置数据、或者以一种或多种编程语言的任意组合编写的源代码或目标代码,所述编程语言包括面向对象的编程语言—诸如Smalltalk、C++等,以及常规的过程式编程语言—诸如“C”语言或类似的编程语言。所述计算机程序可以完全地在用户计算机上执行、部分地在用户计算机上执行、作为一个独立的软件包执行、部分在用户计算机上部分在远程计算机上执行、或者完全在远程计算机或服务器上执行。在涉及远程计算机的情形中,远程计算机可以通过任意种类的网络,包括局域网(LAN)或广域网(WAN),连接到用户计算机,或者,可以连接到外部计算机(例如利用因特网服务提供商来通过因特网连接)。在一些实施方式中,通过利用计算机程序的状态信息来个性化定制电子电路,例如可编程逻辑电路、现场可编程门阵列(FPGA)或可编程逻辑阵列(PLA),该电子电路可以执行计算机可读程序指令,从而实现本发明的各个方面。
这里参照根据本发明实施方式的方法、系统和计算机程序产品的流程图和/或框图描述了本发明的各个方面。应当理解,流程图和/或框图的每个方框以及流程图和/或框图中各方框的组合,都可以由计算机程序实现。这些计算机程序可以提供给通用计算机、专用计算机或其它可编程数据处理装置的处理器,从而生产出一种机器,使得这些程序在通过计算机或其它可编程数据处理装置的处理器执行时,产生了实现流程图和/或框图中的一个或多个方框中规定的功能/动作的装置。也可以把这些计算机程序存储在可读存储介质中,这些计算机程序使得计算机、可编程数据处理装置和/或其他设备以特定方式工作,从而,存储有该计算机程序的可读存储介质则包括一个制造品,其包括实现流程图和/或框图中的一个或多个方框中规定的功能/动作的各个方面的指令。也可以把计算机程序加载到计算机、其它可编程数据处理装置、或其它设备上,使得在计算机、其它可编程数据处理装置或其它设备上执行一系列操作步骤,以产生计算机实现的过程,从而使得在计算机、其它可编程数据处理装置、或其它设备上执行的计算机程序实现流程图和/或框图中的一个或多个方框中规定的功能/动作。
需要说明的是,本说明书中的各个实施例均采用相关的方式描述,各个 实施例之间相同相似的部分互相参见即可,每个实施例重点说明的都是与其他实施例的不同之处。尤其,对于装置、电子设备、计算机可读存储介质实施例而言,由于其基本相似于方法实施例,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。
在本文中,诸如第一和第二等之类的关系术语仅仅用来将一个实体或者操作与另一个实体或操作区分开来,而不一定要求或者暗示这些实体或操作之间存在任何这种实际的关系或者顺序。而且,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、物品或者设备中还存在另外的相同要素。在本文中使用的术语仅用于描述特定实施方式的目的,并非旨在限制本发明。如本文中所使用的,单数形式“一(a)”、“一(an)”和“一(the)”旨在也包括复数形式,除非在上下文中清楚地另外指出。如本文中所使用的,术语“和/或”包括一个或多个相关的所列项目的任意的和所有的组合。当例如“中的至少一个”的表述处于一列元件之后时修饰整列元件,而不是修饰该列中的个别元件。如本文中所使用的,术语“基本上”、“约”以及类似术语被用作近似术语,而不是程度术语,并且意在表示测量值或计算值中的固有偏差,所述偏差将被那些本领域普通技术人员识别。此外,在描述本发明的实施方式时,“可以”的使用指的是“本发明的一个或多个实施方式”。如本文中所使用的,术语“使用”、“正使用”和“使用了”可以被认为分别与术语“利用”、“正利用”和“利用了”是同义的。同样,术语“示例性”意在指出实例或示例。
上述描述仅是对本发明较佳实施例的描述,并非对本发明范围的任何限定,本发明领域的普通技术人员根据上述揭示内容做的任何变更、修饰,均属于权利要求书的保护范围。

Claims (20)

  1. 一种图像中物体的边缘检测方法,其特征在于,所述方法包括:
    对图像进行处理,获得所述图像中灰度轮廓的线条图;
    将所述线条图中相似的多条线条进行合并,得到多条初始合并线条,并根据多条所述初始合并线条确定一边界矩阵;
    根据多条所述初始合并线条得到多条目标线条,包括:将多条所述初始合并线条中相似的多条所述初始合并线条进行合并得到至少一条所述目标线条,并且将未合并的一条或多条所述初始合并线条作为一条或多条所述目标线条;
    根据所述边界矩阵,从多条所述目标线条中确定多条参考边界线;
    通过预先训练的边界线区域识别模型对所述图像进行处理,得到所述图像中物体的多个边界线区域;其中,所述边界线区域识别模型是基于神经网络的模型;
    针对每一所述边界线区域,从多条所述参考边界线中确定与该边界线区域对应的一条目标边界线;
    根据多个所述边界线区域确定的多条所述目标边界线确定所述图像中物体的边缘。
  2. 如权利要求1所述的图像中物体的边缘检测方法,其特征在于,所述对图像进行处理,获得所述图像中灰度轮廓的线条图,包括:
    通过基于OpenCV的边缘检测算法对图像进行处理,获得所述图像中灰度轮廓的线条图。
  3. 如权利要求1所述的图像中物体的边缘检测方法,其特征在于,将所述线条图中相似的多条线条进行合并,得到多条初始合并线条,包括:
    获取所述线条图中的多个长线条;其中,所述长线条为长度超过第一预设阈值的线条;
    从多个所述长线条中获取多组第一类线条;其中,每组所述第一类线条包括至少两个依次相邻的长线条,且任意相邻的两个所述长线条之间的夹角 均小于第二预设阈值;
    针对每一组第一类线条,将该组第一类线条中的各个所述长线条依次进行合并得到一条所述初始合并线条。
  4. 如权利要求1所述的图像中物体的边缘检测方法,其特征在于,将多条所述初始合并线条中相似的所述初始合并线条进行合并得到目标线条,包括:
    从多条所述初始合并线条中获取多组第二类线条;其中,每组所述第二类线条包括至少两个依次相邻的所述初始合并线条,且任意相邻的两个所述初始合并线条之间的夹角均小于第三预设阈值;
    针对每一组第二类线条,将该组第二类线条中的各个初始合并线条依次进行合并得到一条目标线条。
  5. 如权利要求3或4所述的图像中物体的边缘检测方法,其特征在于,两条线条的夹角θ通过以下公式计算:
    Figure PCTCN2019103850-appb-100001
    其中,
    Figure PCTCN2019103850-appb-100002
    分别表示两条线条的向量。
  6. 如权利要求3所述的图像中物体的边缘检测方法,其特征在于,所述边界矩阵按照以下方式确定:对多条所述初始合并线条以及所述长线条中未合并的长线条进行重新绘制,将重新绘制的所有线条中的像素点的位置信息对应到整个图像矩阵中,将图像矩阵中这些线条的像素点所在位置的值设置为第一数值、这些线条以外的像素点所在位置的值设置为第二数值,从而形成边界矩阵。
  7. 如权利要求1所述的图像中物体的边缘检测方法,其特征在于,根据所述边界矩阵,从多条所述目标线条中确定多条参考边界线,包括:
    针对每一条所述目标线条,将该目标线条进行延长,根据延长后的该目标线条确定一线条矩阵,然后将该线条矩阵与所述边界矩阵进行对比,计算延长后的该目标线条上属于所述边界矩阵的像素点的个数,作为该目标线条的成绩;其中,所述线条矩阵与所述边界矩阵的大小相同;
    根据各个目标线条的成绩,从多条所述目标线条中确定多条参考边界线。
  8. 如权利要求1所述的图像中物体的边缘检测方法,其特征在于,针对 每一所述边界线区域,从多条所述参考边界线中确定与该边界线区域相对应的一条目标边界线,包括:
    计算每一条所述参考边界线的斜率;
    针对每一个所述边界线区域,将该边界线区域转换为多条直线,并计算所述多条直线的平均斜率,再判断多条所述参考边界线中是否存在斜率与所述平均斜率相匹配的参考边界线,如果存在,将该参考边界线确定为与该边界线区域相对应的目标边界线。
  9. 如权利要求8所述的图像中物体的边缘检测方法,其特征在于,所述方法还包括:
    针对每一个所述边界线区域,如果判断出多条所述参考边界线中不存在斜率与所述平均斜率相匹配的参考边界线,则针对该边界线区域转换得到的每一条直线,将该直线形成的线条矩阵与所述边界矩阵进行对比,计算该直线上属于所述边界矩阵的像素点的个数,作为该直线的成绩;将成绩最好的直线确定为与该边界线区域相对应的目标边界线;其中,所述线条矩阵与所述边界矩阵的大小相同。
  10. 如权利要求8所述的图像中物体的边缘检测方法,其特征在于,将该边界线区域转换为多条直线,包括:
    利用霍夫变换将该边界线区域转换为多条直线。
  11. 如权利要求7或9所述的图像中物体的边缘检测方法,其特征在于,所述线条矩阵按照以下方式确定:对延长后的目标线条或直线进行重新绘制,将重新绘制的线条中的像素点的位置信息对应到整个图像矩阵中,将图像矩阵中线条的像素点所在位置的值设置为第一数值、线条以外的像素点所在位置的值设置为第二数值,从而形成线条矩阵。
  12. 如权利要求1所述的图像中物体的边缘检测方法,其特征在于,所述边界线区域识别模型按照以下方式训练得到:
    对图像样本集中的每个图像样本进行标注处理,以标注出每个图像样本中物体的边界线区域、内部区域和外部区域;
    通过经过标注处理的图像样本集,对神经网络进行训练,以得到所述边 界线区域识别模型。
  13. 如权利要求1所述的图像中物体的边缘检测方法,其特征在于,所述方法还包括:
    获得多条所述目标边界线的多个交点,对多个所述交点和多条所述目标边界线确定的区域进行投影变换,得到所述图像中的所述物体的正视图。
  14. 一种图像中物体的边缘检测装置,其特征在于,所述装置包括:
    获得模块,用于对图像进行处理,获得所述图像中灰度轮廓的线条图;
    第一合并模块,用于将所述线条图中相似的多条线条进行合并,得到多条初始合并线条,并根据多条所述初始合并线条确定一边界矩阵;
    第二合并模块,用于根据多条所述初始合并线条得到多条目标线条,包括:将多条所述初始合并线条中相似的多条所述初始合并线条进行合并得到至少一条所述目标线条,并且将未合并的一条或多条所述初始合并线条也作为一条或多条的所述目标线条;
    第一确定模块,用于根据所述边界矩阵,从多条所述目标线条中确定多条参考边界线;
    识别模块,用于通过预先训练的边界线区域识别模型对所述图像进行处理,得到所述图像中物体的多个边界线区域;其中,所述边界线区域识别模型是基于神经网络的模型;
    第二确定模块,用于针对每一所述边界线区域,从多条所述参考边界线中确定与该边界线区域对应的一条目标边界线;
    第三确定模块,用于根据多个所述边界线区域确定的多条所述目标边界线确定所述图像中物体的边缘。
  15. 如权利要求14所述的图像中物体的边缘检测装置,其特征在于,所述第一合并模块将所述线条图中相似的多条线条进行合并,得到多条初始合并线条,包括:
    获取所述线条图中的多个长线条;其中,所述长线条为长度超过第一预设阈值的线条;
    从多个所述长线条中获取多组第一类线条;其中,每组所述第一类线条 包括至少两个依次相邻的长线条,且任意相邻的两个所述长线条之间的夹角均小于预设阈值;
    针对每一组第一类线条,将该组第一类线条中的各个所述长线条依次进行合并得到一条所述初始合并线条。
  16. 如权利要求14所述的图像中物体的边缘检测装置,其特征在于,所述第一确定模块,包括:
    第一计算子模块,用于针对每一条所述目标线条,将该目标线条进行延长,根据延长后的该目标线条确定一线条矩阵,然后将该线条矩阵与所述边界矩阵进行对比,计算延长后的该目标线条上属于所述边界矩阵的像素点的个数,作为该目标线条的成绩;其中,所述线条矩阵与所述边界矩阵的大小相同;
    第一确定子模块,用于根据各个目标线条的成绩,从多条所述目标线条中确定多条参考边界线。
  17. 如权利要求14所述的图像中物体的边缘检测装置,其特征在于,所述第二确定模块,包括:
    第二计算子模块,用于计算每一条所述参考边界线的斜率;
    第二确定子模块,用于针对每一个所述边界线区域,将该边界线区域转换为多条直线,并计算所述多条直线的平均斜率,再判断多条所述参考边界线中是否存在斜率与所述平均斜率相匹配的参考边界线,如果存在,将该参考边界线确定为与该边界线区域相对应的目标边界线。
  18. 如权利要求17所述的图像中物体的边缘检测装置,其特征在于,所述第二确定子模块,还用于:
    针对每一个所述边界线区域,如果判断出多条所述参考边界线中不存在斜率与所述平均斜率相匹配的参考边界线,则针对该边界线区域转换得到的每一条直线,将该直线形成的线条矩阵与所述边界矩阵进行对比,计算该直线上属于所述边界矩阵的像素点的个数,作为该直线的成绩;将成绩最好的直线确定为与该边界线区域相对应的目标边界线;其中,所述线条矩阵与所述边界矩阵的大小相同。
  19. 一种电子设备,其特征在于,包括处理器、通信接口、存储器和通信总线,其中,所述处理器、所述通信接口和所述存储器通过所述通信总线完成相互间的通信;
    所述存储器,用于存放计算机程序;
    所述处理器,用于执行所述存储器上所存放的程序时,实现权利要求1-13中任一所述的方法步骤。
  20. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质内存储有计算机程序,所述计算机程序被处理器执行时实现权利要求1-13中任一项所述的方法步骤。
PCT/CN2019/103850 2019-05-16 2019-08-30 边缘检测方法、装置、电子设备和计算机可读存储介质 WO2020228187A1 (zh)

Priority Applications (1)

Application Number Priority Date Filing Date Title
US16/981,293 US11636604B2 (en) 2019-05-16 2019-08-30 Edge detection method and device, electronic equipment, and computer-readable storage medium

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910407150.7 2019-05-16
CN201910407150.7A CN111951290B (zh) 2019-05-16 2019-05-16 一种图像中物体的边缘检测方法及装置

Publications (1)

Publication Number Publication Date
WO2020228187A1 true WO2020228187A1 (zh) 2020-11-19

Family

ID=73290268

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2019/103850 WO2020228187A1 (zh) 2019-05-16 2019-08-30 边缘检测方法、装置、电子设备和计算机可读存储介质

Country Status (3)

Country Link
US (1) US11636604B2 (zh)
CN (1) CN111951290B (zh)
WO (1) WO2020228187A1 (zh)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115170570A (zh) * 2022-09-07 2022-10-11 南通睿谷纺织科技有限公司 基于灰度游程矩阵的织物起毛起球检测方法
CN117152421A (zh) * 2023-10-31 2023-12-01 南方电网数字电网研究院有限公司 输电线路异物检测方法、装置、计算机设备和存储介质

Families Citing this family (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111598074B (zh) * 2020-05-21 2023-07-07 杭州睿琪软件有限公司 边缘检测方法和装置、电子设备和存储介质
CN112418204A (zh) * 2020-11-18 2021-02-26 杭州未名信科科技有限公司 基于纸质文档的文本识别方法、系统及计算机介质
CN112542007A (zh) * 2020-11-30 2021-03-23 福州外语外贸学院 一种金融取款间危险目标检测方法及系统
CN112634235A (zh) * 2020-12-24 2021-04-09 深圳艾灵网络有限公司 产品图像的边界检测方法和电子设备
CN113034527B (zh) * 2021-03-30 2022-05-03 长江存储科技有限责任公司 边界检测方法及相关产品
CN113380394B (zh) * 2021-06-18 2022-04-12 上海睿刀医疗科技有限公司 确定电极针消融边界的方法、装置、电子设备及存储介质
US11798158B2 (en) * 2021-11-16 2023-10-24 GM Global Technology Operations LLC Systems and methods for monitoring chain health
CN116385446B (zh) * 2023-06-06 2023-08-15 山东德圣源新材料有限公司 一种用于勃姆石生产的晶体杂质检测方法
CN116452586B (zh) * 2023-06-15 2023-09-26 山东飞宏工程机械有限公司 一种隧道小导管余料自动对焊质量检测系统

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107622499A (zh) * 2017-08-24 2018-01-23 中国东方电气集团有限公司 一种基于目标二维轮廓模型的识别与空间定位方法
US20180253852A1 (en) * 2015-11-25 2018-09-06 Beijing Qihoo Techology Company Limited Method and device for locating image edge in natural background
CN108647634A (zh) * 2018-05-09 2018-10-12 深圳壹账通智能科技有限公司 图像边框查找方法、装置、计算机设备及存储介质
CN109523603A (zh) * 2018-10-24 2019-03-26 广东智媒云图科技股份有限公司 一种基于皴法风格的绘画方法、装置、终端设备及存储介质

Family Cites Families (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2009199308A (ja) * 2008-02-21 2009-09-03 Dainippon Screen Mfg Co Ltd 線画処理装置、プログラム及び線画処理方法
CN102930540B (zh) * 2012-10-26 2015-06-10 中国地质大学(武汉) 城市建筑物轮廓检测的方法及系统
JP6555211B2 (ja) * 2016-08-15 2019-08-07 Jfeスチール株式会社 二次元画像のエッジ抽出方法
US10127670B2 (en) * 2016-09-27 2018-11-13 Xactware Solutions, Inc. Computer vision systems and methods for detecting and modeling features of structures in images
CN108765456B (zh) * 2018-04-02 2020-10-30 上海鹰觉科技有限公司 基于直线边缘特征的目标跟踪方法、系统
CN108564557B (zh) * 2018-05-31 2020-08-25 京东方科技集团股份有限公司 图像校正方法及装置
CN109165653B (zh) * 2018-08-15 2022-03-15 西安电子科技大学 一种基于语义线段近邻连接的sar图像聚集区域的提取方法
CN109325930B (zh) * 2018-09-12 2021-09-28 苏州优纳科技有限公司 边界缺陷的检测方法、装置及检测设备
US10922860B2 (en) * 2019-05-13 2021-02-16 Adobe Inc. Line drawing generation
CN111598074B (zh) * 2020-05-21 2023-07-07 杭州睿琪软件有限公司 边缘检测方法和装置、电子设备和存储介质

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20180253852A1 (en) * 2015-11-25 2018-09-06 Beijing Qihoo Techology Company Limited Method and device for locating image edge in natural background
CN107622499A (zh) * 2017-08-24 2018-01-23 中国东方电气集团有限公司 一种基于目标二维轮廓模型的识别与空间定位方法
CN108647634A (zh) * 2018-05-09 2018-10-12 深圳壹账通智能科技有限公司 图像边框查找方法、装置、计算机设备及存储介质
CN109523603A (zh) * 2018-10-24 2019-03-26 广东智媒云图科技股份有限公司 一种基于皴法风格的绘画方法、装置、终端设备及存储介质

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115170570A (zh) * 2022-09-07 2022-10-11 南通睿谷纺织科技有限公司 基于灰度游程矩阵的织物起毛起球检测方法
CN117152421A (zh) * 2023-10-31 2023-12-01 南方电网数字电网研究院有限公司 输电线路异物检测方法、装置、计算机设备和存储介质
CN117152421B (zh) * 2023-10-31 2024-03-22 南方电网数字电网研究院股份有限公司 输电线路异物检测方法、装置、计算机设备和存储介质

Also Published As

Publication number Publication date
CN111951290B (zh) 2023-11-03
CN111951290A (zh) 2020-11-17
US11636604B2 (en) 2023-04-25
US20220215557A1 (en) 2022-07-07

Similar Documents

Publication Publication Date Title
WO2020228187A1 (zh) 边缘检测方法、装置、电子设备和计算机可读存储介质
WO2022148192A1 (zh) 图像处理方法、图像处理装置以及非瞬时性存储介质
WO2021233266A1 (zh) 边缘检测方法和装置、电子设备和存储介质
WO2021164228A1 (zh) 一种图像数据的增广策略选取方法及系统
WO2019128646A1 (zh) 人脸检测方法、卷积神经网络参数的训练方法、装置及介质
CN110427932B (zh) 一种识别图像中多个票据区域的方法及装置
WO2018010657A1 (zh) 结构化文本检测方法和系统、计算设备
WO2022057607A1 (zh) 识别对象边缘的方法、系统及计算机可读存储介质
WO2020238054A1 (zh) Pdf文档中图表的定位方法、装置及计算机设备
WO2022033095A1 (zh) 一种文本区域的定位方法及装置
WO2016124103A1 (zh) 一种图片检测方法及设备
KR20190098858A (ko) 딥러닝 기반의 포즈 변화에 강인한 얼굴 인식 방법 및 장치
JP7198350B2 (ja) 文字検出装置、文字検出方法及び文字検出システム
US20180253852A1 (en) Method and device for locating image edge in natural background
EP2954457A1 (en) System and method for identifying similarities in different images
Santosh et al. Arrow detection in biomedical images using sequential classifier
CN109479082A (zh) 图象处理方法及装置
CN110852311A (zh) 一种三维人手关键点定位方法及装置
WO2023024766A1 (zh) 物体尺寸识别方法、可读存储介质及物体尺寸识别系统
WO2021196013A1 (zh) 单词识别方法、设备及存储介质
CN110598703B (zh) 一种基于深度神经网络的ocr识别方法及装置
Chen et al. Method on water level ruler reading recognition based on image processing
JP2019220014A (ja) 画像解析装置、画像解析方法及びプログラム
CN109978829B (zh) 一种待检测对象的检测方法及其系统
CN116524508A (zh) 表格类图像的矫正方法及装置、存储介质、计算机设备

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 19929021

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 19929021

Country of ref document: EP

Kind code of ref document: A1

122 Ep: pct application non-entry in european phase

Ref document number: 19929021

Country of ref document: EP

Kind code of ref document: A1

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 27.06.2022)

122 Ep: pct application non-entry in european phase

Ref document number: 19929021

Country of ref document: EP

Kind code of ref document: A1