This is how we display and process an Image using Opencv:
int _tmain(int argc, _TCHAR* argv[]) {
IplImage* img = cvLoadImage( "MGC.jpg" );
cvThreshold( img, img, 200, 255, CV_THRESH_BINARY );
cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE );
cvShowImage("Example1", img);
cvWaitKey(0);
cvReleaseImage( &img );
cvDestroyWindow( "Example1" );
return 0;
}
Now can you help me to achieve my goal as outlined below:
int _tmain(int argc, _TCHAR* argv[]) {
Some code here (using some API other than OpenCv).... // Captures a frame and
//streams the data into a buffer Buf
Buffer B= Buf; // B contain binary image data i.e 16 bit pixel values
cvThreshold( B, B, 200, 255, CV_THRESH_BINARY );//Notice I am putting B and not an
//Image(legal?)
cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE );
cvShowImage("Example1", B); //Notice I am putting B and not an Image(legal?)
cvWaitKey(0);
cvReleaseImage( &B );
cvDestroyWindow( "Example1" );
return 0;
}
Notice that I have not used any hard-disk read/write operation in the second code snippet, such as the following:
IplImage* img = cvLoadImage( "MGC.jpg" );
Basically I am working with real-time scenario thus I am bypassing the time consuming cvLoadImage
. Obviously not saving the data into hard-disk, my entire data is still in the Buffer B
. This save my time which is critical for my application.
Note: The fact is I will be doing more processing on the Buffer B
, such as applying cvminmaxloc
etc. But all these functions require an Image loaded from disk, not a buffer such in my case.
Can some point me to right direction to achieve my goal of working on Buffers instead of Images stored in the hard-disk? Am I committing some mistake in understanding the openCV functions?
Update:
A suggested below I can use imdecode
for reading images from buffer. As explained above actually I will be doing processing on the image using OpenCv functions, for example CVMinMaxLoc
and
cvThreshold( src, src, 200, 255, CV_THRESH_BINARY );
Now can I put Buffer
as the first argument instead of Image in cvThreshold( )
? If not then what is the alternative to dealing with Buffers
(containing pixel values) with openCv functions? If there is no direct method to work with buffers, then what is the indirect method to achieve this goal? What is the work around?
In short I do not want to bring the data to hard disk before doing any processing.