OpenCV (Open Source Computer Vision) is a library of programming functions for real time computer vision. It is written in C/C++ and is used worlwide in many computer vision applications.
This "how to" is a mix of two other great tutorials on OpenCV installations: A Compreehensive Guide to Installing and Configuring OpenCV 2.3.1 on Ubuntu from ozbots.org; and the OpenCV Installation Guide on Debian and Ubuntu from the OpenCV Wiki. I used this procedure to successfully install OpenCV on two amd64 computers (a laptop and a desktop) running Ubuntu 11.10 Oneiric Ocelot. However, if you find any problem you can check the Comprehensive OpenCV Installation Troubleshooting Guide from ozbots.
1. Remove any installed versions of ffmpeg and x264
sudo apt-get remove ffmpeg x264 libx264-dev
2. Get all the dependencies
sudo apt-get update sudo apt-get install build-essential checkinstall git pkg-config cmake libpng12-0 libpng12-dev libpng++-dev libpng3 libpnglite-dev libpngwriter0-dev libpngwriter0c2 libfaac-dev libjack-jackd2-dev libjasper-dev libjasper-runtime libjasper1 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 zlib1g-dbg zlib1g libgstreamer0.10-0 libgstreamer0.10-dev libgstreamer0.10-0-dbg 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 pngtools libtiff4-dev libtiff4 libtiffxx0c2 libtiff-tools libjpeg8 libjpeg8-dev libjpeg8-dbg libjpeg-prog libavcodec-dev libavcodec52 libavformat52 libavformat-dev libxine1-ffmpeg libxine-dev libxine1-bin libunicap2 libunicap2-dev libdc1394-22-dev libdc1394-22 libdc1394-utils swig python-numpy libpython2.7 python-dev python2.7-dev libjpeg-progs libjpeg-dev libgtk2.0-0 libgtk2.0-dev gtk2-engines-pixbuf
3. Download and install x264 - download any recent stable snapshot from ftp://ftp.videolan.org/pub/videolan/x264/snapshots/ (I used x264-snapshot-20111012-2245-stable.tar.bz2) and extract it to a folder. Then enter the folder and configure and build it:
./configure --enable-static make sudo make install
NOTE: In my computers (64-bit) I had to add the flags "--enable-pic --enable-shared" to the configuration. Otherwise I would get compilation errors when building OpenCV. If you get them too, run
sudo make clean
and reconfigure and rebuild using
./configure --enable-static --enable-pic --enable-shared make sudo make install
4. Download and install ffmpeg - download any recent stable snapshot from http://ffmpeg.org/download.html (I used ffmpeg-0.8.5.tar.gz) and extract it to a folder. Then enter the folder and configure and build it:
NOTE: According to blog reader custom6109 some of the headers in ffmpeg changed and opencv does not recognize the deprecations (03/16/2012). Installing with ffmpeg0.10 should work. (Thanks custom6109!)
./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 install
NOTE: Once again, in my computers (64-bit) I had to add the flags "--enable-pic --enable-shared" to the configuration. Otherwise I would get compilation errors when building OpenCV. If you get them too, run
sudo make clean
and reconfigure and rebuild using
./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-pic --enable-shared make sudo make install
5. Download and install v4l - download any recent stable snapshot from http://www.linuxtv.org/downloads/v4l-utils/ (I used v4l-utils-0.8.5.tar.bz2) and extract it to a folder. Then enter the folder and build it:
make sudo make install
6. Download and install OpenCV - download OpenCV 2.3.1 from http://sourceforge.net/projects/opencvlibrary/files/ and extract it to a folder. Then enter the folder and build it:
mkdir release cd release cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON -D BUILD_EXAMPLES=ON .. make sudo make install
7. Configure Linux - add the following line to your .bashrc in order to tell linux where the shared libraries for OpenCV are located without having to enter it everytime you start a new terminal:
export LD_LIBRARY_PATH=/usr/local/libusing any text editor add the following lines to the end of your /etc/bash.bashrc file
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig export PKG_CONFIG_PATH
8. Reboot.
That's it! If you perform all the steps indicated you should have OpenCV installed in your system. You can check the samples in <your opencv folder>/samples/ . To compile all the C/C++ samples at once you can enter the <your opencv folder>/samples/c folder and give the build_all.sh script permissions to be executed
chmod +x build_all.sh
Then just run
./build_all.sh
and all the samples will be compiled.
To make python work run
python import cv2
If no error occurs, then the python wrappers are successfully installed.
To compile code that uses OpenCV libraries use
g++ `pkg-config --cflags opencv` my_code.cpp -o my_code `pkg-config --libs opencv
If you find any problems in this tutorial post them in the comments. I can't promise that I'll find the solution, since I'm not an expert, but I'll try.
Update (24/10/11): I placed an entry on this blog on How to use CMake with OpenCV to build projects that use the OpenCV libraries.Check it out if you want
Update (29/01/12): As suggested by blog reader Cactus (thanks for your contribution :)), I've added the packages "libopencore-amrnb-dev" and "gtk2-engines-pixbuf" to step 2.
Later I'll post some basic projects using OpenCV.
Did you find this post helpful? Do you wish to contribute to other projects regarding computer science, electronics, robotics or mechatronics that will be posted in this blog? If you wish to do so, you can donate via paypal using the button below. Thanks! :)
I'm Chinese. And this post really help me build my opencv successfully on Oneric! Thank you!
ReplyDeleteThanks for the feedback! You don't imagine how pleasing and motivating it is to get feedback from someone from the other side of the planet 5 days after I started this blog! I'm glad I could help someone by sharing my experiences. Happy programming with OpenCV and thanks for your comment!
ReplyDeletei'v installed opencv as you said, and tried to compile the samples with no success. it tells me that openCV function are not defined, what seems to be the problem?
ReplyDelete"...
find_obj.cpp:(.text+0xfd0): undefined reference to `cvLoadImage'
find_obj.cpp:(.text+0xfe5): undefined reference to `cvLoadImage'
find_obj.cpp:(.text+0x102c): undefined reference to `cvCreateMemStorage'
find_obj.cpp:(.text+0x103f): undefined reference to `cvNamedWindow'
find_obj.cpp:(.text+0x104e): undefined reference to `cvNamedWindow'
find_obj.cpp:(.text+0x105a): undefined reference to `cvGetSize'
find_obj.cpp:(.text+0x106c): undefined reference to `cvCreateImage'
find_obj.cpp:(.text+0x1088): undefined reference to `cvCvtColor'
find_obj.cpp:(.text+0x10ca): undefined reference to `cvSURFParams'
find_obj.cpp:(.text+0x10cf): undefined reference to `cvGetTickCount'
...
"
Yokhai
can you please email me if you know whats wrong
en.yokhai@gmail.com
It seems like Ubuntu is not finding the opencv libraries. Are you sure you performed step 7? Did you reboot after that? How did you compile? Did you use the build_all.sh script included in the samples/c folder? (to compile insert "chmod +x build_all.sh" and then "./build_all.sh"). You can also try entering "export LD_LIBRARY_PATH=/usr/local/lib" manually in your console and then try to build the samples. I wish I could help you better than this but I think the problem is in Ubuntu not finding the libraries.
ReplyDeleteHi,
ReplyDeleteThank you for giving such a detailed step-by-step installation guide. But I have a similar problem.
~/OpenCV-2.3.1/samples/c$ g++ `pkg-config opencv --cflags` `pkg-config opencv --libs` facedetect.cpp -o facedetect
/tmp/ccqGWZrS.o: In function `main':
facedetect.cpp:(.text+0x1b9): undefined reference to `cv::CascadeClassifier::CascadeClassifier()'
facedetect.cpp:(.text+0x1c7): undefined reference to `cv::CascadeClassifier::CascadeClassifier()'
facedetect.cpp:(.text+0x3ac): undefined reference to `cv::CascadeClassifier::load(std::basic_string<char, std::char_traits, std::allocator > const&)'
facedetect.cpp:(.text+0x589): undefined reference to `cv::CascadeClassifier::load(std::basic_string<char, std::char_traits, std::allocator > const&)'
facedetect.cpp:(.text+0x674): undefined reference to `cvCreateCameraCapture'
facedetect.cpp:(.text+0x744): undefined reference to `cv::imread(std::basic_string<char, std::char_traits, std::allocator > const&, int)'
facedetect.cpp:(.text+0x799): undefined reference to `cvCreateFileCapture'
.
.
.
I understand that this is a linker error as my google search returned people encountering the same problem. The important part though is that even if I do step 7 manually (since I cannot change access to /etc/bash.basrc), the problem still persists. I did the following to check environment variables but still now luck:
mjhb@ubuntu:~/OpenCV-2.3.1/samples/c$ echo $LD_LIBRARY_PATH
/usr/local/lib
mjhb@ubuntu:~/OpenCV-2.3.1/samples/c$ echo $PKG_CONFIG_PATH
/usr/local/lib/pkgconfig
I hope you could help me with the linker problem.
-Martin
Hi Martin! Thanks for the detailed description on the problem :) It seems like that command to compile doesn't work in this version of opencv. I got that compilation code from the ozbots tutorial that I mentioned in the post but honestly I didn't tried it myself, until now. As soon as I read your comment I tested it and got the same error as you did. However, I noticed that building the samples with the "build_all.sh" script it worked fine. After all, its not a global variables / path problem, it's a problem with the compilation command (by the time you read this it will already be fixed in the post). By analyzing the build_all.sh script I was able to discover the error and fix it. To compile use the following code: " g++ `pkg-config --cflags opencv` facedetect.cpp -o facedetect `pkg-config --libs opencv` ". It's similar to the previous compile line but now the `pkg-config --libs opencv` part is in the end and in my computer compiles okay. I think this will fix your problem but I strongly suggest you to take a look at the tutorial on how to use CMake with OpenCV that I posted. It will spare you some headaches with compilation / linking stuff. I hope the fix works for you and thanks for your question and detailed description. You have just helped me to correct and improve the tutorial :) When you try it please let me know if it works for you.
ReplyDeleteYou are right with build_all.sh...works like charm. Thanks!
ReplyDeleteHey Martin, thank you for posting this nice step-by-step tutorial. I had installed opencv successfully until I updated to Ubuntu 11.10 today. Suddenly I encounter a warning in Code::Blocks that it needs libavormat.so.52 and a few other file.
ReplyDeleteHowever, I simply tried to install opencv again using your tutorial and it worked fine until making opencv. It then gives me the error:
make[2]: *** No rule to make target `/usr/lib/libz.so', needed by `lib/libopencv_core.so.2.3.1'. Stop.
Did you maybe encounter something similar or have an idea to a possible solution?
Thanks very much in advance I've been trying all day, so I could make use of a little hint.
Hi Mark. When I updated from 11.04 to 11.10 I remember I had a problem with libavformat.so.52 not being found and I didn't find out how to solve it. Then I did a fresh install of 11.10, reinstalled opencv and it worked fine. However, I never got problems making opencv like you do :\ The only thing I can suggest you is to try to remove the packages related to zlib1g and install them again. :\
ReplyDeleteThanks. I'll probably do a fresh install too. Just to be sure I don't spend another 5 hours gaining nothing.
ReplyDeleteIn fact, the fresh install took me about 1h30m... way less than the time I spent trying to solve it :\
ReplyDeleteI am starting to use Opencv. So, I apologize if my doubts are just plain stupid. I followed your guide and installed it on my machine, which is running on Ubuntu 11.10. It seems to work fine. At least I thought so...
ReplyDeleteWhile compiling a code (below) for playing a video (see http://linuxconfig.org/introduction-to-computer-vision-with-opencv-on-linux) I found a problem. It compiles fine, but as I try to play a video I get a segmentation fault:
>> g++ `pkg-config opencv --cflags opencv` ./playvideo.c -o ./playvideo `pkg-config --libs opencv`
>> ./playvideo ./tree.avi
>> Segmentation fault
I am also having trouble running some of the python samples.
------------------------------------------------------------
#include "highgui.h"
int main( int argc, char** argv ) {
cvNamedWindow( "Example2", CV_WINDOW_AUTOSIZE );
CvCapture* capture = cvCreateCameraCapture(0) ;
IplImage* frame;
while(1) {
frame = cvQueryFrame( capture );
if( !frame ) break;
cvShowImage( "Example2", frame );
char c = cvWaitKey(33);
if( c == 27 ) break;
}
cvReleaseCapture( &capture );
cvDestroyWindow( "Example2" );
}
is it also working in 32 bit? i am using dell 1011 netbook
ReplyDeleteI did not try to install in a 32-bit but I think it works for both versions. I think the only differences between 32-bit and 64-bit rely on the --enable-shared and --enable-pic flags.
ReplyDeleteHi. If your code compiles fine, then opencv is correctly installed. The first thing I noticed is that you are compiling a C code with g++, which is used for C++. It may not be an issue since it compiles fine but you may want to check that (I tested with both and had no problems with any). The second thing is that the code you posted is not for displaying a video, it is for displaying a webcam stream from your webcam, if you have any. The code for playing a video file is in the topic 4.3 of the website you provided. I tested both programs in my computer and both compiled fine, so I can guarantee you that the code from that website works. I'd also like to suggest you to read something about OpenCV 2.x since that code you're testing uses some old openCV formats that are not advised anymore. As an example, the structure IplImage should not be used anymore. Instead you should use cv::Mat structures for better and easier memory management.I hope I've helped in any way.
ReplyDeleteOops, I am sorry. I posted the wrong code. Ok, I will try to look for better examples. Thank you for your suggestions.
ReplyDeleteNo problem. If you have any further questions feel free to ask. I can't guarantee that I'll be able to solve them but I'll try. If you want a great book to learn about OpenCV 2.x I recommend getting this one. I've read it and found it very clear and simple. It will give you a great overall view of all the openCV functions with various code examples.
ReplyDeleteHey thanks a lot.
ReplyDeleteI'm new on 64-bit Ubuntu systems and I had a compile error on OpenCV but now it's fixed thanks to your tutorial.
Nice job!
Thanks! I'm happy that it worked for you too :)
ReplyDeleteHi,
ReplyDeleteThanks for such a detailed explanation.But i have a problem.
when i tried to install cv
i got stuck up at the 4th step.
i.e.,
installation of ffmpeg,,,
it showed me the following error,,(i had pasted only the end part of it
, i had done make followed by make install ignoring the error in make)
ffmpeg.c:3330:5: warning: ‘av_open_input_file’ is deprecated (declared at libavformat/avformat.h:1090) [-Wdeprecated-declarations]
ffmpeg.c: In function ‘opt_output_file’:
ffmpeg.c:3995:5: warning: ‘av_set_parameters’ is deprecated (declared at libavformat/avformat.h:1434) [-Wdeprecated-declarations]
ffmpeg.c: In function ‘transcode’:
ffmpeg.c:2644:26: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
ffmpeg.c: In function ‘opt_codec’:
ffmpeg.c:3076:22: warning: ‘pcodec_name’ may be used uninitialized in this function [-Wuninitialized]
ffmpeg.c:3074:23: warning: ‘pstream_copy’ may be used uninitialized in this function [-Wuninitialized]
CC cmdutils.o
cmdutils.c: In function ‘opt_default’:
cmdutils.c:347:9: warning: ‘av_find_opt’ is deprecated (declared at libavutil/opt.h:111) [-Wdeprecated-declarations]
cmdutils.c:354:9: warning: ‘av_find_opt’ is deprecated (declared at libavutil/opt.h:111) [-Wdeprecated-declarations]
cmdutils.c:361:9: warning: ‘av_find_opt’ is deprecated (declared at libavutil/opt.h:111) [-Wdeprecated-declarations]
cmdutils.c: In function ‘set_context_opts’:
cmdutils.c:494:13: warning: ‘av_find_opt’ is deprecated (declared at libavutil/opt.h:111) [-Wdeprecated-declarations]
cmdutils.c: In function ‘read_file’:
cmdutils.c:884:10: warning: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Wunused-result]
LD ffmpeg_g
libavcodec/libavcodec.so: undefined reference to `x264_encoder_open_118'
collect2: ld returned 1 exit status
make: *** [ffmpeg_g] Error 1
srikanthdbp@srikanth-Aspire:~/Documents/ffmpeg-0.8.7$ sudo make install
LD ffmpeg_g
libavcodec/libavcodec.so: undefined reference to `x264_encoder_open_118'
collect2: ld returned 1 exit status
make: *** [ffmpeg_g] Error 1
srikanthdbp@srikanth-Aspire:~/Documents/ffmpeg-0.8.7$
please help me
thank u
Hi! Unfortunately I have never seen this error before. The first thing I suggest is to remove the x264 and ffmpeg installations and try to install again starting on step 1. Maybe you missed some step or for some reason something went wrong. Another thing that you can try is to install ffmpeg through the Ubuntu Software Center. I've read somewhere that someone installed ffmpeg that way and it worked too. Sorry for not being able to help you more than this :\
ReplyDeleteThanks for all your work on this; I'm hoping my issue is something simple:
ReplyDeleteI'm using Ubuntu 11.10, 64-bit on a multi-core desktop (16x3.3GHz). At step 2, I get the following:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'libjpeg62-dev' instead of 'libjpeg-dev'
E: Unable to locate package libpngwriter0-dev
E: Unable to locate package libpngwriter0c2
E: Unable to locate package libjpeg-prog
E: Unable to locate package libavcodec52
E: Unable to locate package libavformat52
Problem solved: I used steps 1-3 from ozbots comprehensive guide, in place of step 2 here.
ReplyDeleteHey! I'm glad you could solve it on your own :) It's weird that it happened since all the packages installed in steps 1-3 from the ozbots comprehensive guide are included in the step 2. Maybe something went wrong :\ Anyway, thanks for you comment and congratulations for solving the problem and a big WOW :o for your multi-core desktop. It must be awesome to work with such computer ;)
ReplyDeleteHi Martin thanks for your useful guide.
ReplyDeleteI'm having the same problem when you updated from 11.04 to 11.10 with libavformat.so.52. When you said a fresh install of 11.10, that means some kind of update or you actually format your machine and started again. I dont want to format my machine any suggestions. Thanks alot.
Hi! When I say "a fresh install" I mean a complete format of the machine. I know that the idea of formatting the machine is a little painfull but in this case you'll probably lose less time formatting than trying to solve the problem :\
ReplyDeleteI had the same problem but managed to fix it. The problem is that libz.so is at /usr/lib/x86_64-linux-gnu/libz.so (on 64 bit systems at least). I built a dummy cmake project to check what FindZLIB was returning and did find that it was correct. Doing a grep in the build directory of opencv showed that in the CMakeCache.txt the ZLIB library file path was set to /usr/lib/libz.so.
ReplyDeleteI had initially set up the build settings through cmake-gui so perhaps this is where the problem came from (but not sure how). Anyway, I simply delete CMakeCache.txt and ran make which rebuilt the cache and magically set the library to the correct value ----- go figure! :-)
Actually it has just dawned on me that the CMakeCache.txt settings were probably there from the previous version of Ubuntu since I had just gone through a series of upgrades (from 10.04 to 11.10!).
ReplyDeleteHey! Thanks for sharing the problem and the solution. I'm sure it will help others that may find the same problem :)
ReplyDeleteSame issue, same solution...
ReplyDeleteHowever it happened an intel i7 (64bits but with ubuntu of 32 installed)...
The tutorial posted here worked in my laptop intel i3 (64bits but with ubuntu of 32 installed)...
what to say? weird...
thanks for the tutorial!!!!
Hi, I get the error like this:
ReplyDeleteLinking CXX shared library ../../lib/libopencv_highgui.so
/usr/bin/ld: /usr/local/lib/libavcodec.a(imgconvert.o): relocation R_X86_64_32S against `ff_cropTbl' 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.3.1] Error 1
make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
make: *** [all] Error 2
This happens in step 6 while making inside the release directory! It just went upto 19% in the process then this pops up, any idea?? I've been trying to install this for days now :(
thanks!
Hi! Which architecture are you running? In steps 3 and 4 did you compile with the --enable-pic and --enable-shared flags, as suggested for 64-bit architectures?
ReplyDeleteHi!
ReplyDeleteFirst of I would like to thank you for a great tutorial. But there are some things that did not work as expected for me. I ran this on a virtual machine (VirtualBox) with Ubuntu 11.10 (vanilla installation + all updates to this date Jan 29, 2012) as client and Windows 7 as host (but that should not make any difference). Here are the errors and the fixes I found for them.
The first thing I noticed was that FFMpeg (0.8.10) failed to build until I installed "libopencore-amrnb-dev". This is in the ozbots tutorial, but not here.
Also, as Steve mentioned, there are packages that is NOT found in Ubuntu 11.10. They might be found in some other repos but not in the original Ubuntu sources.list. The "apt-get" command will not work until you remove these I found.
You also might want to add "gtk2-engines-pixbuf" in step 2 to get rid of some GTK error messages that you get when running some samples.
Example: When you run "find_obj.py", you will most likely get a error message like this
(find_obj SURF:1826): Gtk-WARNING **: Unable to locate theme engine in module_path: "pixmap",
And this disappears after you have installed the pixbuf package.
Hi! First of all, thanks for your contribution! :) When I copied the packages from the ozbots tutorial and mixed with the tutorial from the OpenCV Wiki, I missed the "libopencore-amrnb-dev" package. My mistake! :P Regarding the GTK errors, I never noticed them since my developments with OpenCV never required me to use GTK. I'm glad you figured out how to solve the errors and shared to help everyone that may get the same problems :) Thank for sharing your experiences! :)
ReplyDeleteI have ubuntu 10.10....
ReplyDeleteI want ffmpeg with Opencv2.3.1 support....
I did the installation many times before....with building ffmpeg manually as you said....
Its working fine also its showing me ffmpeg support ON at the time of configuring OpenCv 2.3.1...
But when I use CV_FOURCC('F','L','V','1') to create .flv file through cvCreateVideoWriter I am getting this error [flv @ 0x9bf5000] Tag FLV1/0x31564c46 incompatible with output codec id '22'....
Is their any thing wrong I had done while installation....
Hi! I'm afraid I can't help you with that :\ I never tried to create .flv files since I installed openCV. If you have any sample project files to test that I can run with my installation to see if it's something that just happens to you or to others as well I can try it.
ReplyDeleteShould I post my code over here....
ReplyDeleteUpload in a zip file using dropbox or ubuntu1 and provide the link here. After I download it and test it you may delete the folder.
ReplyDeleteHere is the link....
ReplyDeletehttp://pastebin.com/HQEvbDCh
Please make it test.cpp and keep one test.avi file in same folder....
Here is the link….
ReplyDeletehttp://pastebin.com/HQEvbDCh
Please make it test.cpp and keep one test.avi file in same folder….
Please help me......Try this code....Check if it is creating new.flv file
ReplyDeleteHi! I have tested your code and unfortunately it didn't work either. I successfully saved a file as another .avi but couldn't do it for an .flv. I searched for a while to see if I could figure out a fix but I couldn't. Using ffmpeg I am able to convert the AVI file to flv by typing "ffmpeg -i test.avi test.flv" which means that ffmpeg is working. I also tried to convert an .flv file to avi and no luck either. Try to ask to some other people you know to see if someone has got it working :\
ReplyDeleteI'm curious if anyone has had success with this using Ubuntu 11.10, Enthought 7.2-2. I cannot get it to work - it worked ok with Enthought 7-2.2; and the OpenCV install works OK with the default system python...
ReplyDelete[...] the libraries by myself. But that’s not alwasy as easy as it looks like. After try, nor one, two, three, four, but six different methods, I got OpenCV libraries working on my machine with [...]
ReplyDeleteI WANT TO ASK THE LINK FOR OPENCV IN UBUNTU 11.10
ReplyDeleteI WANT TO DOWNLOAD THE OPENCV FOR UBUNTU 11.10
THANKS
If you read the post I'm sure you'll find the link to download opencv.
ReplyDeleteEveryThing is working fine till now!! Thank You. Awesome Article
ReplyDeleteThanks! :) I'm glad it worked for you ;)
ReplyDeletehi! iam a biginner to opencv. i ran a program using opencv2.2(on ubuntu11.04) .the code uses webcam.compiled the code successfully but when executed, webcam is not working i tried different codes using webcam but ends up with the same result! does opencv 2.2 have any webcam support issues? do i have to downgrade to opencv2.1? please help..
ReplyDeletethanks.
Hi! The problem may be due to several issues. Did you install ffmpeg correctly vefore installing opencv 2.2? Are you sure that the webcam that you are using is supported by openCV? My advice would be to uninstall opencv 2.2 and install opencv 2.3.1 using the tutorial above. It should also work in ubuntu 11.04.
ReplyDeleteThanks Man ... Saved me a lot of time !!!
ReplyDeleteBTW: i had exceptions like undefined reference to `cv::CascadeClassifier::CascadeClassifier()' and undefined reference to `cv::Mat::copySize(cv::Mat const&)' and I found that I was linking incorrect dlls. I was linking dll's compiled with visual studio 9 but compiled my project with mingw. Seems that c++ is linking incorrectly with differed built dlls. Hope this helps for others.
ReplyDeleteinstead use
ReplyDeletesudo apt-get install libjpeg62 libjpeg62-dev
When using your guide I had problems installing ffmpeg 0.10
ReplyDeleteIt said something like
ERROR : Could not find -libfaac
When I removed the --enable-libfaac flag it started missing libxvid.
The other guide worked fine though.
It's weird that it happened since this tutorial is based on the other guide and has been working for the large majority of people :\ Anyway, I'm glad you managed to install it using the other guide and thanks for posting your experience. I'm sure it will help others. :)
ReplyDeleteI don't know what I'm doing wrong. I have installed the opencv 2.3.1 on 11.10 ubuntu. I'm new in this field so plz help me.
ReplyDeleteI'm entering this in my terminal
g++ `pkg-config –cflags opencv` facedetectZuhair.cpp -o facedetectZuhair `pkg-config –libs opencv`
and what i got is this
/tmp/cc8Y7h94.o: In function `main':
facedetectZuhair.cpp:(.text+0x19): undefined reference to `cvLoadImage'
facedetectZuhair.cpp:(.text+0x35): undefined reference to `cvWaitKey'
facedetectZuhair.cpp:(.text+0x41): undefined reference to `cvReleaseImage'
facedetectZuhair.cpp:(.text+0x4d): undefined reference to `cvDestroyWindow'
/tmp/cc8Y7h94.o: In function `detect_and_draw(_IplImage*)':
facedetectZuhair.cpp:(.text+0xbd): undefined reference to `cvCreateImage'
facedetectZuhair.cpp:(.text+0xe5): undefined reference to `cvLoad'
facedetectZuhair.cpp:(.text+0x129): undefined reference to `cvCreateMemStorage'
facedetectZuhair.cpp:(.text+0x142): undefined reference to `cvNamedWindow'
facedetectZuhair.cpp:(.text+0x14f): undefined reference to `cvClearMemStorage'
facedetectZuhair.cpp:(.text+0x1ed): undefined reference to `cvHaarDetectObjects'
facedetectZuhair.cpp:(.text+0x20e): undefined reference to `cvGetSeqElem'
facedetectZuhair.cpp:(.text+0x2f4): undefined reference to `cvRectangle'
facedetectZuhair.cpp:(.text+0x32c): undefined reference to `cvShowImage'
facedetectZuhair.cpp:(.text+0x337): undefined reference to `cvReleaseImage'
collect2: ld returned 1 exit status
Plz help me to proceed. Thanx in advance.
Hi! Are you sure you have set your environment variables according to step 7?
ReplyDeleteYup I have apparently done step 7 that is entering the command in the terminal and adding the lines in the bash file.... I don't know what part am i doing wrong. I guess there is some linking error...
ReplyDeleteUnfortunately, these instructions don't work for me. The compilation of OpenCV fails with the error:
ReplyDelete/tmp/opencv/modules/highgui/src/cap_ffmpeg_impl.hpp:1298:20: error: ‘url_fclose’ was not declared in this scope
/tmp/opencv/modules/highgui/src/cap_ffmpeg_impl.hpp: In member function ‘bool CvVideoWriter_FFMPEG::open(const char*, int, double, int, int, bool)’:
/tmp/opencv/modules/highgui/src/cap_ffmpeg_impl.hpp:1411:35: error: ‘av_set_parameters’ was not declared in this scope
/tmp/opencv/modules/highgui/src/cap_ffmpeg_impl.hpp:1415:35: error: ‘dump_format’ was not declared in this scope
/tmp/opencv/modules/highgui/src/cap_ffmpeg_impl.hpp:1442:15: warning: ‘int avcodec_open(AVCodecContext*, AVCodec*)’ is deprecated (declared at /usr/local/include/libavcodec/avcodec.h:3719) [-Wdeprecated-declarations]
/tmp/opencv/modules/highgui/src/cap_ffmpeg_impl.hpp:1442:36: warning: ‘int avcodec_open(AVCodecContext*, AVCodec*)’ is deprecated (declared at /usr/local/include/libavcodec/avcodec.h:3719) [-Wdeprecated-declarations]
/tmp/opencv/modules/highgui/src/cap_ffmpeg_impl.hpp:1479:42: error: ‘URL_WRONLY’ was not declared in this scope
/tmp/opencv/modules/highgui/src/cap_ffmpeg_impl.hpp:1479:52: error: ‘url_fopen’ was not declared in this scope
/tmp/opencv/modules/highgui/src/cap_ffmpeg_impl.hpp:1485:25: error: ‘av_write_header’ was not declared in this scope
make[2]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_ffmpeg.o] Error 1
make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
A couple of comments.
ReplyDeleteI've built linux from scratch several times and this methodology will work on any platform, and is accurate. However, do not use the snapshot of ffmpeg, because some of the headers changed and opencv does not recognize the deprecations (03/16/2012). I successfully used ffmpeg0.10. Also from the book learning OpenCV it states: "build and use a shared ffmpeg library," this is indicative as to why the build is successful with --enable-shared
The platform I am using is a Pandaboard running ubuntu 10.11. Chris, you probably used the snapshot those are the exact errors I was getting
I have to say - installing opencv 2.3.1 is such a pain in the neck.
ReplyDeleteSo many errors, such a lack of manuals on how to do it successfully - could not those guys take the time to come up with something well-packed, instead of spending 10 hours to achieve NOTHING.
I used the --enable-shared and --enable-pic options in both steps 3 and 4 and it worked.
Then when I go to install opencv 2.3.1 here is an error that I get:
Linking CXXshared 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.3.1] Error 1
make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
make: *** [all] Error 2
=====================
I thought that installing steps 3 and 4 ccessfully was gonna help me solve my problem but NO.
What is the point of doing such work and people killing themselves, frustrating themselves to death to use it.
It's weird :\ I find a little frustrating that I wrote the installation tutorial to help others avoiding all the problems I had and although most people manage to install opencv by following it (over 200 people read this tutorial every day and it's referred by several websites) some problems always appear to a few :\ Some people have managed to fix the errors by following the steps 1-3 from ozbots tutorial instead of step 2 which is something that I don't really understand because it's basically the same, but split into parts.. However, it may work for you as it worked with others.
ReplyDeleteHi! According to a recent comment by blog reader custom6109 it may be due to the version of ffmpeg. Try with ffmpeg0.10.
ReplyDeleteHi! Thanks a lot for your comment and for your suggestion regarding ffmpeg. I'll put a note on the post so that others will benefit from it ;) Btw, the pandaboard looks like a cool board :) Didn't knew about it yet ;)
ReplyDeleteAnd you say it right and I agree.. and that's exactly because of that pain that I wrote this tutorial.. but although it works for most users it still seems that it doesn't work for a few :\ Did you try to compile without --enable-shared and --enable-pic? Did you executed "make clean" before retrying with --enable-pic and --enable-shared? Another option to install opencv without any work is to instal ROS (Robot Operating System) but it will also install lots and lots of other stuff from ROS. The good thing is that OpenCV is completely integrated in the ROS installation. If you wish to try it see here: http://www.ros.org/wiki/electric/Installation/Ubuntu
ReplyDeleteOh I don't care at all buddy, if I get a lot of things that I don't need come with it - I just need this to install and work.
ReplyDeleteThis ROS - is it a completely separate OS like Ubuntu?
I did not run "make clean" in fact - I just deleted the whole ffmpeg0.8.10 directory, the step 3 directory and the build or release directory in opencv.
Does make clean do something more than what I am doing above?
Thank you very much for your immediate response, for you help. You are a beast :)
No. That ROS is just common software, not a full OS. Actually, the ROS architecture can also be used for lots of other purposes other than robots. That way the installation should work without any hassle. It will install you approximately 3GB of stuff. If you deleted the build and release folders then make clean wouldn't have done anything more than that.
ReplyDeleteI installed ROS but pkg config can not locate it:
ReplyDeletepkg-config opencv --libs --cflags
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
In their installation instructions they mention nothing about it.
And one more thing - does make clean have different implications than just deleting the directories I mentioned in the previous post.
Well I must say that OpenCV definitely doesn't like you :P Besides that error, did the installation of ROS finish without any errors? Also, how did you try to compile? Can you try to compile like this: g++ pkg-config --libs --cflags opencv opencvtest.cpp -o opencvtest
ReplyDeleteI don't like it either. I guess OpenCV was not meant for certain machines. Open Source hahahaha. Biggest joke ever. Just spent two days ... I would rather pay some money out of my pocket to have something stable ...
ReplyDeletethank you for tuto, it's great, really simple.
ReplyDeleteplease i need help, how to compile codes using gpu (like those on samples hog..)?
i installed cuda before.
thank you so much, i hope you'll help me
Hi! Thanks for your feedback! :) Unfortunately I never tried anything with gpu before :\ It's on my wishlist but I'm running short in time right now :\ when I get some free time I'll try to learn something about it. Sorry for not being able to help right now :\
ReplyDeleteYou are marvelous!!! I'd like to thank you for this specially for the configuration hint of 64-bit machines. keep up the good work. Your friend from Egypt.
ReplyDeleteThank you very much for your feedback! :D Happy programming with openCV! ;) Your friend from Portugal!
ReplyDeletethanks it works
ReplyDeleteYou're welcome :)
ReplyDeleteHi! I'll try to help, as I always try (which doesn't mean that I can actually find a solution for every error :P ). First it's weird that you are getting an error related to git when you're installing x264, which is unrelated. Are you sure you performed all the previous steps correctly? If you are using a x64 architecture don't forget to use the --enable-pic --enable-shared flags (as referred in step 3).
ReplyDeletehi i have just installed opencv 2.3.1 but i got this error..
ReplyDelete/usr/bin/ld: cannot find -lcv
/usr/bin/ld: cannot find -lhighgui
/usr/bin/ld: cannot find -lcvaux
collect2: ld returned 1 exit status
i dnt have any idea what to do.
plz help me.
Hi! Are you sure you performed steps 7 and 8 as described?
ReplyDeletehi thanx for the tutorial.....
ReplyDeletei was getting the same error as utkarah...
i included opencv_highgui instead if highgui in settings of eclipse.....
but then it stated giving me following errors:
/usr/bin/ld: ./run.o: undefined reference to symbol 'cvCreateMemStorage'
/usr/bin/ld: note: 'cvCreateMemStorage' is defined in DSO /usr/local/lib/libopencv_core.so.2.3 so try adding it to the linker command line
/usr/local/lib/libopencv_core.so.2.3: could not read symbols: Invalid operation
collect2: ld returned 1 exit status
thanks in advance....
Seems like a linker error. Did you configure the linker on Eclipse?
ReplyDeleteHi msaleiro,
Deleteyour blog is awesome..solved many problems of mine...:)
I am also getting same error like
/usr/bin/ld: ../../Soft/Build/targets_versions/linux_sdk_demo_PROD_MODE_vlib_Linux_3.5.0-17-generic_GNU_Linux_gcc_4.7.2/ardrone_testing_tool.o: undefined reference to symbol 'cvCircle'
/usr/bin/ld: note: 'cvCircle' is defined in DSO /usr/lib/libopencv_core.so.2.3 so try adding it to the linker command line
/usr/lib/libopencv_core.so.2.3: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status
make3: *** [/home/nikky/Desktop/tt/ARDrone_SDK_Version_1_7_20110525/Examples/Linux/micro_uav/Build/Release/ardrone_testing_tool] Error 1
make2: *** [all] Error 2
make1: *** [build_app] Error 2
make: *** [linux_sdk_demo] Error 2
nikky@nikky:~/Desktop/tt/ARDrone_SDK_Version_1_7_20110525/Examples/Linux/micro_uav/Build$
plzzzzzzz help me...thanks in advance... :)....... what do you mean by configuring the linker on eclipse????
Hi! Probably you need to set up the compiler/linker in eclipse. Try this link. It contains a few steps to configure Eclipse: http://wrahoolwrites.blogspot.pt/2012/01/setting-up-opencv-23-and-eclipse-on.html Hope it solves your problem :)
DeleteThank you so much for ur reply...but urs is not the correct solution... we need to add open cv flags and libs in makefile under generic_libs.... :)
DeleteHi! I'm glad you managed to fix it and thanks for coming back here to show the solution. I'm sure that others will learn from it :) Since I don't use Eclipse I didn't exactly knew what the problem was. I just thought that maybe it could solve your problem since before I started using CMake I had to configure similar settings in Codeblocks. Anyway, problem solved! :) Congratulations for solving it and sharing the solution! :)
DeleteHey! Nice tuto! I had some problem with your step 2, so I followed steps 1-3 of ozbots.
ReplyDeleteBtw, I installed OpenCV 2.4 by following your tutorial in my 32 bit Oneric laptop.
For testing, I wrote a simple code and it compiled without any errors. The output file is also created. I used the following command for compiling:
g++ `pkg-config --cflags opencv` helloWorld.cpp -o helloWorld `pkg-config --libs opencv`
And then the following error pops up when I try to run the output file:
mayank@mayank-laptop:~/Desktop/test$ ./helloWorld
./helloWorld: error while loading shared libraries: libopencv_core.so.2.4: cannot open shared object file: No such file or directory
Is there something wrong with the linux configuration?
Okay, it worked.. I had to add the following line after compiling and before running
ReplyDeleteexport LD_LIBRARY_PATH=/usr/local/lib
Even though I added it in the end of my bash.bashrc file, it doesn't seem to work.. I mean, I have to type it every time in the terminal.
Btw, during running, the following warning comes in:
(MyFirstWindow:2778): Gtk-WARNING **: Unable to locate theme engine in module_path: "pixmap",
Any idea what could it be for?
Hi! Thanks for the feedback, for testing with opencv 2.4 and for sharing the fixes you found :) Regarding your question about the GTK warning I'm afraid I can't help you much. It has been reported as a bug here: https://bugs.launchpad.net/ubuntu/+source/quickly/+bug/853232 Maybe you can find some useful information in the comments. Thanks!
ReplyDeleteHi to all
ReplyDeleteFirst of all thanks for the website, it is very interesting. I am new to linux and for me is very difficult to install opencv.
I already have problems on the first step, I can't install some packages:
E: No se ha podido localizar el paquete libpngwriter0-dev
E: No se ha podido localizar el paquete libpngwriter0c2
E: No se ha podido localizar el paquete libjpeg-prog
E: No se ha podido localizar el paquete libavcodec52
E: No se ha podido localizar el paquete libavformat52
(E: Could not find the package ...)
I have searched on google to solve the problems but I found that libpngwriter0-dev is obsolete, Is it possible?.
I saw it on this website:
https://launchpad.net/ubuntu/dapper/amd64/libpngwriter0-dev
What do you think?.
Hey arnoldpredator
ReplyDeleteEven I had the same trouble. Just follow the steps 1-3 of the ozbots tutorial.
It may be possible. Things in Linux are always changing.. it may be annoying sometimes but changes have to be made to improve Linux. Anyway, try to follow steps 1-3 from the ozbots tutorial. Some people say that using those steps they manage to install it. I really don't understand why because they're basically the same thing. Anyway, give it a try.
ReplyDeleteHi Mayank and msaleiro
ReplyDeleteI could not post before because I hadn't internet at home for some days.
I have read the ozbots tutorial but I get an error with this package:
libsdl1.2-dev
I can't install it because it depends on libpulse-dev, "but it is not going to be installed"
I have searched on google and perhaps it is a problem on my sources.list file, Could you show your sources.list file?. ANd I will copy it, or perhaps it is better to know what are the options that I must check to create the sources.list on this website:
http://repogen.simplylinux.ch/
Obviously I am assuming that the problem is on sources.list, but I am not sure.
Thanks for your answers.
Regards
Obviously my real name is santi, the other day I used arnoldpredator as a nickname.
ReplyDeleteHi
ReplyDeleteI feel a bit stupid for this error but I don't know how to solve it, when I try to install opencv I create a folder called release, then I enter on it with the console, but when I write the next order (cmake -D ...) I get this message:
The path to the source directory:
" /home/cristo/OpenCV-2.4.0-beta2/release/BUILD_EXAMPLES=ON
contains unsupported character '='.
Please use a different source directory name."
Is it normal? What should I change?.
I hope not to bother you with this stupid questions.
Thanks in advance.
Did you copy the entire command and pasted it exactly as written in the tutorial (including the ".." in the end of the command) ?
ReplyDeleteIn the ozlotz I did not find the exact command, I copied what you put in your blog:
ReplyDeletecmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON -D BUILD_EXAMPLES=ON
And it says that the path cannot have this symbol = , I don't know if I am doing it correctly.
Once again, did you include the space + two dots (" ..") in the end of the command?
ReplyDeleteHello again!
ReplyDeleteJust wanted to give a small update to all the guys wanting Kinect (OpenNI) support in OpenCV. For this you will need OpenNI, Sensor, SensorKinect and NITE. You will also need Java. So if anyone is interested, here is a small tutorial (do this between steps 1 & 2, and in a the same folder as you will later download FFMpeg and the rest of the packages):
------------------------------------------------------------
# JAVA support, do NOT do this if your "javac" command already works.
sudo apt-get install default-jre default-jdk
git clone https://github.com/OpenNI/OpenNI.git
git clone https://github.com/PrimeSense/Sensor.git
git clone https://github.com/avin2/SensorKinect.git
wget http://www.openni.org/downloads/nite-bin-linux-x64-v1.5.2.21.tar.bz2
tar xvjf nite-bin-linux-x64-v1.5.2.21.tar.bz2
cd OpenNI/Platform/Linux/CreateRedist
bash RedistMaker
cd ../Redist/OpenNI-Bin-Dev-Linux-x64-v1.5.2.23
sudo sh install.sh
cd ../../../../../Sensor/Platform/Linux/CreateRedist
bash RedistMaker
cd ../Redist/Sensor-Bin-Linux-x64-v5.1.0.41
sudo sh install.sh
cd ../../../../../SensorKinect/Platform/Linux/CreateRedist
bash RedistMaker
cd ../Redist/Sensor-Bin-Linux-x64-v5.1.0.25
sudo sh install.sh
cd ../../../../..
cd NITE-Bin-Dev-Linux-x64-v1.5.2.21
sudo bash install.sh
cd ..
------------------------------------------------------------
One more thing, and you are done. When you are running the "cmake" command, when configuring OpenCV, add this "-D WITH_OPENNI=ON" you can add it after "-D CMAKE_BUILD_TYPE=RELEASE" if you want.
------------------------------------------------------------
Here are also some other tips (do this between steps 1-2, or before installing OpenNI):
TBB, Eigen & swscale support (+ some other stuff):
sudo apt-get install libopencore-amrnb-dev libtbb-dev libtbb2 libeigen2-dev libopenexr-dev libusb-1.0-0-dev freeglut3-dev doxygen graphviz libswscale-dev
If you get a warning while configuring x264, saying:
"Warning: libavformat is not supported without swscale support"
You can fix this by installing "libswscale-dev" (included in the apt-get install above)
------------------------------------------------------------
I have also tried to install OpenCV 2.3.1 with some newer libraries then what was mentioned in the tutorial, and these libs versions seems to work fine for me:
x264: x264-snapshot-20120501-2245-stable
FFMpeg: 0.10.2
v4l: 0.8.8
Just a quick follow up, you might need some of the packages described in the 4th paragraph to get OpenNI to work. Just to be sure, if you are going to use OpenNI, install those packages as well. Also, I'm using libjpeg62, instead of libjpeg8, if this would make any difference.
ReplyDeleteAnd lastly, in the OpenCV configuration (cmake), you don't need to include "BUILD_PYTHON_SUPPORT=ON", instead, change this to "BUILD_NEW_PYTHON_SUPPORT=ON", as the "old" support is included automagically.
Have Fun.
Hi! Thank you very much for your contribution! I'm sure it will help others :) Now I've been a little short on time but when I get some time maybe I'll write a post dedicated to OpenNI in OpenCV using the info you posted (giving you all the credits for the info, of course :) )
ReplyDelete[...] is the tutorial I followed:http://thebitbangtheory.wordpress.com/2011/10/23/how-to-install-opencv-2-3-1-in-ubuntu-11-10-oneiric... I think the problem is ffmpeg, the version I used is 0.8.10, and I installed it in /usr and enabled [...]
ReplyDeleteHello,
ReplyDeleteYour tutorial is GREAT ,, even though I got some trouble finding these package:
libfaac-dev
libmp3lame-dev
python-numpy libpython2.7 python-dev python2.7-dev
libjpeg-dev
I m on Linux Debian
As I didn'nt really need them, I just skip them and it is working fine
Thanks :)
Hi! Since this tutorial is a mix of two different tutorials it is possible that some packages from one of the tutorials might be out of date or merged into other packages Thanks for your comment and feedback! :)
ReplyDeleteAn amazing 'HOW-TO'.... Helped me get through the process with relative ease... Thank you... and ur feedback to the comments helped me debug a lot of issues
ReplyDeleteThanks! :)
ReplyDeleteThis comment has been removed by the author.
DeleteHello Again,
ReplyDeleteWell, I have had OpenCV2.4.3 installed in Ubuntu 12.04. Now I would like to install the new python support in it. So, how do I do that?
Hi Max. I have not installed Opencv2.4.3 yet so I'm not sure what to tell you about it :\ Have you tried typing "import cv" or "import cv2" in the python console to check if it works by default?
Delete