Chapter 5 Performing Machine Vision Tasks
© National Instruments Corporation 5-29 IMAQ Vision for LabWindows/CVI User Manual
The following code sample provides an example of a typical classification
application.
ClassifierSession* session;
Image* image;
ROI* roi;
char* fileName; // The classifier file to use.
ClassifierReport* report;
session = imaqReadClassifierFile(NULL, fileName,
IMAQ_CLASSIFIER_READ_ALL, NULL, NULL, NULL);
while (stillClassifying)
{
// Acquire and process an image and store it in the
//image variable.
// Locate the object to classify, and store an ROI
//containing that object in the roi variable.
report = imaqClassify(image, session, roi, NULL, 0);
// Take action based on the report.
imaqDispose(report);
}
imaqDispose(session);
Reading Characters
Use OCR to read text and/or characters in an image. Typical uses for OCR
in an inspection application include identifying or classifying components.
Before you read text and/or characters in an image, you must train the
OCR Session with samples of the characters using the NI OCR Training
Interface. Go to Start»Programs»National Instruments»Vision»OCR
Training to launch the OCR Training Interface.
After you have trained samples of the characters you want to read, use the
following functions to read the characters:
1. Use imaqReadOCRFile() to read in a session that you created using
the NI OCR Training Interface.
2. Use imaqReadText() to read the characters inside the ROI of the
image under inspection.
3. Use imaqDispose() to free the resources that the OCR Session used.