C # App Video tutorial 3.4 halcon+c# test

Source: Internet
Author: User

With the previous foundation, let's test how to make the program more generic, first of all, the initialization of the method to modify, at the time of initialization to pass the past Htuple this object (changed to a global variable, so that different method calls)

?

Next need to have camera open/camera off, image saving/image loading function (convenient for us to do a quick test), the front of the camera operation has been said, here the image loading is only applied to the front loading a static image function (the absolute address changed to the parameters), Save image calls the Writeimage method of Halcon

?

This method can be used to refer to the example write_image (see his exported C # program, slightly modified on the line)

?

In addition, in order to prevent the program exit when the control is still running error, so when the form closes, you need to kill the class thread, those variables are thrown away

?

How do I put the template matching content over? We target the C # code generated by the sample program to the part of the drawing feature rectangle, which basically can copy this part (draw rectangle, create rectangle)

?

Of course, after the completion of the drawing will output a lot of parameters of the rectangle, these variables to copy the generated C # code, these long-width high, pi, area, angle is basically the htuple type, this type can be easily understood as floating point number (sometimes also expressed as 0255 of the byte, or int, etc.)

?

Next to the most important part, in fact, two functions, one is to create a template, one is a matching template (generated in C # code inside the For loop body there are also some functions, through the Halcon execution can be found that he is to let the picture rotated at a certain angle and then as a new picture, This has nothing to do with our current project, so we just need to master these two functions.

?

Halcon image processing is process-like, such as a image is the original image, first processing to get B, then do a second processing to get C, so down to the end of the image we need to get the part. Although we do not necessarily fully understand the specific meaning of each image processing algorithm, but as long as the understanding of his process will be used (in this project he finally got the Ho_imagereduced object, output the template matching Hv_tempalteid object)

?

If you want to deepen halcon the effect of the variable you get after each line of program operation, or return to the Halcon program, you can navigate to the variable window every time you F6 one step, and mouse over each of the generated variables to see his hint (region is a variable, image is a variable)

?

You can test the results of the run, draw a rectangle first, then right-click to finish, you can actually get X,y,r,error

?

So how to perform dynamic matching (if we want to let the camera keep taking pictures, and constantly recognize the characteristics and outgoing coordinates), just put this part of the code into the dead loop inside the line (or to do the global Boolean variable, only after the template has been done, otherwise it will error, Your tempalteid is not instantiated), you can test whether the image is moving or you can always get the value

?

It is common sense to know that the default level is the y-coordinate, the vertical is the x-coordinate, and the upper-left corner is the [0,0] point. The so-called error is the value of 0-255 (the exact match is 0, a complete mismatch is 255), and the output of R is radians (these can be tested on their own, the left is my hand to completely block the effect of the picture, the right picture is I rotate the camera 90 degrees of effect, because the monitor is not very good to move)

?

Finally, let's look at a feature that reads and writes feature matching templates (you can't turn on the camera every time-save images-Browse graphics-set Features-get feature matching id-auto mode), we certainly want to match this so-called match ID to save, next time can be loaded automatically run. Halcon also does have an example that provides the Write_template and Read_template methods (the saved file has no suffix, the name is TESTT, this is a bit strange, actually a text file, 2-3m about the size)

?

With the previous experience, here you can directly copy the generated C # code, a Writetempalte method and Readtempalte method, very good understanding (I wrote before the read and write file method must add type, here in order to unify, also set a txt type for him)

?

When reading the template, note that the function parameters to take ref, so-called with ref is the function input variable will be modified (detailed usage you can do a few simple functions to do the test, without ref is more commonly used, if not with the class instance of the Hv_templateid can not be modified, Of course, it can be implemented in other ways.)

?

Summary: So far the mixed programming of Halcon and C # is complete. Things that involve algorithms in industrial applications (like processing, motion control) seldom use C # as the final execution program, because the efficiency is low. But this does not prevent us to use C # as the upper-level interactive program, call others developed DLL, in fact, if used in C + + to do the upper layer, these application layer validation, processing will be more trouble than C #. In the whole image processing algorithm, feature matching is very useful, you can use it as a character recognition (you pick a letter a, and then find all the letter A in the image), can also be used as face recognition (when the match rate is less than the same person, or match a face to remove the image of this face, Discover the possible twins or something). can also be used as a flaw detection (you pick a normal product sample picture, and then take this sample than the wrong thing, if found that the error exceeds a certain value of the product is considered a problem, otherwise qualified) readers need to master:

1 General Vision System operation, basic pixel, binary, exposure, feature, concept of match rate

2 basic usage of Halcon, understanding the design concept of excellent software (especially for such a platform-level product)

3 Halcon+c# 's hybrid programming approach, Understanding C # 's best practices, and experimenting with this hybrid programming in a possible future project

?

?

For more instructional videos and downloads, please pay attention to the following information:

My Youku Space:

Http://i.youku.com/acetaohai123

?

My online forum:

http://csrobot.gz01.bdysite.com/

?

Problem Exchange:

qq:910358960

Email:[email protected]

?

?

C # App Video tutorial 3.4 halcon+c# test

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.