Page 43 -
P. 43
Chapter 1 ■ Practical Aspects of a Vision System 17
if(!img)
{
printf(“Could not load image file: %s\n“,argv[1]);
exit(0);
}
// get the image data
height = img->height;
width = img->width;
step = img->widthStep;
channels = img->nChannels;
data = (uchar *)img->imageData;
printf(“Processing a %dx%d image with %dchannels\n“,
height,width,channels);
// create a window
cvNamedWindow(“win1“, CV_WINDOW_AUTOSIZE);
cvMoveWindow(“win1“, 100, 100);
// show the image
cvShowImage(“win1“, img );
// Convert to AIPCV IMAGE type
x = fromOpenCV (img);
if (x)
{
thr_glh (x);
img2 = toOpenCV (x); // Convert to OpenCV to display
cvNamedWindow( “thresh“);
cvShowImage( “thresh“, img2 );
cvSaveImage( “thresholded.jpg“, img2 );
}
// wait for a key
cvWaitKey(0);
// release the image
cvReleaseImage(&img);
return 0;
}
In the remainder of this book, we will assume that OpenCV can be used for
image display and I/O and that the native processing functions of OpenCV
can be added to what has already been presented.
For convenience, the AIPCV library contains the following X functions for
IO and display of its images directly to OpenCV: