Ask Your Question

Revision history [back]

Webcam picture only gray

Hello,

i try this Code to make a picture with my Webcam But the Picture i get is only gray . it´s only a Problem in C++ with Opencv. In VB Code ist works well. Have somewone an idea ? Thanks System: Win 10 / StudioCommunity 2015

// Webcam

include "opencv2\highgui\highgui.hpp"

include "opencv2\imgproc\imgproc.hpp"

include "opencv\cv.h"

include <stdio.h>

define XRES 1280

define YRES 720

define WINDOWNAME "openCV USB-camera"

int main(int argc, char **argv) {
// open camera:
CvCapture* capture = 0;
capture = cvCaptureFromCAM(-1);
if (!capture) {
    fprintf(stderr, "couldn't open Camera device");
    return -1;
}
// set resolution
cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, XRES);
cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, YRES);
// grab and show frames:
IplImage *frame = cvQueryFrame(capture);
cvNamedWindow(WINDOWNAME, CV_WINDOW_AUTOSIZE);
while (frame != NULL) {
    int key = cvWaitKey(10);
    if (key == 27) break; // stop when ESC is pressed
    cvShowImage(WINDOWNAME, frame);
    frame = cvQueryFrame(capture);
}
// close camera:
cvReleaseCapture(&capture);
cvDestroyWindow(WINDOWNAME);

return 0;

}

click to hide/show revision 2
No.2 Revision

updated 2016-11-06 03:09:17 -0600

berak gravatar image

Webcam picture only gray

Hello,

i try this Code to make a picture with my Webcam But the Picture i get is only gray . it´s only a Problem in C++ with Opencv. In VB Code ist works well. Have somewone an idea ? Thanks System: Win 10 / StudioCommunity 2015

// Webcam

include "opencv2\highgui\highgui.hpp"

include "opencv2\imgproc\imgproc.hpp"

include "opencv\cv.h"

include <stdio.h>

define
// Webcam

#include "opencv2\highgui\highgui.hpp"
#include "opencv2\imgproc\imgproc.hpp"
#include "opencv\cv.h"
#include <stdio.h>

#define XRES 1280

define 1280 #define YRES 720

define 720 #define WINDOWNAME "openCV USB-camera"

USB-camera"
int main(int argc, char **argv) {
 // open camera:
 CvCapture* capture = 0;
 capture = cvCaptureFromCAM(-1);
 if (!capture) {
  fprintf(stderr, "couldn't open Camera device");
 return -1;
 }
 // set resolution
 cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, XRES);
 cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, YRES);
 // grab and show frames:
 IplImage *frame = cvQueryFrame(capture);
 cvNamedWindow(WINDOWNAME, CV_WINDOW_AUTOSIZE);
 while (frame != NULL) {
 int key = cvWaitKey(10);
  if (key == 27) break; // stop when ESC is pressed
 cvShowImage(WINDOWNAME, frame);
 frame = cvQueryFrame(capture);
 }
 // close camera:
 cvReleaseCapture(&capture);
 cvDestroyWindow(WINDOWNAME);
 return 0;
}

}