Archive

Archive for the ‘Vision’ Category

HOWTO: Install and use the latest FFmpeg and x264

October 5, 2011 Leave a comment

see the link: http://ubuntuforums.org/showthread.php?t=786095

add –enable-shared to ffmpeg configuration arguments

Advertisements
Categories: Linux, Vision

Tips and Tricks: A Comprehensive OpenCV Installation Troubleshooting Guide

October 2, 2011 Leave a comment

From: http://ozbots.org/opencv-install-troubleshooting/

[Revised 2011-08-29. See Change Log section for revision information.]

This guide lists solutions for problems you might encounter when installing OpenCV and its dependencies. Many of the problems are related to using webcams. This guide is a companion guide to “A Comprehensive Guide to Installing and Configuring OpenCV 2.3 on Ubuntu,” which can be found on ozbots.org.The problems are listed in the sequence that they might occur during a typical OpenCV install. If the problem is accompanied by an error message, the relevant part of the message is highlighted in yellow.

Here is a list of error messages that are addressed by this guide:

  • ERROR: libx264 not found
  • undefined reference to ‘x264_encoder_open_116′
  • libv4lconvert-priv.h:25:21: fatal error: jpeglib.h: No such file or directory
  • libv4l1.c:53:28: fatal error: linux/videodev.h: No such file or directory
  • /home/osman/src/opencv/OpenCV-2.3.0/modules/highgui/src/cap_ffmpeg_impl.hpp:492:13: error: ‘CODEC_TYPE_VIDEO’ was not declared in this scope
  • libv4lconvert: warning more framesizes then I can handle!
  • [swscaler @ 0x89c3e30]No accelerated colorspace conversion found from yuv420p to bgr24.
  • error while loading shared libraries: libopencv_core.so.2.3: cannot open shared object file: No such file or directory
  • VIDIOC_DQBUF: Input/output error
  • VIDIOC_QUERYMENU: Invalid argument

 

Problems Building ffmpeg

Problem
<84> .../ffmpeg$ ./configure --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-nonfree --enable-postproc --enable-version3 --enable-x11grab
ERROR: libx264 not found

Solution
Use ffmpeg version 0.7.x. This error occurs if you configure ffmpeg version 0.6.x with the options shown above.

 

Problem
<84> .../ffmpeg$ make
LD ffmpeg_g
libavcodec/libavcodec.a(libx264.o): In function `X264_init':
/home/osman/src/ffmpeg/ffmpeg-0.7.3/libavcodec/libx264.c:395: undefined reference to 'x264_encoder_open_116'
collect2: ld returned 1 exit status
make: *** [ffmpeg_g] Error 1
Solution
Rebuild x264 and ffmpeg with the shared library option. To rebuild x264, change to the directory where you untared the x264 source files, and enter the following commands:
./configure --enable-shared --enable-pic
make
sudo make install

To rebuild ffmpeg, change to the directory where you untared the ffmpeg source files, and enter the following commands:

./configure --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-nonfree --enable-postproc --enable-version3 --enable-x11grab --enable-shared
make
sudo make install

This solution comes from http://www.linuxquestions.org/questions/linux-newbie-8/problem-with-enable-libx264-option-in-ffmpeg-822156/page2.html.

 

Problems Building v4l

Problem
<37> .../v4l-utils-0.8.4 $ make
make -C lib all
make[1]: Entering directory `/home/osman/src/v4l/v4l-utils-0.8.4/lib'
make -C libv4lconvert all
make[2]: Entering directory `/home/osman/src/v4l/v4l-utils-0.8.4/lib/libv4lconvert'
cc -Wp,-MMD,"libv4lconvert.d",-MQ,"libv4lconvert.o",-MP -c -I../include -fvisibility=hidden -fPIC -DLIBDIR=\"/usr/local/lib\" -DLIBSUBDIR=\"libv4l\" -I../../include -I../../lib/include -D_GNU_SOURCE -DV4L_UTILS_VERSION='"0.8.4"' -g -O1 -Wall -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -o libv4lconvert.o libv4lconvert.c
In file included from libv4lconvert.c:26:0:
libv4lconvert-priv.h:25:21: fatal error: jpeglib.h: No such file or directory compilation terminated.
make[2]: *** [libv4lconvert.o] Error 1
Solution
Install libjpeg. See “A Comprehensive Guide to Installing and Configuring OpenCV 2.3 on Ubuntu.”

 

Problem
<37> .../v4l-utils-0.8.4 $ make
...
cc -Wp,-MMD,"libv4l1.d",-MQ,"libv4l1.o",-MP -c -I../include -fvisibility=hidden -fPIC -I../../include -D_GNU_SOURCE -g -O1 -Wall -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -o libv4l1.o libv4l1.c
libv4l1.c:53:28: fatal error: linux/videodev.h: No such file or directory
compilation terminated.
make[2]: *** [libv4l1.o] Error 1

Solution
Use v4l-utils-0.8.4 or later. This problem occurs when trying to compile an old version of v4l in Ubuntu 11.x. I have not seen this problem on Ubuntu 10.x.

 

Problems Building OpenCV

Problem
Make fails at around 30% with an error building cap_ffmeg.o. This error might look like this:
[ 29%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_ffmpeg.o
In file included from /home/osman/src/opencv/OpenCV-2.3.0/modules/highgui/src/cap_ffmpeg.cpp:45:0:
/home/osman/src/opencv/OpenCV-2.3.0/modules/highgui/src/cap_ffmpeg_impl.hpp: In member function ‘bool CvCapture_FFMPEG::reopen()’:

/home/osman/src/opencv/OpenCV-2.3.0/modules/highgui/src/cap_ffmpeg_impl.hpp:492:13: error: ‘CODEC_TYPE_VIDEO’ was not declared in this scope
...
/home/osman/src/opencv/OpenCV-2.3.0/modules/highgui/src/cap_ffmpeg_impl.hpp:828:10: error: ‘AVERROR_NUMEXPECTED’ was not declared in this scope
/home/osman/src/opencv/OpenCV-2.3.0/modules/highgui/src/cap_ffmpeg_impl.hpp:832:10: error: ‘AVERROR_NOFMT’ was not declared in this scope
/home/osman/src/opencv/OpenCV-2.3.0/modules/highgui/src/cap_ffmpeg_impl.hpp:834:10: error: ‘AVERROR_IO’ was not declared in this scope
/home/osman/src/opencv/OpenCV-2.3.0/modules/highgui/src/cap_ffmpeg_impl.hpp:836:10: error: ‘AVERROR_NOMEM’ was not declared in this scope

Solution
Install ffmpeg version 0.7.x. You are probably have version 0.8.x installed, which is not compatible with OpenCV 2.3.

 

Problems running a program using OpenCV libraries

Problem
$ ./my_webcam_program
libv4lconvert: warning more framesizes then I can handle!

Solution
Install v4l version 0.8.4 or later, and then run sudo ldconfig. Rerun your program; the message should go away. Note: I don’t really know in what version of v4l this was fixed, but I do know that it is fixed in version 0.8.4.

 

Problem
$ ./my_webcam_program
[swscaler @ 0x89c3e30]No accelerated colorspace conversion found from yuv420p to bgr24.
[swscaler @ 0x8893810]No accelerated colorspace conversion found from yuv420p to bgr24.
[swscaler @ 0x889c5b0]No accelerated colorspace conversion found from yuv420p to bgr24.
Last message repeated 1 times

Solution
The “accepted” solution is to rebuild x264 and ffmpeg with the shared library option. To rebuild x264, change to the directory where you untared the x264 source files, and enter the following commands:
./configure --enable-shared --enable-pic
make
sudo make install

To rebuild ffmpeg, change to the directory where you untared the ffmpeg source files, and enter the following commands:./configure --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-nonfree --enable-postproc --enable-version3 --enable-x11grab --enable-shared
make
sudo make install

After rebuilding x264 and ffmpeg, you do not need to rebuild OpenCV. If the swscaler message still occurs when you run your program, run sudo ldconfig, and run your program again.

This solution comes from the following thread on ubuntuforums.org: http://ubuntuforums.org/showthread.php?t=1471616

Unfortunately for me, configuring and recompiling x264 and ffmpeg does not make the warning meesage go away. If try the solution above, please let me know in the comments if it works for you.

 

Problem
$ ./my_webcam_program
error while loading shared libraries: libopencv_core.so.2.3: cannot open shared object file: No such file or directory

Solutions (choose one)
1. Complete the “Configure Linux” step of the guide “A Comprehensive Guide to Installing and Configuring OpenCV 2.3 on Ubuntu.”
2. Set your LD_LIBRARY_PATHenvironment variable, as shown in the following example:export LD_LIBRARY_PATH=/usr/local/libReplace /usr/local/lib with the path where the OpenCV libraries are installed on your system.

 

Problem
VIDIOC_DQBUF: Input/output error
libv4l2: error converting / decoding frame data: v4l-convert: libjpeg error: Start Of Frame 0xc0: width=640, height=480, components=175
VIDIOC_DQBUF: Input/output error
libv4l2: error converting / decoding frame data: v4l-convert: libjpeg error: End Of Image

Solution
Make sure that your webcam is connected to a high-speed USB 2.0 port. I have seen this problem occur when my webcam was connected to a slower full-speed USB port.

 

Problem
<19> .../test1 $ ./my_webcam_program
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument

Solution
I have not found a solution to this problem. If you know a solution, please let me know! The message is coming from v4l. The message occurs when a webcam is initialized. I think that my webcam, a Logitech C910, does not conform to the UVC specification, and v4l has trouble querying the parameters of the webcam. I can still get frames from the webcam, so I just ignore the message.

 

Change Log

  • 2011-08-29 Added solution for ffmpeg make error undefined reference to 'x264_encoder_open_116'
Categories: Linux, Vision

Ubuntu下安装OpenCV需要的包

September 26, 2011 Leave a comment

sudo apt-get install build-essential cmake pkg-config libpng12-0 libpng12-dev \
libpng3 libpnglite-dev libpngwriter0-dev libpngwriter0c2 \
zlib1g-dbg zlib1g zlib1g-dev libjasper-dev \
libjasper1 pngtools libtiff4 libtiffxx0c2 \
libjpeg8 libjpeg8-dev libjpeg8-dbg libjpeg-progs ffmpeg \
libavcodec-dev libavcodec52 libavformat52 libavformat-dev \
libgstreamer0.10-0-dbg libgstreamer0.10-0 \
libxine1-ffmpeg libxine-dev libxine1-bin \
libdc1394-22-dev libdc1394-22 libdc1394-utils \
swig libv4l-0 libunicap2 libunicap2-dev \
libgstreamer0.10-dev libtiff-tools \
libjasper-runtime libv4l-dev python-numpy \
libpython2.6 python-dev \
libgtk2.0-dev libpng12-dev  libjpeg62-dev  libtiff4-dev zlib1g-dev libjasper-dev libavcodec-dev libdc1394-22-dev \
libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libavformat-dev libv4l-dev libswscale-dev SWIG

Categories: Linux, Vision

Linux下Matlab使用Mex调用OpenCV库函数

June 17, 2011 Leave a comment

唉,用CPP+OpenCV2.2写代码,想调到Matlab下方便调参数和进一步分析。于是,就有了下面的工作。

mex基础就不多说了。首先,自己用mex标准写一个A.cpp函数。然后把乱七八糟的*.h, *.cpp都放到同一个目录下。

Matlab中输入mex -v可以看到一个FILE=xxx/mexopts.sh的文件,直接右击该地址,打开即可修改mex的Makefile文件。

我的机器是32位Linux,于是找到glnx86,里面加上
CXXFLAGS=”$CXXFLAGS -I /usr/local/include/opencv”
CXXFLAGS -L /usr/loca/lib”
CXXLIBS=”$CXXLIBS -lopencv_core -lopencv_imgproc -lopencv_calib3d -lopencv_video -lopencv_features2d -lopencv_ml -lopencv_highgui -lopencv_objdetect -lopencv_contrib -lopencv_legacy”

接下来,mex A.cpp *.cpp即可编译成功!

只是,运行A时发现两个错误:

  1. `GLIBCXX_3.4.11′ not found opencv
    这是因为Matlab目录下自带libstdc++.so的问题,将其软链接到/usr/lib/libstdc++.so.6.0.13即可。
  2. Undefined symbol: _ZN8QMapData10createDataEi.
    这是由于在编译安装OpenCV2.2时选择了With_QT,重新编译安装OpenCV,将With_QT关掉,即可解决。

于是,就可以欢快地在Matlab里面使用mex调用OpenCV2.2了。

 

 

Categories: Vision

Linux下GCC配制安装OpenCV2.2

June 17, 2011 Leave a comment

现在都在Ubuntu下面工作了,于是必须得装个OpenCV才行。Intel OpenCV 2.2 是目前的最新版。

  1. 下载OpenCV 2.2,地址http://www.opencv.org.cn/download/OpenCV-2.2.0.tar.
  2. 安装cmake
    sudo apt-get install cmake
    sudo apt-get install cmake-qt-gui
  3. 打开cmake
    sudo cmake-gui
    其中,Browse Source对应源码文件夹,Browse Build对应OpenCV-build文件夹。点configure,再点Generate就可以了。
  4. 进入OpenCV-build,运行sudo make
  5. 安装,输入sudo make install

这样就完成了!

Categories: Linux, Vision

Ubuntu缺少libstdc++-libc6.1-1.so.2

June 16, 2011 Leave a comment

这几天在用feret数据集。运行里面的文件发现缺少libstdc++-libc6.1-1.so.2。libstdc++-libc需要手动下载deb包安装。下载地址是http://packages.ubuntu.com/dapper/i386/libstdc++2.10-glibc2.2/download

但是,安装后在/usr/lib/里只有libstdc++-libc6.2-2.so.3。只有做链接:
sudo ln -s /usr/lib/libstdc++-libc6.2-2.so.3 /usr/lib/libstdc++-libc6.1-1.so.2

Categories: Linux, Vision