Take the 2-minute tour ×
Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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.


share|improve this answer
I haven't tried this yet - I'll give it a try. Thanks very much! –  crypto Apr 8 '13 at 0:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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