Disclosure of Invention
The application aims to solve the technical problem of providing a book edge detection method which can rapidly and stably position the edge of a bent book in an image and is insensitive to noise existing in the image and shielding of the edge part of the book.
In order to solve the technical problems, the book edge detection method provided by the application comprises the following steps. Step S10: an image containing a book is acquired. Step S20: and extracting left and right edges of the book from the image by adopting a straight line detection method. Step S30: and extracting the upper edge and the lower edge of the book from the image by adopting a detection method based on the cyclic search trip point. The method comprises the steps of obtaining an image through a mobile phone camera; performing straight line detection on the edge map to determine the left edge and the right edge of the book; uniformly sampling a column pixel sequence in the left and right edge range, and determining a response jump point existing in the column pixel sequence; and (3) connecting the response jump points transversely, primarily screening the upper edge sequence and the lower edge sequence of the books through rules, and obtaining the accurate upper edge and the lower edge of the books through depth-first search.
Preferably, the step S10 includes acquiring an image including a book through a photographing and image capturing part of the mobile terminal, or acquiring an image including a book in a memory of the electronic device, or acquiring an image including a book through a network transmission mode. Several common ways of acquiring the original input image are given here by way of example.
Further, the step S20 includes the following steps. Step S21: and extracting an edge graph of the input image, and removing interference information of characters in the edge graph, lines in a table and lines in a picture by using an image processing method. Step S22: and (5) performing straight line detection on the picture. Step S23: and (5) screening left and right edge lines of the book from the detected straight lines. A specific implementation is given here for step S20.
Preferably, in the step S21, an edge map is obtained by using a Canny edge detection method based on a gradient method; or subtracting the image subjected to the vertical corrosion operation on the gray level image from the image subjected to the horizontal corrosion operation on the gray level image to obtain an edge image; and opening the edge graph to remove the interference information.
Preferably, in the step S22, a hough transform line detection method is adopted, and the line angle is limited between-45 ° and 45 °.
Preferably, in the step S23, a line with the greatest number of hough votes at the center point of the line on the left side of the image is selected as the left edge line of the book, and a line with the greatest number of hough votes at the center point of the line on the right side of the image is selected as the right edge line of the book.
Further, the step S30 includes the following steps. Step S31: the multiple sets of column pixel sequences are sampled uniformly over one or more channels or edge maps of the input image, within the range between the left and right edge lines of the book. Step S32: and respectively calculating and recording the jumping points of the sequences of each group of column pixel sequences by adopting a jumping point detection method based on cyclic search. Step S33, the jump points of each group of pixel sequences are transversely connected, and the upper edge and the lower edge of the book are screened out. A specific implementation is given here for step S30.
Preferably, in the step S31, a plurality of sets of column pixel sequences are uniformly sampled on a saturation channel of the input image.
Further, the step S32 includes the following steps. Step S321: the total variance of a certain set of column pixel sequences X is calculated. Step S322: circularly traversing the sequence X to find out the point X with the greatest contribution to the total inter-class variance of the sequence X cut As the first trip point of sequence X. Step S323: cutting the sequence X at the current jump point to obtain two subsequences, denoted S 0 And S is 1 The method comprises the steps of carrying out a first treatment on the surface of the Sub-sequence S 0 Traversing to obtain the point X with the greatest contribution to the total inter-class variance of the sequence X 0 And is recorded in X 0 The contribution of the cut to the total inter-class variance of sequence X is d0, the value pair (X 0 D 0) adding the same to the candidate hopping point set; the same is done for sub-sequence S1. Step S324: traversing the candidate trip point set to find the value pair with the largest contribution to the total inter-class variance of the sequence X, and recording as (X) cut2 D) X produced in this step is subjected to cut2 As a new trip point for sequence X. Step S325: judging whether the cut-off condition is met; if so, proceeding to step S33; if not, jumping to step S323; the cut-off condition includes that the number of hopping points is greater than a preset threshold one and the contribution of the current hopping point to the total inter-class variance of the sequence X is less than a preset threshold two. A specific implementation is given here for step S32.
Further, the step S33 includes the following steps. Step S331: calculating a vertical gradient map on a saturation channel of an input image, and marking as G saturation The method comprises the steps of carrying out a first treatment on the surface of the Calculating on the brightness channel of the input image to obtain a vertical gradient map, which is marked as G brightness . Step S332: searching the jump points of each group of pixel sequences backwards along the approximately horizontal direction according to the following rule to obtain multiple sets of pixel sequencesA set of hopping point sequences { H }; the j-th trip point on the i-th group of column pixel sequences is denoted as P ij The method comprises the steps of carrying out a first treatment on the surface of the Trip point P ij Is marked as y_P by the y-axis seat of (2) ij The method comprises the steps of carrying out a first treatment on the surface of the Assume that the current trip point is P ij The current trip point P ij In the pixel sequence of the immediately adjacent (i+1) th group of columns, the y-axis coordinate is in [ y_P ] ij –η,y_P ij +η]Within the range, and G saturation +G brightness Maximum trip point P i+1,x Connecting; if there is no eligible trip point P in the (i+1) -th group of column pixel sequences i+1,x Searching jump points meeting the conditions in the (i+2) th group of column pixel sequences; repeating the step until all column pixel sequences are exhausted, and transversely connecting all the jumping points meeting the conditions and adding the jumping points into a jumping point sequence set { H }; η is a search range threshold; then repeating the process on the j+1st jumping point on the ith group of column pixel sequences to obtain another jumping point sequence set { H }; each set of hopping point sequences { H } represents a line that is connected approximately horizontally. Step S333: screening out preliminary upper and lower edge sequences from a plurality of hopping point sequence sets { H }; the jump point sequence set { H } with the longest length and positioned at the upper half part of the image is taken as the upper edge sequence H of the image top The jump point sequence set { H } with the longest length positioned at the lower half part of the image is taken as the lower edge sequence H of the image bottom . Step S334: and fine tuning is carried out on the upper edge sequence and the lower edge sequence respectively to obtain the final upper edge and the final lower edge. A specific implementation is given here for step S33.
Preferably, in the step S334, the upper edge sequence H top Is connected with adjacent jumping points and takes the connection as a starting point and an end point to do depth first search so as to maximize G of a sequence saturation +G brightness Obtaining a final upper edge sequence by the value; for the lower edge sequence H bottom And performing the same operation to obtain a final lower edge sequence.
The application provides a book edge detection device which comprises an image acquisition unit, a left edge detection unit, a right edge detection unit and an upper edge detection unit and a lower edge detection unit. The acquisition unit is used for acquiring images containing books. The left and right edge detection unit is used for extracting left and right edges of the book from the image by adopting a straight line detection method. The upper and lower edge detection unit is used for extracting upper and lower edges of books in the images based on a trip point detection method of cyclic search. The device detects the left edge, the right edge, the upper edge and the lower edge of the book by adopting different technical means, and has the characteristics of rapidness and stability.
The technical effects achieved by the application include the following aspects. The processing is fast, and the edges of the books can be detected and extracted in real time at mobile terminals such as mobile phones. And the other is stable treatment. Due to the adoption of the jump point detection method based on the cyclic search, the book edge can still be accurately detected under the conditions of difficult scenes such as poor image quality (blurring or noise existence) and partial shielding of the book edge. Thirdly, the edge of the book can be detected.
Detailed Description
Referring to fig. 1, the method for detecting the edge of the book provided by the application comprises the following steps.
Step S10: an image containing a book is acquired. For example, an image including a book is acquired by a photographing and imaging unit of a mobile terminal such as a mobile phone, or an image including a book is acquired in a memory of an electronic device, or an image including a book is acquired by a network transmission system.
Step S20: and extracting left and right edges of the book from the image by adopting a straight line detection method.
Step S30: and extracting the upper edge and the lower edge of the book from the image by adopting a trip point detection method based on cyclic search.
The left edge and the right edge of the book are not easy to bend and deform, so that the straight line detection method is more suitable. The upper edge and the lower edge of the book are easy to bend and deform, for example, the upper edge and the lower edge of the book after being unfolded are in an arc shape, so that a trip point detection method based on cyclic search is more suitable.
Referring to fig. 2, the step S20 of extracting the left and right edges of the book specifically includes the following steps.
Step S21: and extracting an edge map (edge map) of the input image, and removing interference information such as characters in the edge map, lines in a table, lines in a picture and the like by using an image processing method.
For example, an edge map is obtained by a Canny edge detection method based on a gradient method, which is commonly used in the field of image processing. For example, by adopting the image morphology processing method, the edge image can be obtained more quickly, namely, the image after vertical etching operation (Erode) is performed on the gray image minus the image after horizontal etching operation is performed on the gray image. An image morphological open operation (open) may be performed on the edge map to remove noise interference of text, lines in a table, lines in a picture, and the like.
The present application is not dependent on a specific edge map extraction method or a specific noise removal method. The foregoing is merely a preferred example.
Step S22: and (5) performing straight line detection on the picture. Straight line detection is a common type of digital image processing method, for example, a method of straight line detection using Hough Transform (Hough Transform), and limits the straight line angle to between-45 ° and 45 °.
Step S23: and (5) screening left and right edge lines of the book from the detected straight lines. For example, a line with the greatest number of hough votes at the center point of the line on the left side of the image is selected as the left edge line of the book, and a line with the greatest number of hough votes at the center point of the line on the right side of the image is selected as the right edge line of the book.
Referring to fig. 3, the step S30 of extracting the upper and lower edges of the book specifically includes the following steps.
Step S31: the multiple sets of column pixel sequences are sampled uniformly over one or more channels or edge maps of the input image, within the range between the left and right edge lines of the book. For example, 15 sets of column pixel sequences are sampled uniformly along the x-axis using the saturation channel of the input image.
Step S32: and respectively calculating and recording the jumping points of the sequences of each group of column pixel sequences by adopting a jumping point detection method based on cyclic search. The hopping point (also called a variable point) of a sequence is a point at which the sequence strength changes significantly. The book responds differently to the background area on the saturation channel, so the column pixel sequence will change significantly at the edge of the book, forming a trip point. Due to the different book shooting environments, there will be an unfixed number of jumping points in a group of column pixel sequences.
Step S33, the jump points of each group of pixel sequences are transversely connected, and the upper edge and the lower edge of the book are screened out.
In the step S32, the contents such as text and picture in the book, other objects in the background area, illumination, shadow and the like may interfere with the positioning of the jump points. Compared with the violent search method, the method is faster, and can meet the requirement of the edge detection task on the precision.
First a mathematical definition of variance, inter-class variance and inter-class variance variation over a set of column pixel sequences X is given. The sequence is marked as X, the length of the sequence is N, and the ith element in the sequence is marked as X i 。
The variance of sequence X is defined asAnd is denoted as equation one. Wherein->The average value of the sequence X is shown.
According to the first formula, the definition of the inter-class variance can be obtained after simple deduction. If the sequence X is divided into n subsequences, the jth subsequence is denoted as S j Having a length of n j Average value isThen the inter-class variance of sequence X is defined asAnd is noted as equation two.
According to the formula II, the definition of the variance variation between classes after the sequence is further segmented is further deduced. If subsequence S j Further divided into two subsequences S j0 And S is j1 This partition contributes to the inter-class variance of sequence X asAnd is denoted as formula three. Wherein n is j0 Representing the subsequence S j0 Length n of (2) j1 Representing the subsequence S j1 Is a length of (c).
According to the above definition, the step S32 may employ a trip point detection method based on a loop search as shown in fig. 4, which specifically includes the following steps.
Step S321: the total variance of a certain set of column pixel sequences X, denoted as σ, is calculated from equation one. Initializing a candidate trip point set CandidateCutList as an empty set. Initializing an output trip point set CutList as an empty set.
Step S322: circularly traversing the sequence X, finding out the point with the maximum contribution to the total inter-class variance of the sequence X, and marking the point as X cut X is taken as cut And adding the output jumping point set CutList. Each pair of pointsThe contribution of the total inter-class variance of sequence X can be calculated from equation three. This step only results in the first trip point X of the sequence X cut 。
Step S323: the sequence X is segmented at the current trip point to obtain two subsequences, denoted S 0 And S is 1 . Sub-sequence S 0 Traversing to obtain the point X with the greatest contribution to the total inter-class variance of the sequence X 0 And is recorded in X 0 The contribution of the cut to the total inter-class variance of sequence X is d0, the value pair (X 0 D0) is added to the candidate trip point set CandidateCutList. The same is done for sub-sequence S1.
Step S324: traversing the candidate hopping point set Candida ecartList, finding out the value pair with the largest contribution to the total inter-class variance of the sequence X, and recording as (X) cut2 D) X produced in this step is subjected to cut2 And adding the output jumping point set CutList.
Each time step S323 to step S324 are performed, one trip point is added to the output trip point set CutList.
Step S325: whether the cut-off condition is satisfied is determined. If so, step S33 is entered. If not, go to step S323. The cut-off condition includes that the number of the hopping points is stored to be larger than a preset threshold value I, and the contribution of the current hopping point to the total inter-class variance of the sequence X is smaller than a preset threshold value II.
Referring to fig. 5, a schematic diagram of the result of searching for a trip point for a column of pixel sequences using the method of fig. 4 is shown. The abscissa in fig. 5 is the pixel sequence number in the column pixel sequence, e.g., increasing from top to bottom; the ordinate is the saturation value. In the figure, each scattered point is a saturation value corresponding to each pixel in the column of pixel sequences, and the positions of the jump points detected through cyclic searching are marked on vertical lines. Fig. 5 exemplarily shows that 5 trip points are found in a set of column pixel sequences.
Referring to fig. 6, the step S33 further includes the following steps.
Step S331: calculating a vertical gradient map on a saturation channel of an input image, and marking as G saturation . In the brightness channel of the input imageCalculating to obtain a vertical gradient graph, which is marked as G brightness 。
Step S332: the hopping points of each set of column pixel sequences are searched back in a generally horizontal direction according to the following rules to obtain a plurality of hopping point sequence sets { H }. The j-th trip point on the i-th group of column pixel sequences is denoted as P ij . Trip point P ij Is marked as y_P by the y-axis seat of (2) ij . Assume that the current trip point is P ij The current trip point P ij In the pixel sequence of the immediately adjacent (i+1) th group of columns, the y-axis coordinate is in [ y_P ] ij –η,y_P ij +η]Within the range, and G saturation +G brightness Maximum trip point P i+1,x And (5) connection. If there is no eligible trip point P in the (i+1) -th group of column pixel sequences i+1,x Then the eligible trip points in the i+2-th set of column pixel sequences are searched. This is repeated until all column pixel sequences are exhausted, all the hops meeting the above conditions are laterally connected and added to one set of hopping sequences { H }. η is the search range threshold. And then repeating the process on the j+1st hopping point on the ith group of column pixel sequences to obtain another hopping point sequence set { H }. This step thus results in a plurality of sets of hopping sequences { H } each representing a line of generally horizontal connections.
Step S333: and screening out preliminary upper and lower edge sequences from the plurality of hopping point sequence sets { H }. The jump point sequence set { H } with the longest length and positioned at the upper half part of the image is taken as the upper edge sequence H of the image top The jump point sequence set { H } with the longest length positioned at the lower half part of the image is taken as the lower edge sequence H of the image bottom 。
Step S334: and fine tuning is carried out on the upper edge sequence and the lower edge sequence respectively to obtain the final upper edge and the final lower edge. Upper edge sequence H top Is used as a starting point and an end point to do depth-first search (depth first search) to maximize G of the sequence saturation +G brightness And (5) obtaining a final upper edge sequence. For the lower edge sequence H bottom And performing the same operation to obtain a final lower edge sequence.
For better understanding of the present application, fig. 7 to 13 sequentially illustrate output images of each step of the book edge detection method provided by the present application. Fig. 7 shows step S10 of acquiring an original input image containing a book. Fig. 8 shows the first half of step S21, extracting an edge map of the input image. Fig. 9 shows the second half of step S21, where the text in the edge map, the lines in the table, the lines in the picture, and other interference information are removed. Fig. 10 shows that step S22 and step S23 screen out the left and right edge lines of the book by the straight line detection method. Fig. 11 shows steps S31 to S32, in which the hopping points of the sequences are calculated and recorded for each group of column pixel sequences, respectively, the hopping points being indicated by white dots. Fig. 12 shows step S33, where the hopping points that connect the pixel sequences of each column laterally screen the upper and lower edges of the book. Fig. 13 shows the edges of a book detected according to the application, indicated by a black dashed box.
Referring to fig. 14, the book edge detecting apparatus provided by the present application includes an image acquiring unit 10, a left and right edge detecting unit 20, and an upper and lower edge detecting unit 30, corresponding to the method shown in fig. 1. The acquiring unit 10 is used for acquiring an image including a book, for example, a photographic component of a mobile terminal such as a mobile phone, a memory of an electronic device, or a network communication component. The left and right edge detection unit 20 is used to extract left and right edges of the book in the image using a straight line detection method. The upper and lower edge detection unit 30 is used for extracting upper and lower edges of the book from the image based on a trip point detection method of the cyclic search.
The above are only preferred embodiments of the present application, and are not intended to limit the present application. Various modifications and variations of the present application will be apparent to those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the protection scope of the present application.