opencv videocapture on beaglebone black

270 views
Skip to first unread message

joelk

unread,
Feb 17, 2016, 7:29:50 PM2/17/16
to BeagleBoard
Has anybody managed to capture video from a usb webcam on a BBB with any recent Linux distribution using OpenCV cv::VideoCapture functions?

I'm using a Logitech C615 which works perfectly with OpenCV on x86 PCs and on a Raspberry Pi 2 (a little slow but it works) running the latest Raspbian Jessie image.

But I haven't yet managed to get anything but completely black images running the same program on my BBB.  I've tried it with a recent Arch Linux image.  I've tried Ubuntu 14.04, Debian 7.9 and 8.3 (with a few different kernels) from BeagleBoard.  Nothing!  No problems doing anything else in OpenCV -- it can load and display individual images and videos from files, just not from the camera.  And in all of these installations I can capture video from the camera with other programs (using v4l2) -- just not with OpenCV.

I've seen Derek Molloy's videos demonstrating use of OpenCV on a BBB -- but he was running it under Angstrom, and as far as I can see the last Angstrom distro was at least 3 years ago.

Any suggestions for something more recent?

By the way, here's a sample of a program that's fails to capture any video on the BBB (it displays the frame size and then just gives a series of "select timeout" messages):


#include <iostream>
#include <opencv2/highgui/highgui.hpp>

int main(int argc, char *argv[]) {
  cv::VideoCapture cap;

  cap.open(0);

  if(!cap.isOpened()) {
    std::cout << "Did not connect to camera."  << std::endl;;
    return -1;
  }

  double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH);
  double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT);

  std::cout << "Frame size: " << dWidth << " x " << dHeight << std::endl;
  cv::namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); 

  while(1) {
    cv::Mat frame;
    bool bSuccess = cap.read(frame);
    if(!bSuccess) {
      std::cout << "failed to read frame" << std::endl;
      break;
    }
    cv::imshow("MyVideo", frame);
    if(cv::waitKey(30) >= 0) break;
  }
   
  return 0;
}

Can't get much simpler than that.

joelk

unread,
Feb 17, 2016, 9:42:39 PM2/17/16
to BeagleBoard
Sorry, that wasn't 100% accurate.  When I run that program on the BBB (over ssh from a PC in my lan), it writes the frame size to stdout, then after 10-15 seconds it opens a gray window (sometimes the window immediately opens to the correct size, sometimes opens a tiny window that grows to the correct size after a few seconds), then about 5 seconds later it displays the entirely black frame in that window.  I've left it open for a few minutes, it remains black.  Now, after I click on that window to raise it, hitting any key should cause the program to quit.  But I have to keep hitting keys repeatedly for about a minute before that happens.

joelk

unread,
Feb 17, 2016, 10:19:30 PM2/17/16
to BeagleBoard
I should also mention that I'm currently running the lxqt jessie image with linux-image-4.1.17-ti-r48.  I get the same results with 4.1.17-bone19 and 4.1.15-ti-r43.

I can't use the rt kernels because those make /dev/video0 even more unstable -- frequently can't open the camera at all and can't do a soft reboot.

Wally Bkg

unread,
Feb 25, 2016, 10:18:58 AM2/25/16
to BeagleBoard
I went through this a few months ago and got nowhere.  The problem seems to be in the uvc driver.  To troubleshoot outside of openCV I installed v4l-utils fswebcam gpicview guvcview and permuted available kernels and never could get image capture to work for more than one frame.  I posted a thread about it here at the time.  I gave up and got another RPi2 for this project instead.  I did have success with  Derek Molloy's examples on the old Angstrom image, but Angstrom is too old and has been abandoned, so I didn't want to use it. 

thatg...@gmail.com

unread,
Jan 3, 2019, 8:33:36 PM1/3/19
to BeagleBoard
It anyone else stumbles on this the solution is:

sudo rmmod uvcvideo && sudo modprobe uvcvideo nodrop=1 timeout=5000
Reply all
Reply to author
Forward
0 new messages