Friday, November 16, 2012

Install Target on OpenCV WS2010

Explicitly Select and Build the 'INSTALL' project under OpenCV Solution would install the built binaries, libraries, headers to the directory configured by CMake. This makes building applications against it much easier.

Tuesday, June 19, 2012

Build OpenCV 2.4.1 HTML Doc on Win7-x64

From CMake-GUI 2.8:
  • Check BUILD > BUILD_DOCS option
  • Download and install MikTex Portable Package
    • Use MikTeX Package Manager to install 'latex2html'.
  • Specify Ungrouped Entries > MIKTEX_BINARY_PATH "C:\ProgramData\MikTex2.9 Portable\miktex\bin\" 
    • The rest of that associated binaries (like BIBTEX_COMPILER) will be found in that directory.
    • Math expressions will not appear correctly without latex2html; It still works even without specifying the LATEX2HTML_CONVERTER field in CMake.
  • Download and install Python and Sphinx EGG module.
  • Specify Ungrouped Entries > SPHINX_BUILD "C:\Python26\Scripts\sphinx-build.exe"
  • Download and install Ghostscript package
  • Specify GHOSTSCRIPT_BINARY_PATH and GHOSTSCRIPT_LIBRARY_PATH to where Ghostcript package is installed locally.
  • 'Configure'
  • Verify that the binaries supplied by MikTex package is picked up by CMake (such as BIBTEX_COMPILER).
  • Check that the 'Build Documentation' is YES at CMake console.
  • Check that the PdfLateX.
  • 'Generate'
Open the OpenCV.sln in VS 2010 Express
  • Select html_docs project from Solution Explorer and 'Build'.

Tuesday, April 3, 2012

Adding Ogg Video to VideoWriter

Did the following such that OpenCV could write Theora encoded Ogg Video (.ogv) in Win32 environment. Useful as it is a way to embed HTML5 video

Details of FFMPEG build and OpenCV integration is the same as previous post. Not repeating here.
  1. Setup MinGW-32 environment.
  2. Download Ogg, Vorbis and Theora from
  3. Configure and Build Ogg, Vorbis and Theora from source - in this order.
  4. Configure and Build FFMPEG-0.8.2 with --enable-libvorbis and --enable-libtheora enabled.
  5. Copy the ogg, vorbis and theora archive (.a) to OpenCV, in addition to the updated ffmpeg core libraries. Rebuild opencv_ffmpeg with the new OpenCV library.
  6. Specify codec with fourcc ('t', 'h', 'e', 'o') and output file extension .ogv in call to VideoWriter::open().


  • Fourcc for theora used in OpenCV 2.3 is 'theo' not 'ther'
  • If theora build ended with error in compiling examples, re-configure with --disable-examples flag. This avoids the error and allows the 'make install' to complete without error, thus copying pkg-config files.
  • Use --extra-cflags and --extra-ldflags to specify compile options necessary for ffmpeg to build against the vorbis and theora libraries. The flags could be looked up with pkg-config. (Use PKG_CONFIG_PATH if installed in /usr/local or other non-standard locations).
  • FFMPEG 0.8.2 build failed with error in ffplay if --disable-avfilter is specified. Patched with '0001-fix-compilation-error-when-disable-avfilters.patch' (see References)
  • The order of ogg, vorbis and theora library specified in opencv_ffmpeg build is important. Will failed with missing symbol link-time error if the common libraries are not specified last (like ogg). It is static build. This is what I used: "-lvorbisenc -lvorbisfile -ltheoraenc -ltheoradec -ltheora -lvorbis -logg"
  • Encountered ffmpeg error "Application provided invalid, non monotonically increasing dts to muxer in stream 0". This only happen when I set the output frame rate to certain values such as 5-fps, 15-fps. (Other values might fail, but didn't check). Cross-check with the ffmpeg executable built from the same source. There is no error and the following transcoding succeeded.
    $ ./ffmpeg.exe -i -an -vcodec libtheora -f ogg -b 500k -r 15 15fps.ogv
    Work-around: Noticed that there is a condition check on AVCodecContext->coded_frame->pts before calling av_rescale_q(). (ffmpeg.c line 1312.) Put the same condition to cap_ffmpeg_impl.h. Problem goes away.

Embed HTML Video

  • Apache Configuration: 'AddType' directive to make sure the .ogv is sent to the browser with the intended mime-type.
  • Uses <video> tag on HTML to embed inline video.


Saturday, January 7, 2012

Build FFMPEG for OpenCV2.3-Win32

Replacing FFMPEG (32-bit) for OpenCV 2.3 and above:


Replace opencv_ffmpeg.dll 
  • Follow instructions at opencv/3rdparty/ffmpeg/readme.txt
  • uses 'strip -g' (important to strip only debug symbols) to reduce size of ffmpeg core libraries
  • copy the difference in header file also, if any.