Log plate hole defect detection and positioning method based on ellipse fitting
Technical Field
The invention relates to the technical field of wood processing, in particular to a log board hole defect detection and positioning method based on ellipse fitting.
Background
The shortage of forest resources in China, and the improvement of the timber outturn rate and the production efficiency are the key points in the fields of timber processing and automation. The quality defects of knots, cracks, decay and the like of the wood can cause the solid wood board to have porosity and layering, and the use value, the economic value and the like of the log board can be directly influenced. Traditional wood working enterprises mostly utilize the manual work to detect and fix a position, and the manual work detects with the inefficiency of location, and can waste human resources. The wood surface detection means that surface defect data of the raw wood plate, such as the number, shape, position, size and the like of surface defect holes, are acquired in a nondestructive mode, data information is transmitted to a numerical control machine tool and the like, and a rapid filling scheme is realized. The solid wood board is automatically detected, quickly positioned and optimally filled with holes by adopting an image recognition technology and a graphics technology, so that the board can be utilized to the maximum extent, and the automation level of optimal processing of the log board can be greatly improved.
Disclosure of Invention
The invention provides a log board hole defect detecting and positioning method based on ellipse fitting, aiming at solving the technical defects of low efficiency and waste of human resources in the prior art that the log board hole is detected and positioned manually.
In order to realize the purpose, the technical scheme is as follows:
a log board hole defect detection and positioning method based on ellipse fitting comprises the following steps:
s1, photographing a log plate vertically downwards above a log plate conveying conveyor belt by using photographing equipment to obtain an image of the log plate;
s2, performing color difference mean square value operation on each pixel point in the image of the log plate, performing binarization processing on the image of the log plate according to a color difference mean square value, setting the pixel point with the color difference mean square value larger than a certain set value as 1, and setting the pixel point with the color difference mean square value smaller than the certain set value as 0; thereby separating the wells and the background;
s3, hole edge points are calibrated in the universe by utilizing a binary connected region marking method for the binary image obtained in the step S2, and calibration and successive numbering of each hole edge point are completed;
s4, respectively carrying out ellipse fitting on each hole edge point obtained in the step S3 to enable the fitted ellipse to be minimized and completely cover the hole;
and S5, carrying out pixel measurement on the fixing strips which are used for compacting the plate and are drawn with the fixed marking lines at the two ends of the original wood plate in the step S1, thereby realizing pixel-level positioning in the whole image, accurately positioning the central point of the ellipse by combining fitting ellipse information, and sending the central point of the ellipse to numerical control machine equipment.
Preferably, the specific process of performing the color difference mean square value operation in step S2 is as follows:
1) firstly, each pixel point P is obtained
x,yAverage value of RBG tristimulus values of (R, G, B)
2) Calculate the point and the average value of three colors
Mean square value of θ:
preferably, the specific process of numbering hole edge points in step S3 is as follows:
for a binary image with a background of 0 and a hole of 1, carrying out progressive image scanning from top to bottom, forming a sequence of continuous black pixels in each line into a group, and recording the starting position, the ending position and the line number of the black pixels; when scanning the next row, searching a group of continuous black pixels, and if the group has a superposition area with the group of the previous row, assigning the group mark of the previous row to the group mark of the previous row; if it has overlapping area with more than two groups in the previous row, assigning the minimum label of a connected group to the current group, and writing the group label of the previous row into the equivalent pair; converting each row of the equivalent pairs in the group with the same label into equivalent sequences, giving each sequence an identical label, starting from 2, and giving each equivalent sequence a label; traversing the marks of the starting group, searching the equivalent sequence, and giving a new mark to the equivalent sequence, namely completing the hole edge point search and numbering.
Preferably, the step S4 implements the specific process of precisely positioning the ellipse center point as follows:
using n edge points (x) of the marked holes1,y1),(x2,y2),…(xn,yn) Fitting an ellipse covering the minimum area of the cavity, solving a fitting ellipse method according to a least square method, wherein an ellipse curve can be expressed as:
if the center point offset is considered, another description of the ellipse not at the origin is:
finishing to obtain:
order:
the expansion can be expressed as:
Ax2+By2+Cxy=1
this equation indicates that the major and minor axes of the ellipse are no longer parallel to the coordinate axes, but the center is still at the origin, moving the center point to (x)0,y0) Obtaining:
A(x-x0)2+By(y-y0)2+C(x-x0)(y-y0)=1
the unfolding is as follows:
the general equation for the corresponding ellipse is:
x2+gxy+cy2+dx+ey+f=0
wherein
The ellipse center (x) can be obtained by determining the parameters g, c, d, e and f
0,y
0) The rotation angle theta, and the major and minor axes a and b, which are the least squares solution of the system of equations in five-membered form;
if a certain point (x)i,yj) With an error epsiloniThe least square principle is that the sum of squares of the errors of the minimization equation is used for determining each index parameter;
therefore, it is
First order partial derivatives of the respective parameters
Solving the above equation to find the respective parameters g, c, d, e, f in the least squares sense and thus the ellipse center (x)0,y0) Rotation angle ofTheta, and major and minor axes a and b.
Compared with the prior art, the invention has the beneficial effects that:
according to the invention, an image processing technology and graphics are combined, a log plate image on a conveyor belt is obtained through shooting equipment, a black-white binary image is obtained through color difference mean square value processing, holes with defects are preliminarily separated, edge points of the holes are searched in the universe through a binary connected region marking method, the holes are numbered successively, and a minimum ellipse covering the holes is obtained through ellipse fitting according to the numbered edge points; and determining a measurement pixel value according to the calibration line of the edge of the compacted wood board, finally calculating the position of the center of the ellipse according to the pixel measurement result, realizing the accurate positioning of the hole repairing, and sending the hole repairing result to numerical control machine equipment to finish the hole repairing operation of the log board. The invention uses shooting equipment to complete the detection and positioning of the holes and the large color difference blocks of the original wood board, and is beneficial to the automatic operation of a numerical control machine.
Drawings
FIG. 1 is a schematic flow diagram of a method.
Figure 2 is a schematic view of the log sheet transfer and image acquisition.
Fig. 3 is a schematic image of the obtained raw wood plank.
Fig. 4 is a schematic diagram of a binarized image.
Detailed Description
The drawings are for illustrative purposes only and are not to be construed as limiting the patent;
the invention is further illustrated below with reference to the figures and examples.
Example 1
As shown in fig. 1, the log board hole defect detecting and positioning method based on ellipse fitting provided by the invention comprises the following steps:
s1, photographing a log plate vertically downwards above a log plate conveying conveyor belt by using photographing equipment to obtain an image of the log plate; the color of the transport conveyor belt is required to be a color with a large RGB color mean square value (such as red, green, blue, etc.), and the color is used as a background, so that the holes and the raw wood plates form large color difference contrast. The log planks are on parallel running conveyor belts and the camera is positioned directly above the conveyor belts perpendicular to the conveyor belts as shown in figure 2. An image of the raw wood plank was obtained as shown in fig. 3.
S2, performing color difference mean square value operation on each pixel point in the image of the log plate, performing binarization processing on the image of the log plate according to a color difference mean square value, setting the pixel point with the color difference mean square value larger than a certain set value as 1, and setting the pixel point with the color difference mean square value smaller than the certain set value as 0; thereby separating the pores from the background. The small mean square value of the difference is the natural color of the wood board, the binary array of the difference is set to be 0, the large mean square value of the difference is the background color corresponding to the hole, and the binary array of the difference is set to be 1. Considering that fine noise spots possibly appear in the binary image, a morphological erosion expansion algorithm is adopted for smooth denoising. An example of the binarized image is shown in fig. 4.
S3, hole edge points are calibrated in the universe by utilizing a binary connected region marking method for the binary image obtained in the step S2, and calibration and successive numbering of each hole edge point are completed;
s4, respectively carrying out ellipse fitting on each hole edge point obtained in the step S3 to enable the fitted ellipse to be minimized and completely cover the hole;
and S5, carrying out pixel measurement on the fixing strips which are used for compacting the plate and are drawn with the fixed marking lines at the two ends of the original wood plate in the step S1, thereby realizing pixel-level positioning in the whole image, accurately positioning the central point of the ellipse by combining fitting ellipse information, and sending the central point of the ellipse to numerical control machine equipment. As shown in fig. 2, the plate compacting bars are printed with fixed lines, the fixed lines are 1 cm long stripes with black and white alternated, the number of pixels of 1 cm black and white blocks and 1 cm white blocks of each row of black and white stripes is detected, the average value is obtained, the average value of the pixels in the 1 cm area is calculated, and then the length of the 1 pixel representing the distance can be calculated. And further, the data of the ellipse center and the major and minor axes can be gradually obtained for concretization.
In this embodiment, the specific process of performing the color difference mean square value operation in step S2 is as follows:
1) firstly, each pixel point P is obtained
x,y(R,Average of RBG tristimulus values of G, B)
2) Calculate the point and the average value of three colors
Mean square value of θ:
in this embodiment, the specific process of numbering the hole edge points in step S3 is as follows:
for a binary image with a background of 0 and a hole of 1, carrying out progressive image scanning from top to bottom, forming a sequence of continuous black pixels in each line into a group, and recording the starting position, the ending position and the line number of the black pixels; when scanning the next row, searching a group of continuous black pixels, and if the group has a superposition area with the group of the previous row, assigning the group mark of the previous row to the group mark of the previous row; if it has overlapping area with more than two groups in the previous row, assigning the minimum label of a connected group to the current group, and writing the group label of the previous row into the equivalent pair; converting each row of the equivalent pairs in the group with the same label into equivalent sequences, giving each sequence an identical label, starting from 2, and giving each equivalent sequence a label; traversing the marks of the starting group, searching the equivalent sequence, and giving a new mark to the equivalent sequence, namely completing the hole edge point search and numbering.
In this embodiment, the specific process of implementing accurate positioning of the elliptical center point in step S4 is as follows:
using n edge points (x) of the marked holes1,y1),(x2,y2),…(xn,yn) Fitting an ellipse covering the minimum area of the hole, according to a minimum of twoThe method of fitting an ellipse by multiplication, the ellipse curve can be expressed as:
if the center point offset is considered, another description of the ellipse not at the origin is:
finishing to obtain:
order:
the expansion can be expressed as:
Ax2+By2+Cxy=1
this equation indicates that the major and minor axes of the ellipse are no longer parallel to the coordinate axes, but the center is still at the origin, moving the center point to (x)0,y0) Obtaining:
A(x-x0)2+By(y-y0)2+C(x-x0)(y-y0)=1
the unfolding is as follows:
the general equation for the corresponding ellipse is:
x2+gxy+cy2+dx+ey+f=0
wherein
The ellipse center (x) can be obtained by determining the parameters g, c, d, e and f
0,y
0) The rotation angle theta, and the major and minor axes a and b, which are the least squares solution of the system of equations in five-membered form;
if a certain point (x)i,yj) With an error epsiloniThe least square principle is that the sum of squares of the errors of the minimization equation is used for determining each index parameter;
therefore, it is
First order partial derivatives of the respective parameters
Solving the above equation to find the respective parameters g, c, d, e, f in the least squares sense and thus the ellipse center (x)0,y0) The rotation angle theta, and the major and minor axes a and b.
It should be understood that the above-described embodiments of the present invention are merely examples for clearly illustrating the present invention, and are not intended to limit the embodiments of the present invention. Other variations and modifications will be apparent to persons skilled in the art in light of the above description. And are neither required nor exhaustive of all embodiments. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the claims of the present invention.