Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

ROI not working in Visual Basic OCR Example - either -

The code:

 

'NIOCR1.ReadText2 CWIMAQViewer1.Image, readString, CWIMAQViewer1.Regions, charReport'

 

in the 'OCR First Example' seams to not work as advertised. I attached a picture of the application where I draw an ROI as instructed and 'ReadText2' function seams to just ignore the region and trys to read everything in the image. I have an application I'm trying to develop that reads multiple lines of text on a label using several ROIs to separate them and it doesn’t even work at all because of this. It does seam to work in the Vision Assist program so I attached an example so you can see what I'd like it to do. 

 

Please help... 

Download All
0 Kudos
Message 1 of 8
(4,907 Views)

Hi Gearsoft,

 

I ran the same example (OCR First Example) and did not see the same behavior.  It seemed to only report the letter or letters in the ROI that I selected.


What version of vision do you have?  I am running Vision Development Module 2010.  I'm not sure if it has changed between versions, but it is possible.  If you post your example I can run it and see if I get the same result.

Justin D.

Applications Engineer
National Instruments
0 Kudos
Message 2 of 8
(4,877 Views)

Hi Justin,

 

Here's the example I'm using. It's straight out of the Vision Development Module 2010. I'm running it in Windows XP 32 bit with VB6 SP6. Also I've tried it on several other XP and Windows 7 computers with the same results. I really need this feature to work in my project or I may have to do some masking or some other 'work-around' to extract the text.

 

Thanks,

John

0 Kudos
Message 3 of 8
(4,874 Views)

Hi Gearsoft,

 

I actually do see the same behavior.  The example that I said was working before was a C example that I ran in CVI. I found this example under Documents\National Instruments\CVI\samples\Vision\2. Functions\OCR.

 

I apologize for not paying closer attention to the original post.  I actually do see the same behavior as you described earlier.  I am currently looking at these examples and trying to figure out what is wrong with the VB example.

Justin D.

Applications Engineer
National Instruments
0 Kudos
Message 4 of 8
(4,861 Views)

Justin,

 

I'm glad to see it's not just me. I hope you do find the answer to this. My thought is that there's an issue with the vb ocx wrapper file. If that's the case can you get me the direct declarations for the niocr.dll file? ie: 'Declare Sub ReadText2 Lib "niocr.dll" (ByRef Image as Object, ByVal readString as String, ByRef Regions as Object, ByRef charReport as Object)' (something like that) and the other functions that pertain to niocr.dll.

Here's all of the ocr related functions from the C header file but I need them in vb, if there's no other work-around, and I don't know how to do the convertion:

 

//============================================================================
//  OCR functions
//============================================================================
IMAQ_FUNC CharSet*         __stdcall imaqCreateCharSet(void);
IMAQ_FUNC int              __stdcall imaqDeleteChar(CharSet* set, int index);
IMAQ_FUNC int              __stdcall imaqGetCharCount(const CharSet* set);
IMAQ_FUNC CharInfo2*       __stdcall imaqGetCharInfo2(const CharSet* set, int index);
IMAQ_FUNC int              __stdcall imaqReadOCRFile(const char* fileName, CharSet* set, String255 setDescription, ReadTextOptions* readOptions, OCRProcessingOptions* processingOptions, OCRSpacingOptions* spacingOptions);
IMAQ_FUNC ReadTextReport2* __stdcall imaqReadText2(const Image* image, const CharSet* set, const ROI* roi, const ReadTextOptions* readOptions, const OCRProcessingOptions* processingOptions, const OCRSpacingOptions* spacingOptions);
IMAQ_FUNC int              __stdcall imaqRenameChar(CharSet* set, int index, const char* newCharValue);
IMAQ_FUNC int              __stdcall imaqSetReferenceChar(const CharSet* set, int index, int isReferenceChar);
IMAQ_FUNC int              __stdcall imaqTrainChars(const Image* image, CharSet* set, int index, const char* charValue, const ROI* roi, const OCRProcessingOptions* processingOptions, const OCRSpacingOptions* spacingOptions);
IMAQ_FUNC int*             __stdcall imaqVerifyPatterns(const Image* image, const CharSet* set, const String255* expectedPatterns, int patternCount, const ROI* roi, int* numScores);
IMAQ_FUNC int*             __stdcall imaqVerifyText(const Image* image, const CharSet* set, const char* expectedString, const ROI* roi, int* numScores);
IMAQ_FUNC int              __stdcall imaqWriteOCRFile(const char* fileName, const CharSet* set, const char* setDescription, const ReadTextOptions* readOptions, const OCRProcessingOptions* processingOptions, const OCRSpacingOptions* spacingOptions);


//============================================================================//  OCR functions//============================================================================IMAQ_FUNC CharSet*         __stdcall imaqCreateCharSet(void);IMAQ_FUNC int              __stdcall imaqDeleteChar(CharSet* set, int index);IMAQ_FUNC int              __stdcall imaqGetCharCount(const CharSet* set);IMAQ_FUNC CharInfo2*       __stdcall imaqGetCharInfo2(const CharSet* set, int index);IMAQ_FUNC int              __stdcall imaqReadOCRFile(const char* fileName, CharSet* set, String255 setDescription, ReadTextOptions* readOptions, OCRProcessingOptions* processingOptions, OCRSpacingOptions* spacingOptions);IMAQ_FUNC ReadTextReport2* __stdcall imaqReadText2(const Image* image, const CharSet* set, const ROI* roi, const ReadTextOptions* readOptions, const OCRProcessingOptions* processingOptions, const OCRSpacingOptions* spacingOptions);IMAQ_FUNC int              __stdcall imaqRenameChar(CharSet* set, int index, const char* newCharValue);IMAQ_FUNC int              __stdcall imaqSetReferenceChar(const CharSet* set, int index, int isReferenceChar);IMAQ_FUNC int              __stdcall imaqTrainChars(const Image* image, CharSet* set, int index, const char* charValue, const ROI* roi, const OCRProcessingOptions* processingOptions, const OCRSpacingOptions* spacingOptions);IMAQ_FUNC int*             __stdcall imaqVerifyPatterns(const Image* image, const CharSet* set, const String255* expectedPatterns, int patternCount, const ROI* roi, int* numScores);IMAQ_FUNC int*             __stdcall imaqVerifyText(const Image* image, const CharSet* set, const char* expectedString, const ROI* roi, int* numScores);IMAQ_FUNC int              __stdcall imaqWriteOCRFile(const char* fileName, const CharSet* set, const char* setDescription, const ReadTextOptions* readOptions, const OCRProcessingOptions* processingOptions, const OCRSpacingOptions* spacingOptions);

 

I'm probably jumping the gun here so I'll wait to see what you find.

 

Thanks,

John

0 Kudos
Message 5 of 8
(4,850 Views)

Hi Justin,

 

I couldn't wait for your response so I came up with this workaround.

 

Here's a snipit of the code and I attached the modified vb example:

 

        'Workaround for vb version of ReadText2
        Dim Rectangle As New CWIMAQRectangle
        CWIMAQViewer1.Regions(1).GetBoundingRectangle Rectangle
        CWIMAQVision1.Extract2 CWIMAQViewer1.Image, CWIMAQViewer2.Image, Rectangle
        'Workaround for vb version of ReadText2
        
        ' Read the text
        NIOCR1.ReadText2 CWIMAQViewer2.Image, readString, CWIMAQViewer1.Regions, CharReport
I used the Extract2 function in the vision control to copy a crop of the region that you draw on the first image then read the whole cropped image with the ReadText2
If you figure out what's going on with the ReadText2 function please let me know, otherwise I'll take my own solution as the answer and Kudo myself.
Thanks,
John

 

Download All
0 Kudos
Message 6 of 8
(4,829 Views)

I am having this same problem and National Instruments has not been very helpful so far.

 

I need to specify a rotated ROI so the extract work arround will not work for me.

 

I have been trying to get my application I wrote in 2007 to run with the new versions, but it appears more is broke than fixed over the years.

0 Kudos
Message 7 of 8
(4,360 Views)

When you talk about the 2007 versions and the new versions are you talking about the Vision drivers or Visual Basic? Also, as a note, this is an older thread. Newer threads get more attention from users. It would be a good idea to create a new thread on your question.

Cameron T
Applications Engineer
National Instruments
0 Kudos
Message 8 of 8
(4,335 Views)