Difference between revisions of "Tutorial Videos and Webcams"

From BoofCV
Jump to navigationJump to search
(Created video page)
 
Line 3: Line 3:
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 image widgets but uses Swing instead.  The same philosophy applies to capturing images from videos and webcams.  Unfortunately the built in support that Java provides for reading videos 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 image widgets but uses Swing instead.  The same philosophy applies to capturing images from videos and webcams.  Unfortunately the built in support that Java provides for reading videos and webcams is very limited.


The limited support that BoofCV provides itself for reading videos directly comes in the form of MJPEG videos and image sequence.  MJPEG is a very simple video format that encapsulates a sequence of video images.  MJPEG is not the most efficient format, but it is very easy to read and write.  Its inclusion into BoofCV is primarily to provide video support to applets.  An image sequence contained in a directly can also be read as if it was a video.
The limited built in support that BoofCV provides itself for reading videos directly comes in the form of MJPEG videos and image sequence.  MJPEG is a very simple video format that encapsulates a sequence of video images.  MJPEG is not the most efficient format, but it is very easy to read and write.  Its inclusion into BoofCV is primarily to provide video support to applets.  An image sequence contained in a directly can also be read as if it was a video.


Third party libraries are required for reading webcams. Better support for integrating 3rd party libraries is still being worked onThere are currently no plans for providing support out of the boxThe reason for this is that these 3rd party libraries often require compiling native code and configuring Java to reference the native libraries.  Integrating such libraries into BoofCV by default would greatly increase its complexity.  
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' directoryCurrently wrappers are only provided for XugglerLibraries which are not 'supported' can still be used easily with BoofCV, you just need to provide the routines to convert the images.


== Quick and Dirty ==
== Converting to MJPEG ==


As previously mentioned BoofCV has only very limited support for videos.  Let's say that you want to play your own video in one of BoofCV's examplesBecause BoofCV by default only support MJPEG you need to convert your file into an MJPEG.  This can be done by converting it into a sequence of jpeg images and then using the CreateMJpeg in BoofCV to create the MJPEG or using ffmpeg.  
To read a video and not mess with third party libraries the easiest way to do so is convert the video to MJPEGThe easiest way in Linux to create an MJPEG from some other video format is using ffmpegBelow is a command line example. 
<pre>
ffmpeg -i FILENAME -sameq example.mjpeg
</pre>
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.


The easiest way in Linux to create an MJPEG from some other video format is using ffmpegBelow is a command line example.   
== Xuggler Integration ==
 
Xuggler support is still being worked on to make the API easier to deal withTo read a video file as a SimpleImageSequence use XugglerSimplifiedFor example:
<pre>
<pre>
ffmpeg -i FILENAME -sameq example.mjpeg
SimpleImageSequence<ImageFloat32> videoLeft =
  new XugglerSimplified<ImageFloat32>("FileName.avi", ImageFloat32.class);
</pre>
</pre>
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 comon.


== Third Party Options ==
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'.
 
See also integration JavaDoc
* [http://boofcv.org/javadoc/integration/ JavaDoc]
 
= 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.
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.
Line 26: Line 37:
** http://www.oracle.com/technetwork/java/javase/tech/index-jsp-140239.html
** http://www.oracle.com/technetwork/java/javase/tech/index-jsp-140239.html
** Provided by Oracle and supports a few formats.  Known for being old and poorly supported.
** Provided by Oracle and supports a few formats.  Known for being old and poorly supported.
* Xuggler
** http://www.xuggle.com/xuggler/
** Wrapper around several native libraries.
** Not as well supported as it used to be.
** Ignore the ancient stable release and checkout the SVN code.
** SVN code is occasionally broken from my experience.


'''Webcams'''
'''Webcams'''
Line 38: Line 43:
** http://code.google.com/p/v4l4j/
** http://code.google.com/p/v4l4j/
** I have had good success with it in the past
** I have had good success with it in the past
* Xuggler
** http://www.xuggle.com/xuggler/
** Never used its webcam capabilities, but I believe it says it supports them.


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.
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.

Revision as of 15:56, 22 July 2012

Videos and Webcams in BoofCV

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 image widgets but uses Swing instead. The same philosophy applies to capturing images from videos and webcams. Unfortunately the built in support that Java provides for reading videos and webcams is very limited.

The limited built in support that BoofCV provides itself for reading videos directly comes in the form of MJPEG videos and image sequence. MJPEG is a very simple video format that encapsulates a sequence of video images. MJPEG is not the most efficient format, but it is very easy to read and write. Its inclusion into BoofCV is primarily to provide video support to applets. An image sequence contained in a directly can also be read as if it was a video.

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. Currently wrappers are only provided for Xuggler. Libraries which are not 'supported' can still be used easily with BoofCV, you just need to provide the routines to convert the images.

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.

Xuggler Integration

Xuggler support is still being worked on to make the API easier to deal with. To read a video file as a SimpleImageSequence use XugglerSimplified. For example:

SimpleImageSequence<ImageFloat32> videoLeft =
   new XugglerSimplified<ImageFloat32>("FileName.avi", ImageFloat32.class);

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'.

See also integration JavaDoc

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.

Video Libraries

Webcams

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.