开发者

Opencv: image, retrieved from camera capture is always gray

开发者 https://www.devze.com 2023-04-09 19:03 出处:网络
I am always getting a grey screen when showing image using opencv, the image is captured from camera.

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 anothe开发者_如何学编程r 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.


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);


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; 
}




 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号