2
votes

I am always getting a grey screen when showing image using opencv, the image is captured from camera.

capture = cvCaptureFromCAM(-1);
cvGrabFrame(capture);
image = cvRetrieveFrame(capture);
cvShowImage("name", image);

after this I see the grey screen, even if I do in cycle. But the same code works well on another computer. What is the problem? The same opencv library version is used on both computers. Working in the Visual Studio 2010, C++ Opencv version 2.2.0

EDIT 1: The camera used in both computers is the same. And I have tried to rebuild the opencv on the computer where the problem happens, it didn't help.

2
You should try with device index = 0, just an idea..Adrian
Tried it, didn't help. Actually the camera is working I see the blue light indicator on it is turned on. The problem is somewhere in opencv I suppose.maximus
as explained here: opencv.willowgarage.com/documentation/…, when using RetrieveFrame, you first call GrabFrame. The alternative is to use the single call QueryFrame.crisbia
@crisbia Sorry, I have updated the question. Actualy I do call cvGrabFrame each time before retrieving it from camera. Just by some reason didn't put the it in the code above.maximus

2 Answers

4
votes

I had the same problem in OpenCvSharp. I don't know what's the cause, but for some reason, calling the "WaitKey" method after displaying the image solved it.

CvCapture mov = new CvCapture(filepath);
IplImage frame = mov.QueryFrame();
CvWindow win1 = new CvWindow(window name);
win1.ShowImage(frame);
CvWindow.WaitKey(1);
1
votes

Your problem sounds very weird.

Try to use cvQueryFrame instead of cvRetrieveFrame() and let me know if it does make a difference.

Here is a code of using opencv for face detection, the concept of capturing an image is very similar:

int main( int argc, const char** argv )
{
CvCapture* capture;
Mat frame;
 //-- 1. Load the cascades
if( !face_cascade.load( face_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
 if( !eyes_cascade.load( eyes_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };

 //-- 2. Read the video stream
 capture = cvCaptureFromCAM( -1 );
if( capture )
{
while( true )
{
  frame = cvQueryFrame( capture );

  //-- 3. Apply the classifier to the frame
  if( !frame.empty() )
   { detectAndDisplay( frame ); }
  else
   { printf(" --(!) No captured frame -- Break!"); break; }
  
  int c = waitKey(10);
  if( (char)c == 'c' ) { break; } 

} 
}return 0; 
}