Long ago wanted to summarize the previous time study Halcon's experience, but because other things always can't spare time. Last year, there was a period of concentration study, did a lot of exercises and experiments, and the shape matching algorithm based on the Hdevelop parameter optimization, wrote a "hdevelop-based Shape matching algorithm optimization research" article, summed up in the shape matching process which parameters affect the template search and match, and how to coordinate these parameters to speed up the matching process, improve the accuracy of matching, this paper put on the Chinese paper online, need to be able to download.
The German Mvtec company developed the Halcon Machine Vision development software, which provides many features, where I mainly study and study the shape matching algorithms and processes. There are three kinds of matching methods in HDEVELOP development environment, namely component-based, gray-value-based, shape-based, which are based on component (or component, Element) matching, based on gray value matching and shape-based matching. These three matching methods have their own characteristics and are suitable for different image features, but they all have the same process of creating templates and looking for templates. In these three methods, I mainly on the third-shape-based matching, do a lot of experiments, so also do a shape-based object recognition, based on shape matching video object segmentation and shape matching based on the video object tracking these studies, to achieve better results, simplifying the use of other tools, such as VC + + To develop the process. Under the VC often for different image formats, you will get a headache, not to mention the code to write Image feature extraction, template creation and search template, I think the process will be very complex, the effect will not necessarily be significant. In the following, I will discuss the research and summary of the shape matching algorithm based on Halcon.
1. Basic process of shape-based matching
Halcon provides a shape-based algorithm to create a template for a small area of interest, to create a template for the entire image, but unless the object is a large proportion of the entire image, such as a video conference, such as the upper body of the image, I am in the back of the video object tracking experiment is aimed at the entire image, which is often to sacrifice the matching speed, this later. The basic flow is this, as follows:
⑴ first to determine the ROI of the rectangular region, here only need to determine the upper left and right of the coordinates of the lower point, gen_rectangle1 () This function will help you to create a rectangle, using Area_center () to find the center of the rectangle;
⑵ then needs to get the image of this rectangular region from the image, Reduce_domain () will get this ROI; after that, you can create a template for the rectangle, and before you create the template, you can do some processing of the area to facilitate later modeling, such as threshold segmentation, Some processing of mathematical morphology and so on;
⑶ can then use Create_shape_model () to create the template, which has many parameters, where the pyramid's series is specified by Numlevels, and the larger the value, the less time it takes to find the object. Anglestart and Angleextent determine the possible range of rotation, anglestep the step size of the specified angle range; It should be reminded that in any case the template should be suitable for main memory and the search time will be shortened. For particularly large templates, it is useful to use optimization to reduce the number of template points; Minconstrast separates the template from the noise of the image, and if the range of the grayscale value is 10, the minconstrast should be set to 10 The metric parameter determines the criteria for template recognition, and if set to ' Use_polarity ', the object and template in the image must have the same contrast; After creating the template, you also need to monitor the template, with Inspect_shape_model (), it checks the applicability of the parameters , it also helps to find the right parameters, and it also needs to get the contour of this template for subsequent matches, and Get_shape_model_contours () will easily help us find the profile of the template;
⑷ after you create a template, you can open another image to match the template. This process is in the new image to look for a template to match the part of the image, this part of the work is performed by the function Find_shape_model (), it also has a number of parameters, these parameters affect the speed and accuracy of the search template. The function of this is to find the best matching template in a graph and return the length, width and rotation of a template instance. Where the parameter subpixel determines whether accurate to sub-pixel level, set as ' interpolation ', it will be accurate, this mode will not take up too much time, if needed more accurate, it can be set to ' Least_square ', ' lease_square_ High ', but this will add extra time, so this requires a tradeoff between time and precision, which needs to be linked to the actual. The more important two parameters are Minsocre and greediness, the former is used to analyze the rotation symmetry of the template and the similarity between them, the greater the value, the more similar, the latter is the search greed, the value of a large extent affect the search speed, if 0, then heuristic search, very time-consuming, if 1, It is unsafe to search, but the quickest. In most cases, the value can be increased as much as possible in the case of matching.
Once ⑸ is found, it needs to be transformed so that it can show that the two functions Vector_angle_to_rigid () and AFFINE_TRANS_CONTOUR_XLD () play this role here. The previous one calculates a rigid-body affine transformation from a point and an angle, which is useful for constructing a rigid-body affine transformation from the results of a matching function, turning the reference image into the current image.
Its detailed flowchart and intermediate parameters, as shown in the following figure: (Cannot upload)
2. Parameter relationship and optimization based on shape matching
In Halcon's explanatory material, the role of these parameters and relations, in the above mentioned in the article is also introduced, here is mainly to repeat the role of these parameters, and then emphasize the extent of their impact on the matching speed;
Before setting parameters to speed up, it is necessary to identify those settings that match successfully in all test images, and consider the following scenarios:
① must ensure that the object is truncated at the edge of the image, that is, to ensure the clarity of the contour, which can be processed by some morphological methods;
② if the value of greediness is set too high, some of the visible objects cannot be found, then it is finally set to zero to perform a full search;
③ The object has a closed area, if the object can be recognized in any state, then the Minscore value should be reduced;
④ determines whether the match at the top of the pyramid fails and can be tested by Find_shape_model () reducing the numlevels value;
Whether the ⑤ object has a lower contrast, if the object can be recognized in any state, the Mincontrast value should be reduced;
⑥ judge whether to convert the contrast polarity globally or locally, if it is necessary to be recognized in any state, the parameter metric should be set to a suitable value;
⑦ objects overlap with other instances of the object, and if the object needs to be recognized in any state, the MAXOVERLAP value should be increased;
⑧ determines whether multiple matching values are found on the same object, and if the object is almost symmetrical, the rotation range needs to be controlled;
How to speed up the search match, need to be in these parameters reasonable collocation, there are the following methods can be consulted:
① as long as the match succeeds, increase the value of the parameter Minscore as much as possible;
② increases the greediness value until the match fails, while reducing the minscore value when needed;
③ if possible, use a large numlevels when creating the template, and the image will be divided into several pyramid levels;
④ limits the allowable rotation range and size range, and adjusts the corresponding parameters when calling Find_shape_model ();
⑤ try to limit the area of search ROI;
In addition to the above described, in the case of guaranteed to match, as far as possible to increase the value of greediness, because in the subsequent experiments, the template matching for the video object tracking process, this value to a large extent affect the speed of matching.
Of course, these methods need to be connected with the actual, different images in the matching process will have different matching effect, in specific to some applications, different hardware facilities will also put forward new requirements for this matching algorithm, so need to constantly try. In the next I will combine the specific experiments I do to use Halcon to carry out experiments, mainly in the video object segmentation and video object tracking.