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 Pi stops responding to the keyboard and the mouse, and the only way to quit is to unplug the 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);
    fprintf(stderr, "Error: capture is NULL \n");
    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


    //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);
  return 0;

} //end main

Is there a problem with my code? Do I need to use a different webcam? I've overclocked the Pi; can it simply not handle the stream with a better-quality camera?

  • Is 256x192 a natural resolution for the camera or does opencv have to scale or crop it from something else.
    – NomadMaker
    May 12, 2018 at 17:14

1 Answer 1


Have you tried:


rmmod uvcvideo

modprobe uvcvideo nodrop=1 timeout=5000 quirks=0x80

Also try to remove all "auto" settings through guvcview

It worked perfectly for me. It has been running för 24 hours straight with a steady 15fps @ 320x240.

Please check this for details.


  • I haven't tried this yet - I'll give it a try. Thanks very much!
    – crypto
    Apr 8, 2013 at 0:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.