The specific embodiment
Theoretical foundation: image recognition.The first step of image recognition is to extract effective characteristics of image, here, we mainly introduce moment characteristics amount and contour feature amount, and the moment characteristics amount comprises Hu square, normalization rotary inertia (NMI) and affine not bending moment, and the contour feature amount comprises profile discretization parameter and singular value decomposition.These 5 characteristic quantities all have good translation, rotation and constant rate, have obtained using widely in image object identification.
1 couple of the present invention does further explanation below in conjunction with accompanying drawing.
The 1DST document analysis
Because the embroidery file of computer design is the DST form, can not directly obtain its internal feature and image information, therefore the first step of the present invention is the DST document analysis, and the DST file is resolved, and obtains its image information and internal feature.The DST file is made up of header file and style file body, and two parts are used for depositing different information, and concrete resolving is as follows.
1.1DST header file is formed
The style file header is mainly used to deposit some about the descriptive information of style, the DST file has the file header of 512 bytes, preceding 128 bytes have been stored some fileinfos with the form of text, these information comprise message identification and the value of information, the value of information is used decimal code, untapped part is replaced by space character (ASCII character value 0x20), each section by character " " (ASCII character value 0x0D) isolate, specifically each section meaning is referring to table 1.
Table 1 DST form style file header structure
1.2 style file body structure
What deposit in the style file is the data of describing the whole needle trackings actions of style, has both comprised the displacement of every needle tracking, has also comprised the control of the actions such as trimming, colour changing of embroidery machine.The style file body of DST, form be since the 513rd byte to EOF, and per 3 bytes are used for representing a pin, and are as shown in table 2.
A
7A
6A
5A
4A
3A
2A
1A
0 |
B
7B
6B
5B
4B
3B
2B
1B
0 |
C
7C
6C
5C
4C
3C
2C
1C
0 |
Per three byte representation one pins in the table 2 style file
This paper arranges level and is the X forward to the right, is the Y forward vertically downward.We make △ x, and △ y represents the displacement of needle tracking on X, Y-direction respectively, and namely current pin is with respect to the relative step number of last needlework frame in X, Y-direction movement.DST is a kind of ternary coding form.△ x, △ y need calculate with reference to the weights shown in the table 3.
The weights of every correspondence in one pin of table 3.DST form
Computing formula is as follows:
△x=A
3*(-9)+A
2*9+A
1*(-1)+A
0*1+B
3*(-27)+B
2*27+B
1*(-3)+B
0*3+C
3*(-81)+C
2*81
△y=A
7*1+A
6*(-1)+A
5*9+A
4*(-9)+B
7*3+B
6*(-3)+B
5*27+B
4*(-27)+C
5*81+C
4*(-81)
C among the DST
7, C
6, C
1, C
0This four constitute its function code, as shown in table 4.
Function |
Value |
Make |
C
7=C
6=0,C
1=C
0=1
|
Bouncing pilotage |
C
7=C
1=C
0=1,C
6=0
|
Colour changing |
C
7=C
6=C
1=C
0=1, represent that other position of this pin is 0
|
Trimming |
The bouncing pilotage sign indicating number that several are continuous |
Finish |
C
7=C
6=C
5=C
4=C
1=C
0=1, represent that other position of this pin is 0
|
The function code of table 4DST
Also have a termination character 0xlA at DST formatted file end, in addition, empty needle is the special pin of making, and value is equal to 0.
According to said process, all data messages of DST file are resolved, after parsing is finished, create a width of cloth blank image, the information that obtains according to parsing on this image delineates out in this blank image, thereby obtains the image information of DST file.
1.3 the unit in the justifying DST file extracts
Fig. 2 is the manufacturing DST file of the typical down toy of a width of cloth, and Fig. 3 is the embroidery cloth of its correspondence.The characteristic feature of this class DST file is:
1, a big outer rim is arranged in the DST file, be used for determining to embroider the size of cloth;
2, there are some separate units inside, and each unit is the embroidered square of making down toy;
3, separate unit has frame line separately, and this edge frame line is actual to be the line of cut of this unit;
4, be bouncing pilotage between the separate unit, do not have line to connect, perhaps have only single line to connect;
5, in order to save the space, often according to left-right symmetry, perhaps symmetry is arranged up and down between the internal element;
6, the separate unit inner element is no more than line of cut.
According to these features, we have adopted method as shown in Figure 4 to extract separate unit in the DST file.
1.4DST resolve
The parsing of DST file is handled just passable according to header file composition and the coded system of DST file in theory, but in the DST of reality file, file data tends to occur indivedual mistakes, typical problem is exactly to represent view picture DST size+X in the header file,-X ,+Y ,-Y data are mistake often, the calculating so need sort to the point among the DST obtains actual DST image size.
At first, obtain the offset coordinates of every pin according to DST document No. mode, i.e. △ x, △ y value then by progressively addition, obtains the coordinate of each pin of view picture DST.Because coordinate zero point is starting point in the DST file, handle conveniently for successive image, need handle coordinate, first on upper left side is made as coordinate zero point, be to the right x axle positive direction, be downwards y axle positive direction.When resolving, note each at the embroidery mode of operation of answering.
1.4.1 the judgement of outer rim
In general view picture is embroidered cloth all outer rim, and embroidering the cloth housing mainly is for the size of confirming the DST file substantially, and product does not need outer rim but we send out existing in the reality investigation.Therefore, the first step of DST format analysis has judged whether outer rim exactly.Judge the flow process of outer rim, as Fig. 5.
In order to save cloth, some DST unit may intersect with outer rim, as Fig. 6 in the DST of reality embroidered square.So the size of frame not necessarily with DST space of a whole page equal and opposite in direction.Outer rim is all once embroidered into by embroidery machine, so outer rim is a continuous closed data segment, and continuous data segment is very many in the DST file, therefore need carry out verification to the DST continuous data segment of collecting, and judges whether it is outer rim.Rule of judgment:
1. four end points are relevant with DST space of a whole page size;
2. the point between each end points all point-blank.
1.4.2DST the judgement of cell borders
There is following feature DST unit in the down toy DST file:
1, DST cell borders closure;
2, not thread-changing in the single DST cell borders embroidery process;
3, two adjacent edge frames are if close together may not thread-changing, generally all can thread-changing;
4, the DST unit is arranged uncertainly, and at present association area does not also have Automatic Typesetting software, all is the own random arrangement of designer, and randomness is bigger;
5, if outer rim is arranged, then the frame of DST unit is only surrounded by outer rim.If no outer rim does not then have other closed data segment to surround the DST cell borders.
According to above feature, at first need to determine all closed data segments, judge then whether certain closed data segment is cell borders.Can judge according to feature whether a closed data segment is the DST cell borders.In practical operation, the DST cell borders is irregular figure often, judges whether inside has comparatively difficulty of element, so we adopt the processing of advancing of the method for boundary rectangle.
1.4.3DST inner element is determined
DST unit inner element feature in the down toy DST file:
1, internal element has been embroidered several times.For the consideration that reduces the colour changing number of times, generally all be that color identical in the whole space of a whole page has all been embroidered afterwards just can colour changing, so internal element will repeatedly could have been embroidered in general, so inner element comparatively disperses.
2, inner element can not surpass cell borders.
According to above feature, our processing method mainly is to mate except continuous data and existing DST cell borders boundary rectangle outside outer rim (if existence), the cell borders, and which element can determine has in certain DST cell borders.
1.5 extract DST unit internal information
DST unit according to above DST document analysis obtains extracts its inner parameter, is used for next step images match.By calculating parameters such as obtaining internal feature figure, barycenter, characteristic vector.Because might there be too much feature in inside, DST unit, therefore when extracting DST unit internal information, can be set to automatic information extraction, also can namely select interesting areas with mouse by the mode of artificial extraction.The present invention tends to the latter, the better effects if of coupling some.
2 sample extraction and processing
A most important step of vision-based detection is exactly IMAQ and processing, can realize accurate vision measurement by high-resolution camera, native system adopts the Cannon550d camera, and this camera has 1,800 ten thousand pixels, resolution ratio is 5184*3456, and camera lens is for focusing the 50mm camera lens.Can comparatively comprehensively extract sample information by high-resolution camera, for the processing of sample image is laid a good foundation.Native system has stronger applicability, can be applied in other similar system.
2.1 system calibrating
Because embroidery cloth full-size to be processed is 60cm*40cm, consider the lens parameters of camera, camera frame is located at 1.4m place directly over the cut surface.In case camera is in place, with the cutting machine working face of camera lens perpendicular alignmnet below, adjust camera to pinpointed focus, locked then, no longer change camera parameter and position.The effective field of view of camera is about 62.98cm*42cm.
Carry out camera calibration according to the Zhang Zhengyou method, can obtain the distortion parameter of camera after the demarcation and then utilize the least square circle to detect the information such as mapping point that are tied to the cutting machine coordinate system by camera coordinates.Thereby finish following function:
1, carries out predistortion by distortion parameter, recover the real cloth sample image of embroidering as much as possible;
2, carry out camera coordinates and be tied to mapping under the physical coordinates system (coordinate system of machine), thereby instruct cutting machine correctly to cut.
Need demarcate when using for the first time, the distortion parameter, confidential reference items matrix and the camera coordinates that are used for the acquisition camera are tied to the mapping relations of cutting machine coordinate system.Calibration process is:
At first obtain lens distortion parameter and the confidential reference items matrix of camera by " Zhang Zhengyou gridiron pattern standardization ".Preserve parameter then, behind later every acquisition piece image, at first carry out distortion correction, to recover the information of original image as far as possible.
Next, adopt " based on the coordinate system standardization of least square method circle detection " to obtain the coordinate system transformation matrix, step is as follows:
(1) at first designs the PLT file of demarcating circle for cutting, be illustrated in fig. 7 shown below, cut out the circle of the different radii arrangement of 6*9 at the blank sheet of paper of a 70cm*55cm;
(2) from the PLT file, obtain accurate central coordinate of circle under the cutting machine coordinate system, P
Ij=(x
Ij, y
Ij), x wherein
Ij, y
IjX axial coordinate and the y axial coordinate of the center of circle on the cutting machine coordinate system of representing the circle of the capable j row of i respectively;
(3) utilize camera to take one and demarcate circular image clearly, utilize existing distortion parameter then, carry out image and correct;
(4) adopt casual water completion method that the image after correcting is carried out binary conversion treatment, the circle in the image is become white, background becomes black;
(5) image after the binaryzation is carried out profile and extract, detect the point sequence C that each demarcates circle
Ij
(6) each point sequence is carried out the match of RANSAC circle, obtain the central coordinate of circle Q of each circle
Ij=(x'
Ij, y'
Ij), x' wherein
Ij, y'
IjRepresent x axial coordinate and the y axial coordinate that fasten in camera coordinates in the center of circle of the circle of the capable j of i row respectively;
(7) with the central coordinate of circle under the cutting machine coordinate system according to from left to right, form from top to bottom is arranged as homogeneous coordinates matrix P, with camera coordinates system down central coordinate of circle also be shown homogeneous coordinates matrix Q according to the race-card of correspondence;
(8) adopt least square method, calculate the transform matrix M that is mapped to the cutting machine coordinate system from camera coordinate system, make it to satisfy following formula:
Q*M=P
(9) preserve matrix M, with it as later coordinate system mapping parameters.
2.2 sample extraction
The process of sample extraction is that sample is taken pictures, and carries out the process of distortion correction then.Put into when embroidering the cloth finished product at every turn and need guarantee that sample fully in the visual field of camera, prevents the situation that sample departs from the camera visual field.Be printed on the boundary line of workspace at the working face of cutting machine, place that the boundary line can guarantee to embroider the cloth position in valid analysing range as long as roughly align in the upper left corner when embroidering cloth at every turn.
2.3 sample process
Figure 3 shows that an embroidery cloth that adopts the full-automatic computer embroidery machine to finish, embroider and be covered with a lot of flower type unit (minimum unit in the sampler file) on the cloth, the position of arranging of these flower type unit is basic consistent with the DST design document, therefore there is a perspective transformation matrix from the DST file to embroidery cloth sample, with the DST coordinate system transformation to embroidering the cloth physical coordinates is.Computer embroidering machine is according to the embroidery data that comprises in the DST file, and embroidery such as execution is made, bouncing pilotage, colour changing, trimming are moved.Usually the precision of computer embroidering machine is 0.1mm, under the condition of ignoring the machine system error, can think DST file and actual embroidery cloth finished product, is man-to-man full scale mapping.In the time of on embroidering the cut surface that cloth is placed on cutting machine artificially, exists one from the DST file to the perspective transformation matrix of embroidering cloth sample image, the DST coordinate system transformation is arrived magazine embroidery cloth coordinate system.But in actual the use, it is soft yielding embroidering cloth, causes this conversion to have error.Especially when embroidering the perk of cloth part, have tangible distortion.Therefore need to adopt least square method, calculate the optimal transformation matrix.
A common colored type unit has comprised line of cut and inner a plurality of colored type elements of a closure.These flower type elements arranging and the shape machine of all embroider is embroidered out according to the DST file, therefore, can embroider the thorn embroidery type unit that roughly find correspondence on the cloth according to the position that obtains flower type unit in the DST file.
The basic step of sample process is:
1, cell location according to the arrange linear transformation of position and camera of DST unit, estimates the approximate location of colored type unit, orients a rectangle frame.In the position fixing process, resolve the size of the colored type unit obtain according to DST, choose a rectangle frame that can comprise colored type unit, basis draws the rectangle frame that transforms on the cutting machine by camera to the coordinate system transformation of cutting machine then.
2, binaryzation with the coloured image binaryzation in the flower type unit rectangle frame, arranges embroidery cloth background colour and becomes black, and other elements become white, keep the contour feature of flower type unit inner element.The follow-on casual water completion method in this part is used for improving the effect that casual water is filled.A plurality of as sample point by in the embroidery sample, selecting at random, by judging whether these points of selecting at random are background dot, be used as the seed point if then keep, if not then ignoring, increased the robustness of system after the improvement, the better effects if that the water that overflows is filled.
3, calculate the contour feature vector, calculate Hu square and the barycenter of binaryzation frame.
2.3.1 cell location
According to the DST analysis result, can obtain size and the corresponding bounding box of each DST unit.Also exist a kind of linear transformation between the embroidery cloth sample that DST file and camera collect, therefore can estimate each cell position of embroidering in the cloth according to the cell position that from the DST file, is resolved to.Because camera is fixed, and DST embroidery file and corresponding embroidery cloth can be regarded as basically identical.Just exist translation, rotation, three kinds of conversion of convergent-divergent between the coordinate in the DST file and the corresponding camera coordinates.
The putting position of embroidering cloth has tentatively determined shift factor T and twiddle factor R.Owing to embroider the constraint that is subjected to a certain degree of putting of cloth sample, namely embroider the effective field of view that cloth must be put into camera, therefore can estimate shift factor T'.Can embroider the zoom factor S' of cloth according to a preliminary estimate by the visual field size of camera.Can estimate twiddle factor R' by four angles of embroidering cloth, concrete steps are as follows:
(1) according to embroidering the position constraint that cloth is put: owing to embroider the visual field problem that need consider camera when cloth is put, native system is marked with effective coverage and orthogonal coordinate at cutting machine.To embroider cloth and substantially put into cutting machine as requested, then embroider the cloth anglec of rotation be generally less than ± 10 °.Can be obtained the barycenter homogeneous coordinates V of unit, 4 summits again by DST document analysis result
k=(x
k, y
k, 1), k=1,2,3,4, and corresponding rectangular element frame R
k=W
k* H
kThe unit, summit is numbered 1~4 according to clockwise direction.
Parameter: x wherein
kFor obtaining the x axial coordinate of k summit units centre of mass of image after the DST parsing; y
kFor obtaining the y axial coordinate of k summit units centre of mass of image after the DST parsing; R
kFor obtaining the frame of the unit, k summit of image after the DST parsing; W
kBe its border width; H
kBe its frame length.
(2) adopt the Pan and Zoom conversion coefficient that estimates, obtained the initial barycenter homogeneous coordinates of unit, 4 summits in the sample image by following formula:
V'
k=(x'
k,y'
k,1),k=1,2,3,4
The frame of unit, 4 summits in the image:
R'
k=W'
k×H'
k=S'W
k×S'H
k
Parameter: x wherein
k' be the x axial coordinate of k summit units centre of mass of sample image; y
k' be the y axial coordinate of k summit units centre of mass of sample image; R
k' be the frame of the unit, k summit of sample image; W
k' be its border width; H
k' be its frame length; T'
xShift factor for x axle in the sample image; T'
yShift factor for y axle in the sample image.
(3) it is level and smooth sample image to be carried out Gauss, and it is down-sampled to carry out 1/2 pyramid then, might as well get 1/4 rectangular area of embroidering the cloth size at the center of embroidering cloth, counts the highest color of the frequency of occurrences as embroidering the cloth background colour by color histogram.
(4) in sample image, with coordinate V'
kCentered by, then with 1.5W
k' * 1.5H
k' fill binary conversion treatment for carrying out 11 casual water in the rectangular area of length and width.Shown in Fig. 8 (wherein Fig. 8 is that 9 casual water are filled), select 11 points as alternative seed point at first at random, seed point to each candidate, in the zone of 11 * 11 neighborhoods, calculate color mean value, if mean value approaches the background colour of embroidering cloth, and neighborhood color variance is less, then this point is classified as casual water and is filled the seed point.
(5) each seed point is carried out casual water filling algorithm, obtain unit V'
kBinary image.Then, carry out sliding window search, in window, calculate contour area than and regional Hu square, and with DST in corresponding vertex V
kContour feature carry out similitude relatively, be shown below:
I(A,B)<T
hu
Wherein: A resolves the unit of back image for the DST that selects; B is the unit of the sample image of selection;
With
It is respectively the Hu square of A and B.T
HuBe Hu square similarity threshold, generally be taken as 1.5.
(6) will satisfy the rectangular area of area ratio and Hu square similarity threshold as unit V'
kThe boundary candidate frame, then, with the boundary candidate of Hu square similarity minimum as unit V'
kThe real border frame.And obtain the true barycenter V'' of unit
k
(7) by vertex vector in the image
Vertex vector with DST embroidery file
Between angle theta
kAnd shift factor T', can obtain twiddle factor estimated value R'=θ.
(8) according to resolving each DST cell borders upper left corner homogeneous coordinates L that obtains in the DST file
k=(x
k, y
k, 1) and estimate the transformation factor obtain, can estimate the frame upper left corner homogeneous coordinates L' of each flower type unit in the image
kCorresponding DST frame scaled S' doubly.
2.3.2 the binaryzation of embroidery sample
After carrying out cell location, can decide the home position of each flower type unit, local positioning is carried out in each frame inside then.Not only reduce treating capacity, accelerated processing speed, and improved positioning accuracy.The binaryzation of flower type unit is the basis of accurately extracting each unit inner element contour feature.By contrasting various binarization methods, the result of contrast binaryzation in order to guarantee the robustness of binaryzation, has improved original casual water filling algorithm, has designed a kind of adaptive casual water filling algorithm:
1, obtains the main background colour of embroidering cloth.According to DST file and camera parameter, select to embroider the cloth central area, the color histogram in computer center zone, with the highest color of frequency as embroidering cloth master color, i.e. background colour;
2, adopt 9 methods to calculate the seed point that casual water is filled.Sampling 9 points as shown in Figure 8 in image, whether be background colour, if background colour is then included it in the seed point if calculating this place neighborhood window;
3, adaptive threshold is chosen.Adopt basic thresholding method to obtain the threshold value that two-value is cut apart, and calculate crest to both sides, quantize the peak separation.By the discretization of quantized interval, realize adaptive threshold;
4, with adaptive threshold the seed point that remains is overflow water and fill, and add up the coverage of each seed point and the color average of covering;
5, filter casual water blank map by hsv color, realize embroidering the sample binaryzation.By the seed point coverage of adding up in 9 casual water filling process, can further upgrade background colour.Calculate the hsv color value of background colour then, filter out residual block of pixels in the binary map with this color value;
6, the UNICOM's territory area in the statistics bianry image, UNICOM's territory bounding box length-width ratio filters out the part zone errors;
7, fill the profile that remains, export complete binary map.
2.3.3 flower type element characteristic extracts
According to the cell location among the 2.3.1, regional Hu square and geometric properties in rectangle frame after the calculating embroidery unit binaryzation.
3 couplings
Calculated the internal feature of DST unit and the internal feature of colored type unit to be matched with top, next needed to mate.Coupling is divided into:
1, geometric properties coupling: a. comprises that area filters, and the profile that contour area is too big or too little is rejected; B. the bounding box length-width ratio is not satisfied the rejecting of threshold value.
2, outline contrasts the Hu square that each spends corresponding unit in type unit and the DST file, calculates matching result.Matching formula:
I(A,B)<T
hu
And successfully the units centre of mass of coupling remains, and further does the least square conversion;
3, least square conversion, the least square conversion of each corresponding unit center-of-mass coordinate can obtain a perspective transformation matrix C among the barycenter by flower type unit and the DST.
The 4DST mapping
According to the perspective transformation matrix that coupling obtains, the line of cut that the DST document analysis is obtained is mapped on the embroidery sample image, and shows the embroidery sample image after the mapping.The present invention also has been equipped with individual fine adjustment function, if the line of cut location is inaccurate, and can manual change's line of cut position.After the DST mapping is finished, preservation is mapped to the line of cut information of embroidery sample image, and this information is transformed on the cutting machine coordinate system: demarcate the transform matrix M that the camera coordinates that obtains is tied to the cutting machine coordinate system according to coordinate system, X is the line of cut coordinate of each unit among the DST, and Y is the coordinate of cutting machine coordinate system
Y=CMX
Line of cut image after the preservation conversion, this moment, this line of cut image was laser cutting machine movement locus line to the end.
Because the laser cutting machine control card is only accepted the movement locus of PLT form, therefore the line of cut image that need will obtain at last saves as the file of PLT form.
Operational instances
Be illustrated in figure 9 as the MFC interface that the present invention does, this interface mainly is divided into five parts: embroidery pattern, camera control, image detection, camera calibration and upper right corner display box.Wherein, the embroidery pattern is mainly used in the DST document analysis, by opening the DST file, shows the DST image that parses in the window thereunder; Camera control mainly is the input of control sample image, is used for obtaining sample image, by showing sample information on the cutting machine at upper right corner display box; Image detection is the further processing after the sample image input, mainly is work such as images match, line of cut location; Camera calibration is to be used for determining raw informations such as camera basic parameter, coordinate system transformation when using this invention for the first time.
Figure 10 is the cutting machine schematic diagram after the improvement of the present invention.As shown in FIG., camera frame is located at 1.4m place directly over the cut surface, can comparatively ideally obtain the cloth information of embroidering like this, because uneven illumination is even the image post-processed there is very big influence, therefore set up two fluorescent lamps on the cutting machine both sides, can reduce the inhomogeneous influence for post-processed of light so to greatest extent.The effective field of view of camera is about 62.98cm*42cm, therefore need consider visual field problem when placing embroidery cloth, and we have marked the desirable visual field on cut surface, only need put into marked region substantially when cloth is embroidered in placement and get final product.
Provide the operating procedure of an example below:
(1) need demarcate when of the present invention for the first time using.There are two buttons to be used for demarcating in the lower right corner at MFC interface, finish demarcation by clicking these two buttons, obtain the raw information of system.
(2) sample of will embroidering is put on the working face of cutting machine, is printed on the boundary line of workspace at working face, places that the boundary line can guarantee to embroider the cloth position at valid analysing range as long as roughly align in the upper left corner when embroidering cloth at every turn.
(3) click open button, input is DST file and the parsing of correspondence with it, shows the DST image after resolving in the display window of this part.
(4) click " finding a view " button at the camera control section, in top-right display box, show the visual field of camera, judge by observing whether the embroidery sample is placed in the effective field of view.
(5) clicking " taking pictures " button is used for sample image is imported into system.
(6) click " position probing " button this moment, obtain the matching result of DST image and embroidery sample, as shown in figure 11.Red square frame among the figure, the result of expression coupling namely searches out characteristic area.
(7) click " line of cut detections " and obtain the image that shows among Figure 12, Figure 13, the line of cut image that image obtains according to matching result, it is qualified that the result who locatees by the observation line of cut judges whether.
(8) judge that line of cut is qualified after, click " derivations " button and derive the PLT formatted file that cutting machine can read, begin to cut, cutting process is as shown in figure 14.
(9) Figure 15 is through the cloth after the laser cutting.