I have successfully installed OpenCV on my Raspberry Pi and have been fooling around with some simple webcam streaming, live canny-edge detection, and so forth, all using basic C and C++ code.
However, I'm running into problems with the two webcams I'm using. The first, a really basic, cheap Logitech I had sitting around, works fine, but the image quality leaves a LOT to be desired. But when I switch to my Logitech 510c camera, the image is much better, but the Pi freezes.
Rather, the streaming program continues to run fine, but I can't exit the program - the Raspberry Pi stops responding to the keyboard and the mouse, and the only way to quit is to unplug the Raspberry Pi. Here's an example of some of the code:
#include <cv.h>
#include <highgui.h>
#include <stdio.h>
int main(){
int c, i, j;
//Capture frame from camera
CvCapture* capture = cvCaptureFromCAM(CV_CAP_ANY);
if(!capture){
fprintf(stderr, "Error: capture is NULL \n");
getchar();
return -1;
}
//Set resolution of capture
cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 256);
cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 192);
//Create window for display
cvNamedWindow("canny");
while(true){
//Find/mark edges using canny
IplImage* frame = cvQueryFrame(capture);
IplImage* grey = cvCreateImage(cvGetSize(frame), 8, 1);
cvCvtColor(frame, grey, CV_RGB2GRAY);
IplImage* frame2 = cvCreateImage(cvSize(grey->width+6, grey->height+6), grey->depth, grey->nChannels);
CvPoint offset = cvPoint(3,3);
cvCopyMakeBorder(grey, frame2, offset, IPL_BORDER_REPLICATE, cvScalarAll(0));
IplImage* edges = cvCreateImage(cvGetSize(frame2), IPL_DEPTH_8U, frame2->nChannels);
cvCanny(frame2, edges, 4900, 39200, 7);
cvShowImage("canny", edges);
//Wait for a keypress
int c = cvWaitKey(10);
if (c!=-1)
break;
} //End while
cvReleaseCapture (&capture);
cvDestroyWindow("canny");
return 0;
} //End main
Is there a problem with my code? Do I need to use a different webcam? I've overclocked the Raspberry Pi; can it simply not handle the stream with a better-quality camera?
There are known issues with video cameras on Raspberry Pi, boiling down to the USB handling. You can try upgrading to the latest kernel, although most the fixes so far have not affected cameras.