This guide describes how to install and configure OpenCV 2.4.2 and its dependencies on Ubuntu 12.04. This guide includes instructions for both 32-bit and 64-bit systems.
Revision History:
[2012-09-12] Updated guide to work with OpenCV 2.4.2. Updated ffmpeg section: ffmpeg 0.11.1 now requires -pic option on 64-bit systems.
[2012-06-05] Updated guide to work with OpenCV 2.4.1 and Ubuntu 12.04. Added instructions for 64-bit systems.
[2011-08-11] Initial version. Worked with OpenCV 2.3.1 and Ubuntu 11.10. Archived here.
If you need help troubleshooting OpenCV installation problems, see the companion guide “A Comprehensive OpenCV Installation Troubleshooting Guide.”
The Installation Procedure
To install and configure OpenCV 2.4.1, complete the following steps. The commands shown in each step can be copy and pasted directly into a Linux command line.
- Remove any installed versions of ffmpeg and x264.
sudo apt-get remove ffmpeg x264 libx264-dev
- Get all the dependencies for x264 and ffmpeg.
sudo apt-get update
sudo apt-get install build-essential checkinstall git cmake libfaac-dev libjack-jackd2-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libsdl1.2-dev libtheora-dev libva-dev libvdpau-dev libvorbis-dev libx11-dev libxfixes-dev libxvidcore-dev texi2html yasm zlib1g-dev - Download and install gstreamer.
sudo apt-get install libgstreamer0.10-0 libgstreamer0.10-dev gstreamer0.10-tools gstreamer0.10-plugins-base libgstreamer-plugins-base0.10-dev gstreamer0.10-plugins-good gstreamer0.10-plugins-ugly gstreamer0.10-plugins-bad gstreamer0.10-ffmpeg
- Download and install gtk.
sudo apt-get install libgtk2.0-0 libgtk2.0-dev
- Download and install libjpeg.
sudo apt-get install libjpeg8 libjpeg8-dev
- Create a directory to hold source code.
cd ~
mkdir src - Download and install install x264.
- Download a recent stable snapshot of x264 from ftp://ftp.videolan.org/pub/videolan/x264/snapshots/. The exact version does not seem to matter. To write this guide, I used version x264-snapshot-20120528-2245-stable.tar.bz2, but I have used previous versions too.
cd ~/src
wget ftp://ftp.videolan.org/pub/videolan/x264/snapshots/x264-snapshot-20120528-2245-stable.tar.bz2
tar xvf x264-snapshot-20120528-2245-stable.tar.bz2
cd x264-snapshot-20120528-2245-stable
- Configure and build the x264 libraries.
./configure --enable-static
make
sudo make installIMPORTANT: If you are running a 64-bit version of Ubuntu, you must configure x264 as shown in the following command:
./configure --enable-shared --enable-pic
The -shared and -pic options might also be required when you compile for some other architectures, such as ARM. You know you need these options if you get the following error when compiling OpenCV:
[ 25%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/bitstrm.cpp.o
Linking CXX shared library ../../lib/libopencv_highgui.so
/usr/bin/ld: /usr/local/lib/libavcodec.a(avpacket.o): relocation R_X86_64_32S against `av_destruct_packet' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libavcodec.a: could not read symbols: Bad value
- Download a recent stable snapshot of x264 from ftp://ftp.videolan.org/pub/videolan/x264/snapshots/. The exact version does not seem to matter. To write this guide, I used version x264-snapshot-20120528-2245-stable.tar.bz2, but I have used previous versions too.
- Download and install install ffmpeg.
- Download ffmpeg version 0.11.1 from http://ffmpeg.org/download.html.
cd ~/src
wget http://ffmpeg.org/releases/ffmpeg-0.11.1.tar.bz2
tar xvf ffmpeg-0.11.1.tar.bz2
cd ffmpeg-0.11.1 - Configure and build 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
make
sudo make installIMPORTANT: Just like with x264 in the previous step, you must configure ffmpeg with the -shared and -pic options if you are running a 64-bit version of Ubuntu or some other architectures, such as ARM.
./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 --enable-pic
- Download ffmpeg version 0.11.1 from http://ffmpeg.org/download.html.
- Download and install install a recent version of v4l (video for linux) from http://www.linuxtv.org/downloads/v4l-utils/. For this guide I used version 0.8.8.
cd ~/src
wget http://www.linuxtv.org/downloads/v4l-utils/v4l-utils-0.8.8.tar.bz2
tar xvf v4l-utils-0.8.8.tar.bz2
cd v4l-utils-0.8.8
make
sudo make install - Download and install install OpenCV 2.4.2.
- Download OpenCV version 2.4.2 from http://sourceforge.net/projects/opencvlibrary/files/
cd ~/src
wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.2/OpenCV-2.4.2.tar.bz2
tar xvf OpenCV-2.4.2.tar.bz2
- Create a new build directory and run cmake:
cd OpenCV-2.4.2/
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE .. - Verify that the output of cmake includes the following text:
- found gstreamer-base-0.10
- GTK+ 2.x: YES
- FFMPEG: YES
- GStreamer: YES
- V4L/V4L2: Using libv4l
- Build and install OpenCV.
make
sudo make install
- Download OpenCV version 2.4.2 from http://sourceforge.net/projects/opencvlibrary/files/
- Configure Linux.
- Tell linux where the shared libraries for OpenCV are located by entering the following shell command:
export LD_LIBRARY_PATH=/usr/local/lib
Add the command to your .bashrc file so that you don’t have to enter every time your start a new terminal.
Alternatively, you can configure the system wide library search path. Using your favorite editor, add a single line containing the text
/usr/local/lib
to the end of a file named/etc/ld.so.conf.d/opencv.conf
. In the standard Ubuntu install, the opencv.conf file does not exist; you need to create it. Using vi, for example, enter the following commands:sudo vi /etc/ld.so.conf.d/opencv.conf
G
o
/usr/local/lib
<Esc>
:wq!After editing the opencv.conf file, enter the following command:
sudo ldconfig /etc/ld.so.conf
.
- Using your favorite editor, add the following two lines to the end of /etc/bash.bashrc:
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
- Tell linux where the shared libraries for OpenCV are located by entering the following shell command:
After completing the previous steps, your system should be ready to compile code that uses the OpenCV libraries. The following example shows one way to compile code for OpenCV:
g++ `pkg-config opencv --cflags` my_code.cpp -o my_code `pkg-config opencv --libs`
More Information
- If you encounter problems installing OpenCV, see the companion guide, “A Comprehensive OpenCV Installation Troubleshooting Guide.”
- Utkarsh Sinha runs AiShack, a site that has easy-to-understand tutorials using OpenCV to solve real-world problems: http://www.aishack.in/topics/tutorials/
- Sebastian Montabone has several articles on installing OpenCV and image processing. His web site is http://www.samontab.com/
- FakeOutdoorsman’s posted an excellent dependency install guide, which is located on the Ubuntu forums: http://ubuntuforums.org/showthread.php?t=786095
Hey Osman! thanks for the post! I went through every step with any problem until I got to the make of the OpenCV, where this error appeared. any idea?
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `avpriv_vorbis_parse_extradata’
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `av_des_init’
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `av_rc4_crypt’
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `av_aes_crypt’
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `av_des_mac’
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `av_tree_destroy’
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `av_sha_update’
collect2: ld returned 1 exit status
make[2]: *** [bin/opencv_perf_imgproc] Error 1
make[1]: *** [modules/imgproc/CMakeFiles/opencv_perf_imgproc.dir/all] Error 2
make: *** [all] Error 2
It looks like the OpenCV build can’t find some ffmpeg files. Here’s a couple things to check:
1. Are you sure you installed ffmpeg with the “sudo make install” command?
2. In step 10c, did you see the line that says “FFMPEG: YES”?
3. Did you download ffmpeg 0.11 or 0.11.1? Version 0.11.1 was just released, and I haven’t tested it yet. There might be an incompatibility.
Please let me know the answers to the above questions. Thanks. –Osman
Osman, thanks for the quick reply, this are the answers to your questions:
1 & 3:
/build$ ffmpeg -version
ffmpeg version 0.11
built on Jun 13 2012 08:51:38 with gcc 4.6.1
2:
— FFMPEG: YES
— codec: YES (ver 54.23.100)
— format: YES (ver 54.6.100)
— util: YES (ver 51.54.100)
— swscale: YES (ver 2.1.100)
— gentoo-style: YES
Anything else I could check?
SOLVED! I am using ubuntu 11 over VMWAre Fusion (for Mac). although it is a 32bit VM, I used –enabled-shared and it worked. Thanks Osman for the post!
Thanks Ivan, that worked for me too…
regards
Yeipis
Thanks, Ivan. Fixed my problem too.
Does this work on MAC 10.6.8 ?
I know MAC has unix based … but I am not sure if this instruction suitable with MAC or not
Does anybody try it
I do not know if anyone has tried the instructions on MAC. If you try it, please let me know the results!
Hey Ivan. Sorry for my English.
I had the same problem. But there I need write -enable-shared?
You need the
--enable-shared
option in step 8b when you are running the configure command for ffmpeg.i have same problem and i have tried using 64 bit configuration. but i still have same error. if i want to fix this problem, should i start from the begining installation process or i just need repeat the step for x264 and ffmpeg ?
Repeat the steps for ffmpeg and x264. Then remove the opencv build directory and repeat the steps for building opencv. Let me know how it goes.
Just chiming in to say that this also worked for me. Note that I’m not sure whether it was the 64-bit fix that resolved my issues with the OpenCV build completing, or the fact that I switched to v4l-utils-0.9.5. But, I did both and OpenCV built without errors.
VMWare Workstation 9
guest: Ubuntu Linux 12.10 (32-bit)
host: Windows 7 64-bit (running on a Mac with Boot Camp)
Glad to hear it!
Hey Osman! I have a problem with the file opencv.conf, i alredy checked my ld.so.conf.d directory and there’s no such file with the name opencv.conf. What can i do? I really need to solve this problem, because i hace to run a program that is for a project!
The opencv.conf file does not exist by default. You need to create the file if it does not exist. I will mention this in the instructions. Thanks.
Hi Osman,
I followed your guide and all is working fine, one question cames up: How do we install the qt library according to the guide you posted?
regards,
yeipis
Hi,
I was trying to install OpenCV 2.4.1 on Ubuntu 12.04. I have followed your installation guide and with 17% of the installation complete, I got the following error –
/usr/bin/ld: /usr/local/lib/libavcodec.a(avpacket.o): relocation R_X86_64_32S against `av_destruct_packet’ can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libavcodec.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[2]: *** [lib/libopencv_highgui.so.2.4.1] Error 1
make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
make: *** [all] Error 2
How do I get through this?
Try using the instructions for 64 bit systems. That means going back to the step where you built x264 and ffmpeg.
In Step 9-
I am getting compilation error.
I am using OpenCV2.4.1 with 12.04 ubuntu over VM player.
Any Idea?
make -C lib all
make[1]: Entering directory `/root/src/v4l-utils-0.8.8/lib’
make -C libv4lconvert all
make[2]: Entering directory `/root/src/v4l-utils-0.8.8/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.8″‘ -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
make[2]: Leaving directory `/root/src/v4l-utils-0.8.8/lib/libv4lconvert’
make[1]: *** [all] Error 2
make[1]: Leaving directory `/root/src/v4l-utils-0.8.8/lib’
make: *** [all] Error 2
If I remove libjpeg from my system, I get the same error that you got. Thus, I think libjpeg is not installed properly on your system. Did you download and install libjpeg in step 5? If yes, try removing libjpeg and installing it again:
sudo apt-get remove libjpeg8 libjpeg8-dev
sudo apt-get install libjpeg8 libjpeg8-dev
Thank you so much for such a nice article. It simplified my job. Keep up the good work.
I am trying to write a face detection loggin mechanism for ubuntu. I am no-voice in openCV. Your website is a good start.
Regards,
Venkat
I start trying this instruction … but I got command not found when I type the first line !!!
apt-get I think this is not working in MAC … beacuse I am not expert in unix or mac
I will try to find the command in mac that work like apt-get !!!
You need install mac port
http://guide.macports.org/chunked/installing.macports.html
i am a learner. i want to know how do i run my code in ubuntu terminal.
i want the commands used for compilation and running the program
Thank you Osman, this is very helpful!
/home/shiva/OpenCV-2.4.1/release/modules/core/precomp.hpp:1:0: fatal error: can’t create precompiled header /home/shiva/OpenCV-2.4.1/release/modules/core/precomp.hpp.gch/opencv_core_RELEASE.gch: Permission denied
compilation terminated.
Preprocessed source stored into /tmp/ccTDynBj.out file, please attach this to your bugreport.
make[2]: *** [modules/core/precomp.hpp.gch/opencv_core_RELEASE.gch] Error 1
make[1]: *** [modules/core/CMakeFiles/pch_Generate_opencv_core.dir/all] Error 2
make: *** [all] Error 2
why this error???
I followed the steps to install but when i tried execute the samples:
compiling contours.c
/usr/local/include/opencv2/core/types_c.h:312: error: undefined reference to ‘lrint’
contours.c:78: error: undefined reference to ‘sin’
contours.c:77: error: undefined reference to ‘cos’
contours.c:76: error: undefined reference to ‘sin’
contours.c:75: error: undefined reference to ‘cos’
collect2: ld returned 1 exit status
compiling convert_cascade.c
/usr/local/include/opencv2/core/types_c.h:312: error: undefined reference to ‘lrint’
collect2: ld returned 1 exit status
compiling delaunay.c
Some suggestion?
Sorry for the delay. It looks like you might be missing the math libraries. Did you compile with the -lm option?
hi i have an error while building opencv 241
i am using ubuntu 12.04 64 bit
can u please explain me thanks in advance
[ 25%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/bitstrm.cpp.o
Linking CXX shared library ../../lib/libopencv_highgui.so
/usr/bin/ld: /usr/local/lib/libavcodec.a(avpacket.o): relocation R_X86_64_32S against `av_destruct_packet’ can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libavcodec.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[2]: *** [lib/libopencv_highgui.so.2.4.1] Error 1
make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
make: *** [all] Error 2
Use the instructions for 64 bit systems. That means going back to steps 7 and 8 where you built x264 and ffmpeg. I am confident that will fix your problem.
Got the same error on building. I re-tried step 7 and this is what I get:
Warning: PIX_FMT_RGB is missing from libavutil, update for swscale support
Warning: libavformat is not supported without swscale support
fatal: Not a git repository (or any of the parent directories): .git
platform: X86_64
system: LINUX
cli: yes
libx264: internal
shared: yes
static: no
asm: yes
interlaced: yes
avs: no
lavf: no
ffms: no
gpac: no
gpl: yes
thread: posix
filters: crop select_every
debug: no
gprof: no
strip: no
PIC: yes
visualize: no
bit depth: 8
chroma format: all
You can run ‘make’ or ‘make fprofiled’ now.
Building after this and step 8 produces the same error messages that were first displayed. What should be done now?
Hi I am getting the same error in spite of repeating steps 7 and 8 for 64bit. I deleted the build directory and tried again, but the problem still persists. I would be very grateful if you could help me resolve this issue. Thanks
../../lib/libopencv_highgui.so.2.4.2: undefined reference to `av_fifo_generic_read’
../../lib/libopencv_highgui.so.2.4.2: undefined reference to `avpriv_vorbis_parse_extradata’
../../lib/libopencv_highgui.so.2.4.2: undefined reference to `av_des_init’
../../lib/libopencv_highgui.so.2.4.2: undefined reference to `av_rc4_crypt’
../../lib/libopencv_highgui.so.2.4.2: undefined reference to `av_aes_crypt’
../../lib/libopencv_highgui.so.2.4.2: undefined reference to `av_des_mac’
../../lib/libopencv_highgui.so.2.4.2: undefined reference to `av_tree_destroy’
../../lib/libopencv_highgui.so.2.4.2: undefined reference to `av_sha_update’
collect2: ld returned 1 exit status
make[2]: *** [bin/opencv_perf_core] Error 1
make[1]: *** [modules/core/CMakeFiles/opencv_perf_core.dir/all] Error 2
make: *** [all] Error 2
I don’t see any obvious errors with your procedure. The undefined references are part of ffmpeg, so the build script might be finding ffmpeg. Are you sure that you installed ffmpeg after you compiled it using “sudo make install” in step 8? Do you have another older version of ffmpeg on the system? If so, try removing the older version. Use “apt-cache search ffmpeg” to see if other versions of ffmpeg are installed.
Hello I have the same problem that the one above, but when I did step 8 for 64 bits ubuntu 12.04 I have this error:
LD libavutil/libavutil.so.51
/usr/bin/ld: libavutil/intfloat_readwrite.o: relocation R_X86_64_PC32 against undefined symbol `ldexp@@GLIBC_2.2.5′ can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: ld devolvió el estado de salida 1
make: *** [libavutil/libavutil.so.51] Error 1
can you help me please.
Did you complete step 7 using the 64 bit instructions? Step 7 is the important step to solve the error. If you complete steps 7 and 8 for 64 bit and you still have an error, try removing the OpenCV build directory and creating a new build directory. I have seen situation where a failed build interferes with subsequent builds.
In step-2 I am facing an error-
/var/cache/apt/archives/libatk-adaptor-schemas_2.4.0-1ubuntu2_i386.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
I’m not sure the cause of your error. You could try “sudo apt-get autoremove” and then try to install the packages again.
Hi!
I’m trying to install the opencv and use it with python EPD 7.3.
I’ve followed this guide and these steps to use EPD 7.3:
http://t3hmikez0r.com/2011/05/18/installing-opencv-with-epd-on-ubuntu-11-04
(I’ve already installed opencv 2.2 before, using these steps and it worked fine)
At the end of this tutorial I executed the following command:
sudo cp /usr/local/lib/python2.7/site-packages/cv2.so /home/jorge/Software/epd7.3/lib/python2.7/site-packages/cv2.so
Now I go to Ipython and try:
import cv2
and I get:
—————————————————————————
ImportError Traceback (most recent call last)
/home/jorge/ in ()
—-> 1 import cv2
ImportError: /usr/local/lib/libopencv_highgui.so.2.4: undefined symbol: _ZNK9QCheckBox15minimumSizeHintEv
I’ve used the 64 bit instructions.
Can you help me figuring out whats wrong?
Best Regards!
I have not seen this error before. Perhaps someone else will reply with a suggestion.
Great post, thanks.
As others have noted, you might want to use –enable-shared on the library deps.
Another quick note: to enable the installation of the python module (e.g python ‘cv’ package), make sure you also install python deps:
apt-get install python-dev python-numpy
Adam
[ 6%] Built target libtiff
[ 11%] Built target libjasper
[ 15%] Built target opencv_core
[ 16%] Built target opencv_ts
[ 22%] Built target opencv_imgproc
[ 22%] Built target opencv_flann
[ 25%] Built target opencv_ml
[ 26%] Built target opencv_video
[ 26%] Built target opencv_photo
Linking CXX shared library ../../lib/libopencv_highgui.so
/usr/bin/ld: /usr/local/lib/libavcodec.a(avpacket.o): relocation R_X86_64_32S against `av_destruct_packet’ can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libavcodec.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[2]: *** [lib/libopencv_highgui.so.2.4.1] Error 1
make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
make: *** [all] Error 2
Go back to steps 7 and 8, and use the directions for 64-bit systems. If you still have an error, try removing the OpenCV build directory and creating a new build directory. Would you mind giving me info about your system? What version of Ubuntu are you using? Is it 32 or 64 bit? What platform do you have, such as Intel, AMD, or ARM? Are you running in a virtual machine?
Hi, Upon ‘make’ing OpenCV:
Linking CXX executable ../../bin/opencv_perf_imgproc
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `av_fifo_space’
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `av_fifo_free’
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `av_base64_encode’
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `avpriv_vorbis_parse_frame’
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `av_fifo_realloc2′
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `av_aes_init’
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `av_tree_insert’
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `av_tree_enumerate’
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `av_tree_node_size’
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `av_sha_size’
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `av_base64_decode’
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `av_bitstream_filter_filter’
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `av_adler32_update’
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `av_bitstream_filter_close’
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `av_sha_init’
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `av_tree_find’
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `av_fifo_generic_write’
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `avcodec_register_all’
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `av_fifo_size’
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `av_fifo_alloc’
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `av_sha_final’
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `av_des_crypt’
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `av_aes_size’
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `av_bitstream_filter_init’
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `av_fifo_drain’
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `avpriv_vorbis_parse_reset’
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `av_rc4_init’
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `av_fifo_generic_read’
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `avpriv_vorbis_parse_extradata’
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `av_des_init’
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `av_rc4_crypt’
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `av_aes_crypt’
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `av_des_mac’
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `av_tree_destroy’
../../lib/libopencv_highgui.so.2.4.1: undefined reference to `av_sha_update’
collect2: ld returned 1 exit status
make[2]: *** [bin/opencv_perf_imgproc] Error 1
make[1]: *** [modules/imgproc/CMakeFiles/opencv_perf_imgproc.dir/all] Error 2
make: *** [all] Error 2
The first post mirrors this problem and occurred on Ubuntu 11.10 (64 bit). I re-tried this installation procedure for Ubuntu 12.04 (32 bit) and it worked perfectly fine. Thanks very much!
Hi Hull,
I am getting the same problem but on ubuntu 12.04 (32 bit). Do you have any suggestions about the cause of this error ?
Thanks,
Amey
+1
Thank you…Thank you..Thank you
i followed your steps 1 by 1 i am using ubuntu 12.04
you rock!!
while on step 8(b)
./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: libfaac not found
If you think configure made a mistake, make sure you are using the latest
version from Git. If the latest version fails, report the problem to the
ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file “config.log” produced by configure as this will help
solving the problem.
I got this problem,i updated my git also….but the problem still persists.
Hi Osman,
Thank you very much for the tutorial.
I installed OpenCV 2.4.1 successfully under Ubuntu 12.04 (32 bit) and Ubuntu is running in the virtual machine by VirtualBox in WIN 7 (64 bit).
The first several attempts failed and got the error message as
“make[2]: *** [bin/opencv_perf_imgproc] Error 1
make[1]: *** [modules/imgproc/CMakeFiles/opencv_perf_imgproc.dir/all] Error 2
make: *** [all] Error 2”
but I went back and re-configure for step 7,8, taking 64-bit steps and now it works!
so again, thanks a lot!!!I am really new to this and finally I got this!
Hi i have tried to make the open cv it gave the following error.
what could be the solution.
i am running 32 bit version ubuntu on virtual machine.
collect2: ld returned 1 exit status
make[2]: *** [bin/opencv_perf_imgproc] Error 1
make[1]: *** [modules/imgproc/CMakeFiles/opencv_perf_imgproc.dir/all] Error 2
make: *** [all] Error 2
Thanks
Hey,
thanks for the tutorial. I can build everything perfectly well, but I cannot get anything from a webcam. When I run the example camera.py, all I get is a grey screen, when I run the c example facedetect I get an the message that Capture from Cam 0 did not work. Have you encountered this problem? Do you know any solution? I can see the webcam for example with cheese webcam… (using ubuntu 12.04, opencv 3.4.1)
Thanks
Here’s a couple ideas:
1. Make sure your webcam is UVC compliant. Most of the recent webcams, such as Logitech’s Pro 9000 and C910, are UVC compliant. If you are using a webcam that is more than five years old, try switching to a more recent model.
2. You probably have a loop in your code that ends with a statement like this: key = cvWaitKey( waitTime );. Make sure that the waitTime is not zero. It will probably need to be greater than about 3 or 4 ms. I have seen the grey screen you mention when the waitTime is set to zero.
Thank you for the reply, i tried out your suggestions, neither gets my webcams to work. (Logitech Communicator STX, Microsoft LifeCam Cinema. They work perfectly fine with OpenCV and MacOS… any other ideas? Could it be a hardware problem? Ubuntu is running on an oldish Dell… any hints very much appreciated
If someone have the same problem installing the v4l.
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 is:
sudo apt-get install libjpeg62-dev
Thanks for the tip!
I had to set –enable-pic also for ffmpeg. Without it it give an error at 17%
/usr/bin/ld: /usr/local/lib/libavcodec.a(avpacket.o): relocation R_X86_64_32S against `av_destruct_packet’ can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libavcodec.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[2]: *** [lib/libopencv_highgui.so.2.4.1] Error 1
make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
make: *** [all] Error 2
with it all OK! (MINT 13 64bit)
A really noob query!
Once I compile code.cpp it will generate an executable in the same folder. What command do I use to run it? In other words , how do I execute/run an OpenCV program.
To run the OpenCV program, enter the name of the program. For example, say your compile command looks like this:
g++ `pkg-config opencv --cflags` my_code.cpp -o my_code `pkg-config opencv --libs`
The compile command will produce a file called my_code. Make sure you are in the same directory as my_code, and run it by typing its name:
./my_code
Hi Osman,
I have tried compiling this way and it works fine. However, just for knowledge purpose, can you please tell how to use cmake to compile programs instead of this method ?
Thanks in advance,
Amey
I use the guide step by step but when I compile my file.cpp using Qt. I had 22 errors.
I added the path and the lib in the file.pro. please help me!
I had these error!
18:43:03: Exécution des étapes de compilation pour le projet exemple1…
18:43:03: Configuration inchangée, étape QMake sautée.
18:43:03: Débute : “/usr/bin/make” -w
make: Entering directory `/home/rafik/traitement_image_opencv/exemple1′
g++ -Wl,-O1 -o exemple1 webcam.o -L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann -lavcodec -lavformat
/usr/local/lib/libavcodec.so: undefined reference to `av_bprint_finalize@LIBAVUTIL_51′
/usr/local/lib/libavformat.so: undefined reference to `av_timecode_make_smpte_tc_string@LIBAVUTIL_51′
make: Leaving directory `/home/rafik/traitement_image_opencv/exemple1′
/usr/local/lib/libavformat.so: undefined reference to `av_timecode_make_string@LIBAVUTIL_51′
/usr/local/lib/libavcodec.so: undefined reference to `av_realloc_f@LIBAVUTIL_51′
/usr/local/lib/libavformat.so: undefined reference to `av_timecode_get_smpte_from_framenum@LIBAVUTIL_51′
/usr/local/lib/libavformat.so: undefined reference to `av_timecode_init@LIBAVUTIL_51′
/usr/local/lib/libavcodec.so: undefined reference to `av_samples_set_silence@LIBAVUTIL_51′
/usr/local/lib/libavcodec.so: undefined reference to `av_calloc@LIBAVUTIL_51′
/usr/local/lib/libavcodec.so: undefined reference to `av_get_media_type_string@LIBAVUTIL_51′
/usr/local/lib/libavformat.so: undefined reference to `av_dynarray_add@LIBAVUTIL_51′
/usr/local/lib/libavcodec.so: undefined reference to `av_bprint_init@LIBAVUTIL_51′
/usr/local/lib/libavcodec.so: undefined reference to `av_asprintf@LIBAVUTIL_51′
/usr/local/lib/libavcodec.so: undefined reference to `av_timecode_make_mpeg_tc_string@LIBAVUTIL_51′
/usr/local/lib/libavformat.so: undefined reference to `av_rescale_q_rnd@LIBAVUTIL_51′
/usr/local/lib/libavcodec.so: undefined reference to `av_bprintf@LIBAVUTIL_51′
/usr/local/lib/libavcodec.so: undefined reference to `av_samples_copy@LIBAVUTIL_51′
/usr/local/lib/libavcodec.so: undefined reference to `av_get_default_channel_layout@LIBAVUTIL_51′
/usr/local/lib/libavcodec.so: undefined reference to `av_timecode_init_from_string@LIBAVUTIL_51′
/usr/local/lib/libavcodec.so: undefined reference to `av_bprint_chars@LIBAVUTIL_51′
/usr/local/lib/libavcodec.so: undefined reference to `av_timecode_adjust_ntsc_framenum@LIBAVUTIL_51′
/usr/local/lib/libavcodec.so: undefined reference to `av_tempfile@LIBAVUTIL_51′
collect2: ld returned 1 exit status
make: *** [exemple1] Error 1
18:43:04: Le processus “/usr/bin/make” s’est terminé avec le code 2.
Erreur à la compilation du projet exemple1 (cible : Desktop)
Lors de l’exécution de l’étape “Make”
Did you get it solved? I’m facing the same issue
You would get an undefined reference if you forgot to include the include paths in the g++ command. Please use this syntax:
g++ `pkg-config opencv --cflags` my_code.cpp -o my_code `pkg-config opencv --libs`
Let me know if you still are having problems.
Yes, the code compiles on command line with that command but the executable doesn’t run. On Qtcreator, it still gives build errors upto 22 but not on terminal.
Hi. i am facing the same problem in qt. did you find the solution?
Great article mate, I can’t believe what an ordeal it is to get OpenCV up and running.
FYI
I’m running 64 bit linux and I had this error on step 10b when I tried to compile OpenCV:
[ 25%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/bitstrm.cpp.o
Linking CXX shared library ../../lib/libopencv_highgui.so
/usr/bin/ld: /usr/local/lib/libavcodec.a(avpacket.o): relocation R_X86_64_32S against `av_destruct_packet’ can not be used when making a shared object; recompile with -fPIC
I fixed it by redoing step 8b but adding the compiler option –enable-pic.
As author replied to similar question before – “Go back to steps 7 and 8, and use the directions for 64-bit systems. If you still have an error, try removing the OpenCV build directory and creating a new build directory.” I had the same error, the above solution works
Oops! I missed your line “I fixed it by redoing step 8b but adding the compiler option –enable-pic.”
Hi Osman
firstly thanks for this guide, clear and precise. Only a thing.. it could be great if you could modify step 8, in 64 bit section, adding to configure line “–enable-pic”… this resolve
25%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/bitstrm.cpp.o
Linking CXX shared library ../../lib/libopencv_highgui.so
/usr/bin/ld: /usr/local/lib/libavcodec.a(avpacket.o): relocation R_X86_64_32S against `av_destruct_packet’ can not be used when making a shared object; recompile with -fPIC
definetely
thanks
Interesting. The newest version of ffmpeg, 0.11.1, requires the -pic option, otherwise ffmpeg does not build. This problem occurs even before I try to build opencv. I’ll update the ffmpeg instructions. Thanks for the suggestion!
I was wondering if there is or will be an Ubuntu ISO/Image that I can just install on my laptop, where OpenCV is fully installed? I for one would be very grateful, I’ve been struggling with this for well over three hours now and still no luck..
What is the problem?
There is a package you can install, but it is not the latest version of OpenCV, and it might not include all of the file handlers that you need. However, it might be enough to get you started. Run this command:
sudo apt-get install libopencv-dev
Hey Osman!
You updated the guide and it is as superb as ever!! Perfectly smooth installation.
Thanks a ton! 😀
Hey. I found one small stumble.
When ‘make’ing OpenCV-2.4.2, the matchers.cpp file has a header Eigen/Array.
This header is in /usr/local/include/eigen3/, and it generates an error saying that Eigen/Array no longer exists in eigen3 and the functionality has been moved to Eigen/Core.
I simply commented out that #error macro in the header. So far, it seems to be going well.
🙂
Hi Osman
I am uing 64bit servion.
I am up to step 8b. After running the one for 64 bit servion, I run “make ” and got this error
hien@ubuntu:~/src/ffmpeg-0.11.1$ make
LD libavutil/libavutil.so.51
/usr/bin/ld: libavutil/intfloat_readwrite.o: relocation R_X86_64_PC32 against undefined symbol `ldexp@@GLIBC_2.2.5′ can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: ld returned 1 exit status
make: *** [libavutil/libavutil.so.51] Error 1
How can I fix it?
I try to ignore it and continue then at stepp 10, I get the Error 2.
That is the error you would get if you forgot to use the
--enable-pic
option when you ran theconfigure
command. Make sure you used two minus signs: the option is--enable-pic
and not-enable-pic
. Are you sure you included the option?Yeah i did. i copied pasted the code. Pretty sure its included
Hi Osman,
I am facing the exact same problem which later results in error2 in step10. Please suggest something .
On this step:
./configure –enable-static
make <——- HERE
sudo make install
I get this error. Any ideas? I am running 12.04 on a micro instance. Maybe not enough RAM?
is function [-Wuninitialized]
encoder/cabac.c:1014:17: note: ‘nnzbak[2][2]’ was declared here
encoder/cabac.c:1058:17: warning: ‘nnzbak[1][3]’ may be used uninitialized in this function [-Wuninitialized]
encoder/cabac.c:1014:17: note: ‘nnzbak[1][3]’ was declared here
encoder/cabac.c:1058:17: warning: ‘nnzbak[1][2]’ may be used uninitialized in this function [-Wuninitialized]
encoder/cabac.c:1014:17: note: ‘nnzbak[1][2]’ was declared here
encoder/cabac.c:1058:17: warning: ‘nnzbak[0][3]’ may be used uninitialized in this function [-Wuninitialized]
encoder/cabac.c:1014:17: note: ‘nnzbak[0][3]’ was declared here
encoder/cabac.c:1058:17: warning: ‘nnzbak[0][2]’ may be used uninitialized in this function [-Wuninitialized]
encoder/cabac.c:1014:17: note: ‘nnzbak[0][2]’ was declared here
gcc: internal compiler error: Killed (program cc1)
Please submit a full bug report,
with preprocessed source if appropriate.
See for instructions.
make: *** [encoder/analyse.o] Error 4
Hi Osman,
This is a very good guide for OpenCV installation.
I installed it and went through a couple of examples and works good. But I tried some older code and I got the following error:
/usr/bin/ld: cannot find -lcv
/usr/bin/ld: cannot find -lcxcore
/usr/bin/ld: cannot find -lml
/usr/bin/ld: cannot find -lhighgui
/usr/bin/ld: cannot find -lcvaux
/usr/bin/ld: cannot find -liomp5
collect2: ld returned 1 exit status
make: *** [bin/afers] Error 1
Do you know how could I fix this? I tried looking for the files but I haven’t found them.
Thanks,
Did you get the error while building OpenCV or when compiling user code?
I was compiling user code, which seems to have been developed for OpenCV 2.0.
Thank you very much, I found this tutorial very useful for installing OpenCV on a BeagleBoard Xm running Ubuntu.
Glad it worked for you. I’ve used OpenCV on a PandaBoard with good results. Good to know it also works on a BeagleBoard.
Hi Osman,
I have the same problem as someone before
make[2]: *** [lib/libopencv_highgui.so.2.4.1] Error 1
make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
make: *** [all] Error 2
I have tried the method you gave above.If I take the 64 bit method in step 8,there would be an error during the make.It makes me really puzzled.My ubuntu version is 12.04 32 bit,win7 32 bit.I am installing OpenCV-2.4.3.Could you help me with the problem?Thanks in advance.
Just before the error you show, did you get something like this:
/usr/bin/ld: /usr/local/lib/libavcodec.a(avpacket.o): relocation R_X86_64_32S against `av_destruct_packet’ can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libavcodec.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
Yes,totally the same!
Additionally,I found these in cmake ..
— Looking for libavformat/avformat.h
— Looking for libavformat/avformat.h – found
— Looking for ffmpeg/avformat.h
— Looking for ffmpeg/avformat.h – not found
Does this matter?
Yes, it matters 🙂 There are three possibilities:
1. Something is wrong with your ffmpeg installation. Make sure you you used the
--enable-shared --enable-pic
options when you configured ffmpeg.2. The opencv build is confused. Try deleting the build directory and running cmake again.
3. Something changed in opencv 2.4.3. If 1 and 2 don’t help, let me know and I’ll do some testing with 2.4.3.
Surprisingly!I added –enable -static –enable -shared –enable -picoption in step 8,it worked!
That is strange that you needed both static and shared options. I’m glad you got it working. Thanks for the info.
In fact,I also tried to install OpenCV-2.3.1,but failed.It was really a tough process!Thank you very much for your comprehensive guide!
Hi,
thanks so much for your tutorial so detail.
I have tried to much to install and compile with Opencv ( on Windows and Ubuntu too). But I have problem with linking.
Now, I try again with your guide. That’s better. But, I’m in a trouble:
giang @ ubuntu: ~ / src $ cd OpenCV-2.4.2 /
giang @ ubuntu: ~ / build $ cd src/OpenCV-2.4.2
giang @ ubuntu: ~ / src/OpenCV-2.4.2/build $ g+ + ‘pkg-config opencv – cflags’ Drawing_1.cpp-o test ‘pkg-config opencv – libs’
g+ +: error: pkg-config opencv – cflags: No such file or such
g+ +: error: pkg-config opencv – libs: No such file or such
I don’t understand what’s happend.
You can help me? I really need your help in this case.
Thank you so much.
I have a same problem with you
How can I solve this problem?
I have sloved this problem. I’m very very happy with your guide.
Thanks thanks so much.
I also have a same prolblem with you..
How can I solve this problem…
Did you use the exact syntax shown in step 10? In particular, make sure that you use the backwards single quote, not the regular single quote. Also, make sure you type
--cflags
, not-cflags
.Hi, I have tried installing, when I get to part 9, after installing the v4l and going into the v4l-utils-0.9.3 (that’s the version I’m using), I used to ‘make’ command and i got the following error: make: *** No targets specified and no makefile found. Stop.
Help please. Cheers.
It sounds like you are not in the v4l directory. Did you cd into the v4l-utils directory? If you type ls, do you see the file Makefile?
Yes I’m in the directory and Have seen the Makefile
What do i do with the makefile. By the way, there are two makefiles, .am and .in.
Makefiles usually do not have extensions. I don’t know what the .am and .in files might be for. Maybe something has changed in v4l 0.9.3. I’ll try to build it, and I’ll post my results here.
It appears you need to do a ./configure to generate the Makefile for 0.9.3
For x86_64, I did
./configure --enable-shared --enable-pic
marhaba osman,
Ben linux mint 13 cinnamon 64 bit kullanıyorum. ama ffmpeg kuramadım bilgisayarıma. x264-encoder-open 124 hatası alıyorum. ayrıca ffmpeg 11 sürümü daha önce bende opencv programını derlerken hataya yol açmıştı bu yüzden bende 8 sürümünü kuramaya çalıştım yada 9 sürümünü ikiside hata verdi ne yapmam gerek….
Merhaba, Do you get the error compiling ffmpeg or opencv? I installed Mint 13 Cinnamon 64-bit. I was able to build ffmpeg by following steps 1 to 8. Did you complete all of the steps?
THIS INSTALL IS A NIGHTMARE :d
The install procedure might look complicated, but you should be able to cut and paste the commands which doesn’t take too long. Remember that OpenCV is free, so don’t complain too much!
Hi, Osman.
Thanks a lot for the great guide.
I am new to Linux and searched for guides like that. this is indeed the best I have found so far. I almost made OpenCV install to complete successfully….
I experience problem with stage 7. for some reason the call to ./config fails. I get the following error:
“fatal: Not a git repository (or any of the parent directories): .git”
and the relevant properties are not changed.
when I build OpenCV 2.4.3 I get:
[ 5%] Built target libtiff
[ 9%] Built target libjasper
[ 18%] Built target IlmImf
[ 21%] Built target opencv_core
[ 26%] Built target opencv_imgproc
Linking CXX shared library ../../lib/libopencv_highgui.so
/usr/bin/ld: /usr/local/lib/libavcodec.a(avpacket.o): relocation R_X86_64_32S against `av_destruct_packet’ can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libavcodec.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[2]: *** [lib/libopencv_highgui.so.2.4.3] Error 1
make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
make: *** [all] Error 2
seems like stage 8 is working well but still OpenCV doesnt build… 🙁
what might be the reason?
Thanks a lot,
You have two separate problems:
1. The configure of x264 failed. You really should fix this before building opencv. Make sure you are running “./configure” and not “./config” as you just stated. Also make sure you have a recent snapshot of x264. Someone else had a similar problem which I think was because they downloaded a snapshot created in 2005! Make sure that 2012 is in the name of the snapshot file. Make sure ran the “cd” command as shown in step 7a.
2. It looks like you are on a 64-bit system. You need to redo steps 7 and 8 using the commands shown in the sections labeled IMPORTANT. That is, you need to use the
--enable-shared --enable-pic
options.After fixing the two problems, build opencv again. I’m sure it will work this time.
Let me know if you have any more problems.
Hi, Osman.
Thanks for your prompt response.
I downloaded the latest stable release of x264 (from December 2012) and followed steps 7 and 8.
I then deleted the build folder in opencv and recreated it again and built the project. after 29% this is the message I get:
Linking CXX shared library ../../lib/libopencv_highgui.so
/usr/bin/ld: /usr/local/lib/libavcodec.a(avpacket.o): relocation R_X86_64_32S against `av_destruct_packet’ can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libavcodec.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[2]: *** [lib/libopencv_highgui.so.2.4.3] Error 1
make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
make: *** [all] Error 2
it seems to be still related somehow to stage 7 although I do see that shared and PIC are indicated as “Yes” (while before the enablement of shared and pic they were indicating ‘no”. this means that the ./configure did work, doesnt it?)
Any idea what should be the problem now?
Thanks a lot for the support!
Guy
Yes, the configure did work if you see that shared and PIC are “yes”. Are you sure you did the “make” and “sudo make install” after running configure?
Great guide.
Minor fix: the word “install” is repeated in a few (4) spots, i.e. “…install install x264”
Thanks! I’m probably the only one who actually likes to get grammar corrections!
Hi Osman,
I’m running ubuntu 12.04 on virtualBox under windows 7 host and I have this error and don’t find solution
Linking CXX shared library ../../lib/libopencv_stitching.so
CMakeFiles/opencv_stitching.dir/src/precomp.cpp.o: file not recognized: File truncated
collect2: ld returned 1 exit status
make[2]: *** [lib/libopencv_stitching.so.2.4.2] Error 1
make[1]: *** [modules/stitching/CMakeFiles/opencv_stitching.dir/all] Error 2
make: *** [all] Error 2
would you help me please
Hi, Osman
Well, that’s embaracing… indeed I forgot the make and sudo make install… 🙂
However, trying to run make I now get an error on the following gcc (that is probably part of the make):
gcc -o x264 x264.o input/input.o input/timecode.o input/raw.o input/y4m.o output/raw.o output/matroska.o output/matroska_ebml.o output/flv.o output/flv_bytestream.o filters/filters.o filters/video/video.o filters/video/source.o filters/video/internal.o filters/video/resize.o filters/video/cache.o filters/video/fix_vfr_pts.o filters/video/select_every.o filters/video/crop.o filters/video/depth.o input/thread.o input/lavf.o libx264.a -L. -pthread -L/usr/local/lib -lavformat -lavcodec -ldl -lva -lXfixes -lXext -lX11 -ljack -lasound -lSDL -lxvidcore -lx264 -lvorbisenc -lvorbis -ltheoraenc -ltheoradec -logg -lopencore-amrwb -lopencore-amrnb -lmp3lame -lfaac -lz -lrt -lswscale -lavutil -lm -L/usr/local/lib -lswscale -lavutil -lm -m64 -lm -lpthread
/usr/local/lib/libavcodec.a(libx264.o): In function `X264_init’:
/home/guy/Documents/work/src/ffmpeg-0.11.1/libavcodec/libx264.c:478: undefined reference to `x264_encoder_open_124′
collect2: ld returned 1 exit status
make: *** [x264] Error 1
as you can see, the src path is /home/guy/Documents/work/src and it looks for ffmpeg-0.11.1/libavcodec and surprisingly finds something (I get an error on libx264.c). however, there is no such folder in src. the ffmpeg install comes only at stage 8…
any idea why the make of x264 fails ? the build that I’ve downloaded is x264-snapshot-20121214-2245-stable
Thanks a lot !
Guy
it’s solved Men I removed /build under Opencv and repeated step 10
I have found that creating a new build directory solves a lot of problems!
Hi Osman,
I did exactly what you describe in this page and everythinig works fine, until I try to create a video using CvVideoWriter.
.
I get the following error message:
.
“Unsupported format or combination of formats (Gstreamer Opencv backend doesn’t support this codec actually.)”
.
I looked everywhere I could, but I didn’t find an answer to my problem. Could you please, help me?
.
Thanks in advance,
Gabe.
Getting the right combination of options can be tricky. This should work:
CvVideoWriter* videoOut = cvCreateVideoWriter(
"videoOut.avi",
CV_FOURCC('M','J','P','G'),
30, // fps. This doesn't actually do anything, but it needs to be here.
size
);
If mjpeg is not acceptable, what format are you trying to save the video in?
Hi, Osman.
I have removed all src directory and restarted the process again.
I have deleted all files related to the previous installaion and uninstalled anything that is related to ffmpeg from the linux (to my poor understanding in Linux).
I have tried all the process from the start but still fail on make at the same stage:
/usr/local/lib/libavcodec.a(libx264.o): In function `X264_init’:
/home/guy/Documents/work/src/ffmpeg-0.11.1/libavcodec/libx264.c:478: undefined reference to `x264_encoder_open_124′
collect2: ld returned 1 exit status
make: *** [x264] Error 1
the folder /home/guy/Documents/work/src does not exist anymore.
Do I have to delete Linux and re-install all over again to be able to install openCV ?
Well, I start to understand why OpenCV is so much more popular on Windows….
do you have any idea how can I easily reset this installation ?
(I must say OpenCV installation is not for Linux novice…. maybe I should give up…)
Thanks for your support so far,
Guy
Don’t give up! I have seen that error before, but I don’t remember the cause. I’ll run through the installation procedure and try to duplicate the error. Check back in a day or so…
I downloaded the same snapshot of x264 that you downloaded. It compiled fine for me, so there is nothing wrong with the source code. You should be able to build x264 without ffmpeg. Try this: cd to the …/x264-snapshot-20121214-2245-stable directory. Type
make distclean
. Then complete step 7b by typing./configure --enable-static
make
sudo make install
Let me know if that works.
Hi, Osman.
Thanks a lot for the help !
Actually I have decided to reinstall Linux and then followed your instructions again. this time it worked 🙂
But now I’m stuck on 11.b – it doesnt let me write the bash.bashrc file (did I mention that I’m Linux novice ?…)
I guess its easy to override it (I tried chmod but seems like I do have write access but still doesnt work).
Thanks a lot for your support !
Guy
Glad to hear you got it working! The files in /etc are owned by root, so you need to run your editor as root. For example, if you are using the vi editor, enter
sudo vi /etc/filename
.Hey Osman,
I installed OpenCV 2.4.3 by following your procedure. It installed without any errors. But when I tried compiling any code, I get this error:
mayank@mayank-laptop:~/Desktop/test$ g++ `pkg-config opencv --cflags` filteringImages.cpp -o filteringImages `pkg-config opencv --libs`
/usr/bin/ld: warning: libjpeg.so.62, needed by /usr/local/lib/libopencv_highgui.so, not found (try using -rpath or -rpath-link)
/usr/local/lib/libopencv_highgui.so: undefined reference to `jpeg_finish_compress@LIBJPEG_6.2'
/usr/local/lib/libopencv_highgui.so: undefined reference to `jpeg_write_scanlines@LIBJPEG_6.2'
/usr/local/lib/libopencv_highgui.so: undefined reference to `jpeg_std_error@LIBJPEG_6.2'
/usr/local/lib/libopencv_highgui.so: undefined reference to `jpeg_set_quality@LIBJPEG_6.2'
/usr/local/lib/libopencv_highgui.so: undefined reference to `jpeg_finish_decompress@LIBJPEG_6.2'
/usr/local/lib/libopencv_highgui.so: undefined reference to `jpeg_stdio_src@LIBJPEG_6.2'
/usr/local/lib/libopencv_highgui.so: undefined reference to `jpeg_alloc_huff_table@LIBJPEG_6.2'
/usr/local/lib/libopencv_highgui.so: undefined reference to `jpeg_set_defaults@LIBJPEG_6.2'
/usr/local/lib/libopencv_highgui.so: undefined reference to `jpeg_read_scanlines@LIBJPEG_6.2'
/usr/local/lib/libopencv_highgui.so: undefined reference to `jpeg_CreateCompress@LIBJPEG_6.2'
/usr/local/lib/libopencv_highgui.so: undefined reference to `jpeg_start_compress@LIBJPEG_6.2'
/usr/local/lib/libopencv_highgui.so: undefined reference to `jpeg_CreateDecompress@LIBJPEG_6.2'
/usr/local/lib/libopencv_highgui.so: undefined reference to `jpeg_start_decompress@LIBJPEG_6.2'
/usr/local/lib/libopencv_highgui.so: undefined reference to `jpeg_destroy_decompress@LIBJPEG_6.2'
/usr/local/lib/libopencv_highgui.so: undefined reference to `jpeg_resync_to_restart@LIBJPEG_6.2'
/usr/local/lib/libopencv_highgui.so: undefined reference to `jpeg_destroy_compress@LIBJPEG_6.2'
/usr/local/lib/libopencv_highgui.so: undefined reference to `jpeg_read_header@LIBJPEG_6.2'
/usr/local/lib/libopencv_highgui.so: undefined reference to `jpeg_stdio_dest@LIBJPEG_6.2'
collect2: ld returned 1 exit status
So, what’s the problem here?
Hi Osman,
Referring to the above error, perhaps I should try reinstalling opencv. But before that, I do I uninstall it? How do I reset the installation?
It looks like you might have an old version of ffmpeg (6.2) installed, and opencv is trying to link to that version. Run
dpkg --get-selections | grep ffmpeg
to see if ffmpeg has been previously installed as a package. If it has, usesudo apt-get remove
to remove the packages.If you want to remove the software that you compiled yourself, go to the directory for the software, and type
make uninstall
. However, I don’t think you need to do this. I would double check that you ranmake install
for the software that you compiled yourself. If you don’t install it, opencv won’t be able to find it.On further thought, your problem might be related to the version of libjpeg installed on your system. Make sure you completed step 5 of the installation procedure which installs the latest version of libjpeg.
Hi Osman,
Thanks for your suggestion! I double checked all the steps. I did all of them. Later, I have run “sudo make install” once again in the opencv build directory, and it worked! 🙂
Thank you very much….
Didn’t occur to me to compile ffmpeg and x264 from source…
I got the whole thing running in 10 minutes thanks to your help!! 🙂
Hi,
Great guide, thanks 🙂 v4l depends on the qt-sdk, which i didn’t have installed in the begging. Might want to add that to your guide.
Cheers
-E
I tried compiling the basic program to load and display an image the result was:
g++ `pkg-config opencv –cflags` p1.cpp -o p1 `pkg-config opencv –libs`
Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc’
to the PKG_CONFIG_PATH environment variable
No package ‘opencv’ found
Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc’
to the PKG_CONFIG_PATH environment variable
No package ‘opencv’ found
g++: error: p1.cpp: No such file or directory
g++: fatal error: no input files
compilation terminated.
What to do?
I think you forgot to complete step 11b.
i have something wrong with step 9.please help me…thank you.
dvb-v5.h:69:9: error: ‘NULL’ undeclared here (not in a function)
In file included from dvb-fe.c:21:0:
dvb-v5-std.h:167:2: error: initializer element is not constant
dvb-v5-std.h:167:2: error: (near initialization for ‘dvbv5_attr_names[0]’)
…
dvb-v5-std.h:167:2: error: initializer element is not constant
dvb-v5-std.h:167:2: error: (near initialization for ‘dvbv5_attr_names[44]’)
dvb-fe.c: In function ‘dvb_fe_open’:
dvb-fe.c:43:10: warning: ignoring return value of ‘asprintf’, declared with attribute warn_unused_result [-Wunused-result]
make[2]: *** [dvb-fe.o] Error 1
make[2]: Leaving directory `/home/sungang/openCV/src/v4l-utils-0.8.8/utils/dvb’
make[1]: *** [all] Error 1
make[1]: Leaving directory `/home/sungang/openCV/src/v4l-utils-0.8.8/utils’
make: *** [all] Error 2
I also recieved an error when typing:
sudo make install
make[2]: Entering directory `/home/eos/src/v4l-utils-0.8.8/utils/dvb’
cc -Wp,-MMD,”dvb-fe.d”,-MQ,”dvb-fe.o”,-MP -c -I../../include -I../../lib/include -D_GNU_SOURCE -DV4L_UTILS_VERSION='”0.8.8″‘ -g -O1 -Wall -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -o dvb-fe.o dvb-fe.c
In file included from dvb-fe.c:20:0:
dvb-v5.h:69:9: error: ‘NULL’ undeclared here (not in a function)
In file included from dvb-fe.c:21:0:
dvb-v5-std.h:167:2: error: initializer element is not constant
dvb-v5-std.h:167:2: error: (near initialization for ‘dvbv5_attr_names[0]’)
…
dvb-v5-std.h:167:2: error: initializer element is not constant
dvb-v5-std.h:167:2: error: (near initialization for ‘dvbv5_attr_names[44]’)
dvb-fe.c: In function ‘dvb_fe_open’:
dvb-fe.c:43:10: warning: ignoring return value of ‘asprintf’, declared with attribute warn_unused_result [-Wunused-result]
make[2]: *** [dvb-fe.o] Error 1
make[2]: Leaving directory `/home/eos/src/v4l-utils-0.8.8/utils/dvb’
make[1]: *** [install] Error 1
make[1]: Leaving directory `/home/eos/src/v4l-utils-0.8.8/utils’
make: *** [install] Error 2
Are you sure that in step 9 you compiled AND installed v4l?
Hi All,
I have followed all steps succesfully for instiling opencv, after I typed the last statement:
g++ `pkg-config opencv –cflags` my_code.cpp -o my_code `pkg-config opencv –libs`
my_code has been created, so is this means that I have installed opencv succesfully ?
Any one has any idea how to install sdllib for ubunto using the same steps ?
Regards,
Muhsin
Yes, you were successful. Sorry, I’m not familiar with the installation process for sdllib.
Hi,
when i run step 7 i get the following: fatal: Not a git repository
amulya@amulya-G31M-ES2L:~/src/x264-snapshot-20120528-2245-stable$ ./configure –enable-shared –enable-pic –enable-static
fatal: Not a git repository (or any of the parent directories): .git
platform: X86
system: LINUX
cli: yes
libx264: internal
shared: yes
static: yes
asm: yes
interlaced: yes
avs: no
lavf: yes
ffms: no
gpac: no
gpl: yes
thread: posix
filters: resize crop select_every
debug: no
gprof: no
strip: no
PIC: yes
visualize: no
bit depth: 8
chroma format: all
and finally when i run opencv make i am getting the following error:
../../lib/libopencv_highgui.so.2.4.2: undefined reference to `av_rc4_crypt’
../../lib/libopencv_highgui.so.2.4.2: undefined reference to `av_aes_crypt’
../../lib/libopencv_highgui.so.2.4.2: undefined reference to `av_des_mac’
../../lib/libopencv_highgui.so.2.4.2: undefined reference to `av_tree_destroy’
../../lib/libopencv_highgui.so.2.4.2: undefined reference to `av_sha_update’
collect2: ld returned 1 exit status
make[2]: *** [bin/opencv_perf_core] Error 1
make[1]: *** [modules/core/CMakeFiles/opencv_perf_core.dir/all] Error 2
make: *** [all] Error 2
I have deleted the build directory and retried and also have followed all the steps for 64 bit.
Please let me know what is the problem
Hi,
Thanks a lot, it worked 🙂 Brilliant tutorial 🙂
What was the cause of your earlier problems?
I guess my ffmpeg was not installed properly. I repeated the entire process again for 64bit. It worked 🙂
Great! Glad to hear it.
Hi Osman
I have a problem when i try to open camera with OpenCV.
my enviroment is :Ubuntu 12.0: UTC.my procedure is followed:
1.I use the cmake tool to generate a Makefile.
my toolchain.cmake is
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_C_COMPILER arm-xilinx-linux-gnueabi-gcc)
set(CMAKE_CXX_COMPILER arm-xilinx-linux-gnueabi-g++)
2.then,
cmake -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake /(the OpenCV sourcecode path)
— GUI:
— QT 4.x: NO
— GTK+ 2.x: NO
— GThread : NO
— GtkGlExt: NO
— OpenGL support: NO
—
— Media I/O:
— ZLib: zlib (ver 1.2.7)
— JPEG: NO
— PNG: NO
— TIFF: NO
— JPEG 2000: NO
— OpenEXR: NO
—
— Video I/O:
— DC1394 1.x: NO
— DC1394 2.x: NO
— FFMPEG: NO
— codec: NO
— format: NO
— util: NO
— swscale: NO
— gentoo-style: NO
— GStreamer: NO
— OpenNI: NO
— OpenNI PrimeSensor Modules: NO
— PvAPI: NO
— GigEVisionSDK: NO
— UniCap: NO
— UniCap ucil: NO
— V4L/V4L2: NO/NO
— XIMEA: NO
— Xine: NO
—
— Other third-party libraries:
— Use IPP: NO
— Use Eigen: NO
— Use TBB: NO
— Use OpenMP: NO
— Use GCD NO
— Use Concurrency NO
— Use C=: NO
— Use Cuda: NO
— Use OpenCL: NO
—
— Python:
— Interpreter: /usr/bin/python (ver 2.7.3)
—
— Java:
— ant: NO
— JNI: NO
— Java tests: YES
—
— Documentation:
— Build Documentation: NO
— Sphinx: NO
— PdfLaTeX compiler: NO
—
— Tests and samples:
— Tests: YES
— Performance tests: YES
— C/C++ Examples: NO
—
— Install path: /home/jiong/OpenCV-build
—
— cvconfig.h is in: /home/jiong/opencv-2.4.5
ccmake /the OpenCV sourcecode path
in this step ,i open the WITH_V4L ON ,
then make
the error like :
/home/jiong/opencv-2.4.5/modules/highgui/src/cap_libv4l.cpp:250:21: fatal error: libv4l1.h: No such file or directory
compilation terminated.
make[2]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_libv4l.cpp.o] 错误 1
make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] 错误 2
make: *** [all] 错误 2
but i have installed the v4l,i don’t uderstand.
if I open the ffmepg ,the similar error will appear.
i forget to say my linux is running on the ARM!
I succeed to install until the last command for OpenCV. When command sudo make install It takes quite less than it needs to be. I got the result above. There is no error so I dont know what I did wrong
Install the project…
— Install configuration: “Release”
— Installing: /usr/local/include/opencv2/opencv_modules.hpp
— Installing: /usr/local/lib/pkgconfig/opencv.pc
— Installing: /usr/local/share/OpenCV/OpenCVConfig.cmake
— Installing: /usr/local/share/OpenCV/OpenCVConfig-version.cmake
— Up-to-date: /usr/local/include/opencv/cxcore.hpp
…
— Installing: /usr/local/bin/opencv_traincascade
— Set runtime path of “/usr/local/bin/opencv_traincascade” to “/usr/local/lib”
I am a newbie to command line stuff. I am running Linux Mint 14 Nadia, Linux 3.5.0-17-generic (x86_64). I discovered OpenCV while looking for a way to track and analyze the motion of a something moving in two dimentions. This guide is very clear and discrete. However, I appear to be lacking some basic knowledge regarding the best way to go about installing and then actually using the application.
Is there a guide that can help someone who barely knows how to navigate the terminal?
Thank you
To use OpenCV you will need to write your own programs in C, C++, or Python. Hopefully you have some programming experience even though you are not familiar with the command line. There are many guides that list the basic commands you can use. Here is one: http://sunsite.utk.edu/UNIX-help/quickref.html.
Hello
I am trying to install openCv 2.4.2 on ubuntu 10.04 on Vmware.
But I am not able to install libjack-jackd2-dev and libva-dev.
please help me to install these on ubuntu 10.04
Thanks
What is the problem? Did you get an error message?
Thanks for reply.
I got error message
E:package not found.
Then I installed libjack0 with the help of synaptic manager.
But I was not successfull to install jack2 on my ubuntu.
openCv is successfully installed.
To add path should I use full path
e.g. export LD_LIBRARY_PATH=Aska123/src/OpenCV-4.2/usr/local/lib
or
export LD_LIBRARY_PATH=/usr/local/lib
sufficient?
Please explain how to add path.
ALso give a example to test OpenCv
Step 11a shows how to change your LD_LIBRARY_PATH to include the libraries that you installed in step 10d. The correct command is shown in step 11a: export LD_LIBRARY_PATH=/usr/local/lib.
The official opencv installation page for info about testing opencv: http://opencv.willowgarage.com/wiki/InstallGuide.
I’m with same problem of sungang and Andrew on “make” of step 9:
dvb-fe.c: Na função ‘dvb_fe_open’:
dvb-fe.c:43:10: aviso: ignoring return value of ‘asprintf’, declared with attribute warn_unused_result [-Wunused-result]
make[2]: ** [dvb-fe.o] Erro 1
make[2]: Saindo do diretório `/home/lucio/src/v4l-utils-0.8.8/utils/dvb’
make[1]: ** [all] Erro 1
make[1]: Saindo do diretório `/home/lucio/src/v4l-utils-0.8.8/utils’
make: ** [all] Erro 2
Thank you.
Hello,
Did your problem get solved? If so, could you please outline the steps you took?
Thanks
I faced the above problem when trying to install v4l version 0.8.8 on Ubuntu 12.10(Quantal). I solved this by going for the version 0.9.3
cd ~/src
wget http://www.linuxtv.org/downloads/v4l-utils/v4l-utils-0.9.3.tar.bz2
tar xvf v4l-utils-0.9.3.tar.bz2
cd v4l-utils-0.9.3
./configure
make
sudo make install
Hi,
I am installing OpenCV on Ubuntu 13.04. I follow all the steps till 9th step where I have to type “make” and then “sudo make install” for v4l-utils and when I type “make” I receive this error:
dvb-v5-std.h:167:2: error: (near initialization for ‘dvbv5_attr_names[44]’)
dvb-fe.c: In function ‘dvb_fe_open’:
dvb-fe.c:43:10: warning: ignoring return value of ‘asprintf’, declared with attribute warn_unused_result [-Wunused-result]
make[2]: *** [dvb-fe.o] Error 1
make[2]: Leaving directory `/home//src/v4l-utils-0.8.8/utils/dvb’
make[1]: *** [all] Error 1
make[1]: Leaving directory `/home//src/v4l-utils-0.8.8/utils’
make: *** [all] Error 2
Please help.
I’m sorry, I do not know the cause of the error. When I update the guide to use Ubuntu 13.04, I will try to include a solution.
Hi
I have installed OpenCV 2.4.2 along with ffmpeg using the above post on ubuntu 11.10. Although, it is installed well. However when I tried to run some video using opencv. I got “Segmetation fault”. I think Opencv is not communication with ffmpeg correctly.
Do have any suggestion.???
Hi Osman,
when i compiled code
i got this
my_code.cpp: In function ‘int main(int, char**)’:
my_code.cpp:7:62: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
after running it i got this
./my_code
./my_code: error while loading shared libraries: libopencv_core.so.2.4: cannot open shared object file: No such file or directory
Also after 10b i got this
FFMPEG: NO
I am very new to ubuntu and not getting how to solve this.
Please help
[…] Removal and Installation: This largely follows the tutorial here with modifications necessary for ARM devices and to add support for gstreamer on […]