I suggest you gentlemen invent a way to put a square peg in a round hole.

In which we optimize OpenCV on the BeagleBone Black.

If you have been paying attention to the BBB group on Google Groups, you may have discovered a lively thread on webcams [1]. As part of this thread, I have been working with Michael Darling to realize the best performance possible when using OpenCV to process an MJPG stream from a webcam on the BBB.  OpenCV relies on libjpeg when loading the MJPG frames to OpenCV Mats, and libjpeg is not the fastest of jpeg libraries.  However, there is another option - libjpeg-turbo [2].

While it is technically possible to compile OpenCV with libjpeg-turbo support on the BBB, you will have fewer issues and spend less time compiling if you use a cross compiler on a more powerful computer.  Michael has written a guide to cross compiling OpenCV.  Below you will find the guide as a webpage for online viewing or a pdf for download as well as the latest code to capture frames from a webcam and convert them to OpenCV Mats.  The guide is currently a draft, and we would appreciate any feedback you can provide.  Many thanks to Michael for taking the time to write this up.

Note: The code in the guide and the latest code are slightly different.

  1. -o is used to indicate which frames to convert to OpenCV Mats and requires an integer argument.
        -o 1 will convert every frame
        -o 2 will convert every 2nd (ever other) frame, and so on.
        The default is 1.
  2. -p is similar to -o in the original framegrabber.  However, it doesn't actually output anything.  It just controls if any frames are to be converted.
  3. Captured count and processed count variables have been renamed and moved to the top.
  4. Formatting has been corrected.
  5. Setting of the Mat size now uses the width and height variables.

 

The guide will be updated to reflect these changes in a future release, but in the meantime, you will need to adjust the command line arguments specified in the guide, namely replace -o with -p.

Guide [DRAFT]
    BBB_30fps.html
    BBB_30fps.pdf (204.32 kb)
Code
    framegrabberCV.c (19.77 kb)

[1] problems with webcams
[2] libjpeg-turbo

Comments (3) -

  • Ricardo

    10/9/2013 11:10:51 AM | Reply

    I have the following errors while compiling your test code...

    g++: error: ‘pkg-config: No such file or directory
    g++: error: unrecognized command line option ‘--cflags’
    g++: error: unrecognized command line option ‘--opencv’
    g++: error: opencv: No such file or directory
    g++: error: libv4l2‘: No such file or directory

    I've trying to make this works for days, and i don't know where to go now. I'm using a logitech c270 and a BBB. I didn't have success trying the cross-compiling so i did it at the BBB, can this be the reason?

    I'm following exact what the tutorial is saying except for the cross-compiling part. What may i'm doing wrong?

    Thanks!

    • Lemoneer

      10/10/2013 3:17:05 AM | Reply

      Are you having trouble compiling OpenCV, libturbo-jpeg, or the test application?  Do you have pkg-config and OpenCV installed?  Also, what distro are you using?

      You should also be aware of an issue with the C270; I have been told the C270 does not generate complete jpegs when capturing using MJPG.  You will need to inject the Huffman table before loading the frame into an OpenCV Mat.  I have written a demo application in Python to demonstrate this blog.lemoneerlabs.com/...09%2fMJPEGpatcher.py.axdx

  • Zoroastro

    10/10/2013 5:23:27 AM | Reply

    Hi, I have had a brand new Ubuntu 13.04 installed from the images suggested by you on the draft and I have followed all the instructions also.
    When I try to compile OpenCV it show negative (NO) for FFMPEG.
    Do I need to install any libraries prior to this compilation or the Ubuntu image suggested has it all?

    Thank you.
    Zoroastro.

Loading