09-22-2011 10:05 AM
Hello
I am trying to explore the LearnPatternAdvancedOptions and MatchPatternAdvancedOptions of the NI Vision CVI since I am developing a inspection system using C++. But I can not figure out how to use these two parameters and get errors. I did the following
(1) First, I did was trying the VC example "Easy Pattern Matching", in National Instruments\Vision\Examples\MSVC. This example uses
imaqLearnPattern() to learn the template and imaqMatchPattern() to search, which works well.
(2) Then, I noticed in the NI Vision CVI function reference, these functions are obsolete, and there are new versions as imaqLearnPattern3() and imaqMatchPattern2(), I then replaced the two functions, and it also works well. But here I put NULL to the LearnPatternAdvancedOptions and MatchPatternAdvancedOptions parameters of the two functions, as in
imaqLearnPattern3(templateImage, IMAQ_LEARN_ALL,NULL,NULL);
imaqMatchPattern2(searchImage, templateImage, &matchOptions,NULL,IMAQ_NO_RECT, &numMatches);
(3) Last, I tried to use these advance option parameters, and I defined the following:
LearnPatternAdvancedOptions LPAO;
MatchPatternAdvancedOptions MPAO;
and used as
imaqLearnPattern3(templateImage, IMAQ_LEARN_ALL,&LPAO,NULL);
imaqMatchPattern2(searchImage, templateImage, &matchOptions, &MPAO,IMAQ_NO_RECT, &numMatches);
However, either case I try, the applcation crashed. The error message shows neither &LPAO nor & MPAO is properly used. So could any expert here give me some hint how to handle these two parameters?
Thanks
Ben
09-23-2011 02:33 PM
Ben,
It appears that you are not actually calling any of the advanced functions. These functions can be found in the CVI help. In the help contents tab, go to NI Vision for Lab Windows/CVI Function Reference Help»Function Reference»imaqLearnPattern3 and then follow the link to LearnPatternAdvancedOptions. You can then open either the Shift Options or Rotation Options to see the list of specific calls for each element. Please let me know if you have any further questions or this does not solve your issue.
09-23-2011 03:13 PM
Hi Chris
Thank you for the reply. I did look into the CVI reference and added the following
LearnPatternAdvancedOptions LPAO;
LPAO.rotationOptions=(LearnPatternAdvancedRotationOptions*)malloc( sizeof(LearnPatternAdvancedRotationOptions));
LPAO.rotationOptions->searchStrategySupport=IMAQ_CONSERVATIVE;
imaqLearnPattern3(templateImage,IMAQ_LEARN_ROTATION_INFORMATION,&LPAO,NULL);
The application builds successfully, but crash when run to the learning step, the debugger shows " Access violation reading location ", so I seems not setting up the pointer of the LPAO correctly. Could you give some hint?
Thanks
Ben
09-26-2011
12:33 PM
- last edited on
10-30-2025
06:31 PM
by
Content Cleaner
Ben,
I apologize for not catching this earlier, but I just realized you said you are using C++. CVI does not directly support C++. There is a way around that using DLLs which is explained in the KnowledgeBase article below. However, you may want to look into using Measurement Studio (NI's add-on to MS Visual Studio) as it directly supports C++. I've included a link to a tutorial on using C++ with Measurement Studio. One other thing I would point out is that I don't see where you are initializing your variable. You have a pointer to LPAO, but I don't see where you actually define it. Each function has its own data type which must be initialized prior to calling the function. The functions and their associated data types can be found on the help page I referenced in my earlier post. Take a look at these two documents and let me know if you have any further questions.
https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z000000P6EPSA0&l=en-US
http://zone.ni.com/devzone/cda/tut/p/id/3637