Difference between revisions of "Tutorial Videos and Webcams"

From BoofCV
Jump to navigationJump to search
m
m
Line 1: Line 1:
BoofCV focuses on image processing and computer vision algorithms and for the most part relies on other libraries for input and output.  For example, BoofCV does not define GUI widgets but uses Swing instead.  The same philosophy applies to capturing images from videos and webcams.  Unfortunately the built in support in Java for read video files and webcams is very limited.
BoofCV focuses on image processing and computer vision algorithms and for the most part relies on other libraries for input and output.  For example, BoofCV does not define GUI widgets but uses Swing instead.  The same philosophy applies to capturing images from videos and webcams.  Unfortunately the built in support in Java for reading videos and webcams is very limited.


The only video format which BoofCV natively supports is MJPEG and image sequence.  MJPEG is a very simple video format that is for the most part a series of JPEG images concatenated together.  MJPEG's inclusion in BoofCV is primarily to provide video support in applets.  Support is also provided for reading image sequences from directories.
The only video format which BoofCV natively supports is MJPEG and image sequence.  MJPEG is a very simple video format that is for the most part a series of JPEG images concatenated together.  MJPEG's inclusion in BoofCV was primarily to provide video support in applets.  Support is also provided for reading image sequences from directories.


Third party libraries are required for reading webcams or other video formats.  Support for these third party libraries can be found in the 'boofcv/integration' directory.  Of most interest to people are the wrappers for Xuggler and Webcam Capture, which is used to read video files and webcams, respectively.   Libraries which are not 'supported' can still be used easily with BoofCVYou just need to convert the output image (typically a BufferedImage) into a BoofCV style image.
Third party libraries are required for webcams and reading video formats.  Support for these third party libraries can be found in the 'boofcv/integration' directory.  Of most interest to people are the wrappers for [https://github.com/lessthanoptimal/BoofCV/tree/master/integration/javacv JavaCV] and [https://github.com/lessthanoptimal/BoofCV/tree/master/integration/WebcamCapture Webcam Capture].  JavaCV provides a wrapper around [https://ffmpeg.org/ FFMPEG]Webcam Capture wraps several different webcam libraries into a simple interface, see their [http://webcam-capture.sarxos.pl/ website] for details.


== Converting to MJPEG ==
== Converting to MJPEG ==
Line 14: Line 14:


== Video ==
== Video ==
Xuggler is used to provide support for reading video files.  It's still being worked on to make the API easier to deal withTo read a video using the SimpleImageSequence interface use XugglerSimplified. For example:
The easiest way to use Video in BoofCV is to use the default media manager.  It checks your class path to see what you have installed and will use the best option available.  SimpleImageSequence is an interface that provides an easy to use and common interface for different image streams.
 
<pre>
<pre>
SimpleImageSequence<GrayF32> videoLeft =
MediaManager media = DefaultMediaManager.INSTANCE;
  new XugglerSimplified<GrayF32>("FileName.avi", ImageFloat32.class);
SimpleImageSequence<Planar<GrayU8>> video = media.openVideo(fileName, ImageType.pl(3,GrayU8.class);
 
while( video.hasNext() ) {
  Planar<GrayU8> input = video.next();
  ... process ...
}
</pre>
</pre>
Be sure to correctly setup all the classpaths for Xugger and to include the BoofCVXuggler.jar in your classpath.  BoofCVXuggler.jar can be downloaded online or compiled yourself using ant scripts provided in 'boofcv/integration/xuggler'.


The following is a list of alternatives:
The following is a list of alternatives:
* Xuggler used supported but after a long protracted death is no longer available
* Java Media Framework (JMF)
* Java Media Framework (JMF)
** http://www.oracle.com/technetwork/java/javase/tech/index-jsp-140239.html
** http://www.oracle.com/technetwork/java/javase/tech/index-jsp-140239.html
Line 34: Line 39:


Support is also provided for [http://code.google.com/p/v4l4j/ Video for Linux for Java (V4L4J)], but it is more difficult to use and is Linux only.
Support is also provided for [http://code.google.com/p/v4l4j/ Video for Linux for Java (V4L4J)], but it is more difficult to use and is Linux only.
== Bumblebee2 Stereo Camera in Linux ==
I also wrote a Java wrapper for Bumblebee2 stereo cameras which does not rely on any code from PtGrey, which in the past has had poor support for Linux.  You can checkout the source code from github using the link below:
https://github.com/lessthanoptimal/JBumblebee


= Other Options =
= Other Options =

Revision as of 18:08, 3 January 2017

BoofCV focuses on image processing and computer vision algorithms and for the most part relies on other libraries for input and output. For example, BoofCV does not define GUI widgets but uses Swing instead. The same philosophy applies to capturing images from videos and webcams. Unfortunately the built in support in Java for reading videos and webcams is very limited.

The only video format which BoofCV natively supports is MJPEG and image sequence. MJPEG is a very simple video format that is for the most part a series of JPEG images concatenated together. MJPEG's inclusion in BoofCV was primarily to provide video support in applets. Support is also provided for reading image sequences from directories.

Third party libraries are required for webcams and reading video formats. Support for these third party libraries can be found in the 'boofcv/integration' directory. Of most interest to people are the wrappers for JavaCV and Webcam Capture. JavaCV provides a wrapper around FFMPEG. Webcam Capture wraps several different webcam libraries into a simple interface, see their website for details.

Converting to MJPEG

To read a video and not mess with third party libraries the easiest way to do so is convert the video to MJPEG. The easiest way in Linux to create an MJPEG from some other video format is using ffmpeg. Below is a command line example.

ffmpeg -i FILENAME -sameq example.mjpeg

Other flags can be added to resize the image or adjust image quality. There are a few videos where ffmpeg will produce an MJPEG which BoofCV cannot read, but this is not common.

Video

The easiest way to use Video in BoofCV is to use the default media manager. It checks your class path to see what you have installed and will use the best option available. SimpleImageSequence is an interface that provides an easy to use and common interface for different image streams.

MediaManager media = DefaultMediaManager.INSTANCE;
SimpleImageSequence<Planar<GrayU8>> video = media.openVideo(fileName, ImageType.pl(3,GrayU8.class);

while( video.hasNext() ) {
  Planar<GrayU8> input = video.next();
  ... process ...
}

The following is a list of alternatives:

Webcams

The recommended way to use webcams with BoofCV is with Webcam Capture. Webcam Capture is very easy to use and works out of the box on Linux, Windows, and MacOS. The BoofCV integration package only provides a single function for opening up a camera at a resolution as close to the one you requested as possible.

Webcam Capture Example

Support is also provided for Video for Linux for Java (V4L4J), but it is more difficult to use and is Linux only.

Other Options

The easiest way to integrate a 3rd party library with BoofCV is to read in a frame as a BufferedImage, then convert it into a native BoofCV image format using ConvertBufferedImage. An alternative is to write a wrapper that implements SimpleImageSequence, which is used by several examples.


If you know of some other options please post a message to BoofCV's message board (see sidebar link) letting us know about it! Especially if you have suggestions for Windows and MacOS.