Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ OpenCV
Hi,
 
I can not capture image from my webcam using following OpenCV code.
 
The code can show images from a local AVI file or a video device. It works fine on a "test.avi" file.
 
When I make use my default webcam(CvCapture* capture =cvCreateCameraCapture(0)), the program can detected the size of the image from webcam,but just unable to display the image.
 
Anyone encounter the same problem?
 
You can also see my post here with figures
 

 
<pre lang="cs">
 
//code start
cvNamedWindow( "Example2", CV_WINDOW_AUTOSIZE );
    CvCapture* capture =cvCreateFileCapture( "C:\\test.avi" );// show images from avi file, works well
//    CvCapture* capture =cvCreateCameraCapture(0);           //show the frame(images) from default webcam not work
 
    assert( capture );
 
    IplImage* image;
      while(1) {
    image = cvQueryFrame( capture );
         if( !image ) break;
          cvShowImage( "Example2", image );
        char c = cvWaitKey(33);
        if( c == 27 ) break;
    }
    cvReleaseCapture( &capture );
    cvDestroyWindow( "Example2" );
 

opencv 2.2
Debug library *d.lib
WebCam isight
Macbook OS win7 32
VS2008
Posted 11-Jan-11 3:30am
Du Sijun1.1K
Edited 14-Nov-12 1:12am
Legor5.2K
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Latest update! Problem solved!
 
This happen to be one of OpenCV 2.2′s bug
 
In
$(OpenCV Folder)\modules\highgui\src\precomp.hpp around line 60+ replace following
 
#if !defined WIN32 && !defined _WIN32
#include “cvconfig.h”
#else
void FillBitmapInfo( BITMAPINFO* bmi, int width, int height, int bpp, int origin );
#endif
 
with
 

#include “cvconfig.h”
#if defined WIN32 || defined _WIN32
void FillBitmapInfo( BITMAPINFO* bmi, int width, int height, int bpp, int origin );
#endif
 
More info:
 
http://dusijun.wordpress.com/2011/01/11/opencv-unable-to-capture-image-from-isight-webcam/[^]
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try CvCapture* capture =cvCreateCameraCapture(-1);
 
Regards
Espen Harlinn
  Permalink  
Comments
startstarts at 11-Jan-11 9:52am
   
thanks, same as before
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

I'm working on opencv 2.3 with Macbook pro Mid 2012 and I had that problem with the Isight cam. Somehow I managed to make it work on opencv by simply adjusting the parameters of the Cvcapture and adjusting the frame width and height:
 
CvCapture* capture = cvCaptureFromCAM(0);
cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH, 500 );
cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT, 600 );
 
You can also change these numbers to the frame width and height you want.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 375
1 _Amy 235
2 Andreas Gieriet 180
3 Peter Leow 175
4 Dave Kreskowiak 155
0 OriginalGriff 7,540
1 Sergey Alexandrovich Kryukov 6,462
2 Maciej Los 3,849
3 Peter Leow 3,653
4 CHill60 2,712


Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 14 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100