OpenCV-2.4.3 does not work with AVI files

At the end of all this can compile code but it does not open AVI files. Even the supplied example video-input-psnr-ssim.cpp of the tutorial does not work. It fails with Could not open reference video/Megamind.avi but does not say why. (Buried deep in the CMake output files there is an error complaining about ffmpeg but the cause OpenCV's problems could be something else...)

Others have reported this too.

Work around

Use ffmpeg to extract all the frames from the AVI file as single images and then read each image file into the application. Eg:
ffmpeg -i AC_Left.avi -f image2 AC_Left_%03d.ppm

Installing OpenCV-2.4.3

Down loaded OpenCV-2.4.3.tar.bz2 from

Decompress with

bunzip2 OpenCV-2.4.3.tar.bz2

Unpack with

tar xvf OpenCV-2.4.3.tar
cd OpenCV-2.4.3

Problems with CMake OpenCV-2.4.3

Old cmake gives Parse error

CMake Error: Error in cmake code at
Parse error.  Function missing ending ")".  Instead found left paren
with text "(".
OpenCV-2.4.3 refuses to work with our default cmake (cmake version 2.4-patch 6).
WARNING: This project requires version 2.8.8 of CMake.  You are running version 2.4.6.

Work around

Use newer version of cmake. I.e. replace cmake with /usr/opt/cmake/2.8.3/cmake

CMake set_target_properties called with incorrect number of arguments

CMake fails on two files in OpenCV-2.4.3 apps/haartraining/CMakeLists.txt apps/traincascade/CMakeLists.txt

These errors should be corrected before CMake is run. Alternatively (and more realistically):

Work around
Bugfixing apps/haartraining/CMakeLists.txt and apps/traincascade/CMakeLists.txt

CMake Error at apps/haartraining/CMakeLists.txt:39 (set_target_properties):
  set_target_properties called with incorrect number of arguments.

CMake Error at apps/traincascade/CMakeLists.txt:29 (set_target_properties):
  set_target_properties called with incorrect number of arguments.
can be fixed in both files by enclosing ${EXECUTABLE_OUTPUT_PATH} with a pair of double quotes (").

CMake fails to deterimine the bitness of target platform

It appears that this is a side effect of CMake having got part way through setting things up before it failed with one of the errors above. This leaves the CMake files in a mess and subsequent attempts to use CMake file with the confusing error message CMake fails to deterimine the bitness of target platform.. A solution is to extract a clean copy from OpenCV-2.4.3.tar and reapply your patches before running CMake.

Configuring OpenCV-2.4.3

The idea here is to get local copy of OpenCV running, not to install it on top of the operating system.
/usr/opt/cmake/2.8.3/bin/cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/cs/research/crest/projects1/ucacbbl/OpenCV-2.4.3/install/ /cs/research/crest/projects1/ucacbbl/OpenCV-2.4.3/

Compiling OpenCV-2.4.3


Compiling freak.cpp with gcc version 4.1.2 fails

/cs/research/crest/projects1/ucacbbl/OpenCV-2.4.3/modules/features2d/src/freak.cpp:437: error: unable to find a register to spill in class GENERAL_REGS
/cs/research/crest/projects1/ucacbbl/OpenCV-2.4.3/modules/features2d/src/freak.cpp:437: error: this is the insn:
(insn:HI 1685 1684 1686 131 (parallel [
            (set (subreg:DI (reg:V16QI 21 xmm0 [848]) 0)
                (ior:DI (reg:DI 1 dx [832])
                    (reg:DI 4 si [839])))
            (clobber (reg:CC 17 flags))
        ]) 315 {*iordi_1_rex64} (insn_list:REG_DEP_TRUE 1660 (insn_list:REG_DEP_TRUE 1659 (nil)))
    (expr_list:REG_UNUSED (reg:CC 17 flags)
        (expr_list:REG_UNUSED (reg:CC 17 flags)
            (expr_list:REG_DEAD (reg:DI 4 si [839])
                (expr_list:REG_DEAD (reg:DI 1 dx [832])
This bug has been reported in
  Being unable to find a register to spill appears to be a problem with some versions of gcc (bugzilla 35135).

Work around

Compile freak.cpp without optimisation. I.e. remove -O3 from the command line used by make to try and compile freak.cpp and run it by hand. (NB. running it from the correct directory.) Once freak.cpp has been compiled, make will detect this and not try to compile it again. (Remember to restore the correct working directory before invoking make a second time)

W.B.Langdon Back 3 December 2012 (last update 4 Dec)