OpenCV 2.4.0 was released this May providing, a lot of improvements and bug fixes. For a complete change log see here.
This post will hopefully make your life easier to configure, compile, install and test it out.
This time I tried to categorize and explain the dependencies, so that it is easier to configure it for your needs. As always, comments and suggestions are welcome.
Ubuntu 12.04 provides a package of OpenCV 2.3.1 that you can easily install by typing:
Essentials
These are libraries and tools required by OpenCV.
You should see something like that:
Note that some failures when testing other modules may come from missing image files. To correctly run these tests or samples you should move the corresponding image files from OpenCV-2.4.0/samples to OpenCV-2.4.0/build/bin.
For testing that you can compile your own programs and link against the installed OpenCV libraries I have packaged the face detection sample with all the necessary files and a simple Makefile. Download it here, extract and type:
This post will hopefully make your life easier to configure, compile, install and test it out.
This time I tried to categorize and explain the dependencies, so that it is easier to configure it for your needs. As always, comments and suggestions are welcome.
Ubuntu 12.04 provides a package of OpenCV 2.3.1 that you can easily install by typing:
sudo apt-get install libopencv-devIf you do not care about having the latest version you could skip the rest of the post.
Install Dependencies
Essentials
These are libraries and tools required by OpenCV.
sudo apt-get install build-essential checkinstall cmake pkg-config yasm
Image I/O
Libraries for reading and writing various image types. If you do not install then the versions supplied by OpenCV will be used.
sudo apt-get install libtiff4-dev libjpeg-dev libjasper-dev
Video I/O
You need some or all of these packages to add video capturing/encoding/decoding capabilities to the highgui module.
You need some or all of these packages to add video capturing/encoding/decoding capabilities to the highgui module.
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev
Python
Packages needed to build the Python wrappers.
Packages needed to build the Python wrappers.
sudo apt-get install python-dev python-numpy
Other third-party libraries
Install Intel TBB to enable parallel code in OpenCV.
Install Intel TBB to enable parallel code in OpenCV.
sudo apt-get install libtbb-dev
GUI
The default back-end for highgui in Linux is GTK. You can optionally install QT instead of GTK and later enable it in the configuration (see next section).
The default back-end for highgui in Linux is GTK. You can optionally install QT instead of GTK and later enable it in the configuration (see next section).
sudo apt-get install libqt4-dev libgtk2.0-dev
Compile and Install
Get a copy of the source code here, extract and create a build directory:tar -xvf OpenCV-2.4.0.tar.bz2 cd OpenCV-2.4.0/ mkdir build cd buildConfigure using CMake. You have a lot of options in this step. This is what I use:
cmake -D WITH_QT=ON -D WITH_XINE=ON -D WITH_OPENGL=ON -D WITH_TBB=ON -D BUILD_EXAMPLES=ON ..Notice, that by adding the -D WITH_QT=ON, the highgui module will use QT instead of GTK. If you want to go with GTK just remove this. For more information on the options, look at the CMakeLists.txt file. When you are happy with the configuration you have, you can start compiling:
makeIf compilation finishes without errors, you can install by saying:
sudo make installFinally, make sure that your programs can link to the OpenCV library in run-time by adding the following line at the end of your /etc/ld.so.conf:
/usr/local/libAnd then configure dynamic linker run-time bindings:
sudo ldconfig
Testing
An easy way to test that the compilation went well is to use the OpenCV test utilities. For example, to test the core module go to OpenCV-2.4.0/build/bin and run:./opencv_test_core
Note that some failures when testing other modules may come from missing image files. To correctly run these tests or samples you should move the corresponding image files from OpenCV-2.4.0/samples to OpenCV-2.4.0/build/bin.
For testing that you can compile your own programs and link against the installed OpenCV libraries I have packaged the face detection sample with all the necessary files and a simple Makefile. Download it here, extract and type:
makeThis should compile and run with a test image, so you should see something like this:



make -D WITH_QT=ON -D WITH_XINE=ON -D WITH_OPENGL=ON -D WITH_TBB=ON -D BUILD_EXAMPLES=ON ..
ReplyDeleteshould be:
cmake -D WITH_QT=ON -D WITH_XINE=ON -D WITH_OPENGL=ON -D WITH_TBB=ON -D BUILD_EXAMPLES=ON ..
Thank you Alex
ReplyDeletemakefile doesn't work for the demo program in the last step
ReplyDeleteHey Ayush,
ReplyDeleteI noticed I packed the binary in the zip file and it created problems. The link is now fixed. Let me know if it works for you. If not, please post the error you get.
Works for me. Newb OpenCV developer here.
ReplyDeleteReally handy! Thank you very much. :)
ReplyDeleteHi
ReplyDeletewhile executing make , i got the following build message , any idea?
[ 6%] Building CXX object modules/imgproc/CMakeFiles/opencv_imgproc.dir/src/rotcalipers.cpp.o
/home/OpenCV-2.4.0/modules/imgproc/src/rotcalipers.cpp: In function ‘CvBox2D cvMinAreaRect2(const CvArr*, CvMemStorage*)’:
/home/OpenCV-2.4.0/modules/imgproc/src/rotcalipers.cpp:331:33: warning: ‘*((void*)& buffer +16)’ may be used uninitialized in this function [-Wuninitialized]
/home/OpenCV-2.4.0/modules/imgproc/src/rotcalipers.cpp:97:10: note: ‘*((void*)& buffer +16)’ was declared here
/home/OpenCV-2.4.0/modules/imgproc/src/rotcalipers.cpp:328:33: warning: ‘*((void*)& buffer +8)’ may be used uninitialized in this function [-Wuninitialized]
/home/OpenCV-2.4.0/modules/imgproc/src/rotcalipers.cpp:97:10: note: ‘*((void*)& buffer +8)’ was declared here
/home/OpenCV-2.4.0/modules/imgproc/src/rotcalipers.cpp:318:52: warning: ‘*((void*)& buffer +20)’ may be used uninitialized in this function [-Wuninitialized]
/home/OpenCV-2.4.0/modules/imgproc/src/rotcalipers.cpp:97:10: note: ‘*((void*)& buffer +20)’ was declared here
/home/OpenCV-2.4.0/modules/imgproc/src/rotcalipers.cpp:317:87: warning: ‘*((void*)& buffer +4)’ may be used uninitialized in this function [-Wuninitialized]
/home/OpenCV-2.4.0/modules/imgproc/src/rotcalipers.cpp:97:10: note: ‘*((void*)& buffer +4)’ was declared here
/home/OpenCV-2.4.0/modules/imgproc/src/rotcalipers.cpp:317:52: warning: ‘buffer’ may be used uninitialized in this function [-Wuninitialized]
/home/OpenCV-2.4.0/modules/imgproc/src/rotcalipers.cpp:97:10: note: ‘buffer’ was declared here
/home/OpenCV-2.4.0/modules/imgproc/src/rotcalipers.cpp:314:30: warning: ‘*((void*)& buffer +12)’ may be used uninitialized in this function [-Wuninitialized]
/home/OpenCV-2.4.0/modules/imgproc/src/rotcalipers.cpp:97:10: note: ‘*((void*)& buffer +12)’ was declared here
[ 7%] Building CXX object modules/imgproc/CMakeFiles/opencv_imgproc.dir/src/phasecorr.cpp.o
[ 7%] Building CXX object modules/imgproc/CMakeFiles/opencv_imgproc.dir/src/geometry.cpp.o
I only see warnings in what you posted. Was there an error?
ReplyDelete@sateeshkg
ReplyDeleteI guess the uninitialized buffer makes this error/warning.
Initializing the buffer after creation removes the error.
buffer is in modules/imgproc/src/rotcalipers.cpp line 97
But I got this message with codeblocks. no errors with gnu make
I added
memset((void *)(buffer), 0x00, 32);
Awesome.. I didn't have libgtk2.0-dev and pkg-config, as I chose to go with GTK I encountered a small error when running ur sample program..
ReplyDeleteOtherwise everything went very well.. Thanks for the great tutorial..
Hi, it is possible install opencv 2.4 in ubuntu 11.04 with the above steps? thanks.
ReplyDeleteThanx for the tutorial!
ReplyDeleteIt worked in the end, but not exactly as mentioned.
The library was installed at /usr/local/lib/
so in the beginning I couldn't compile the example.
(I thought that the files would be installed at /usr/local/lib/openCV or sth similar)
Then I added (at the LIBS +=) -L/usr/local/lib/, and everything worked.
dimitris
Thank you very much. A long time I'm trying install OpenCV-2.4 but always had errors.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
Deletethanks Laz...
ReplyDeleteGreat and clear tutorial...
Great and simple tutorial
ReplyDeletethanks LAZ
Thank you very much for such easy steps! Tried for the first time in life n it worked really fine. Got the face recognition image as was in the web. Thanks again for the great help!
ReplyDeleteYoo !
ReplyDeleteTried a couple of tutorials and this one did the trick !! Thanks !
I'm really glad you guys find it useful
ReplyDeletethank you so much!
ReplyDeleteYou saved my day. Thank you!
ReplyDeletei am new in c++ and opencv..
ReplyDeletewill you please help me to run a open cv program in ubuntu 12.10 that i wrote to load an image.
Thanks..
If you installed opencv, then all you have to do is write a makefile and compile your simple program. You can use the makefile I provide above.
DeleteI got error:
ReplyDeleteIllegal instruction (core dumped)
make: *** [run] Error 132
This error happen when I try to run a sample or your example with faceDetect
Any idea what I can do so I can ran the samples?
Thanks
I am sorry but this doesn't give me enough information. Can you post the whole make output?
DeleteWorked perfectly, first time (installed on a fresh copy of Xubuntu 12.04 LTS). Thank you for posting this, as it is the clearest and most current documentation I've seen.
ReplyDeleteI'm glad I could help, Michael
DeleteI got the error:
ReplyDeletefaceDetect.cpp:1:43: fatal error: opencv2/object/objdetect.hpp: no such files
This was just solved by moving the files from /modules to /include/opencv2/ and adding -I/home/...(the directory of .cpp files) in Makefile, i.e., g++ -I/home/... blablabla
DeleteMy current problem is:
ReplyDeleteg++ faceDetect.cpp -I/home/johnestar/CV/OpenCV-2.4.0/include -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_objdetect -o faceDetect
/usr/bin/ld: cannot find -lopencv_core
/usr/bin/ld: cannot find -lopencv_imgproc
/usr/bin/ld: cannot find -lopencv_highgui
/usr/bin/ld: cannot find -lopencv_objdetect
collect2: ld returns 1
Could you help me? I've passed ./opencv_test_core
Please,tell me your method:Use opencv and qt everywhere to build your project for KIT ARM (example: friendlyARM mini2440,tiny210...).Thanks
ReplyDeleteI did all steps but there is problem ;
ReplyDeleteDescription Resource Path Location Type
Function 'cvDestroyWindow' could not be resolved main.cpp /deneme1/src line 19 Semantic Error
make: *** [src/main.o] Hata 1 deneme1 C/C++ Problem
Function 'cvReleaseImage' could not be resolved main.cpp /deneme1/src line 18 Semantic Error
Function 'cvWaitKey' could not be resolved main.cpp /deneme1/src line 17 Semantic Error
Function 'cvShowImage' could not be resolved main.cpp /deneme1/src line 16 Semantic Error
Symbol 'CV_WINDOW_AUTOSIZE' could not be resolved main.cpp /deneme1/src line 15 Semantic Error
Function 'cvNamedWindow' could not be resolved main.cpp /deneme1/src line 15 Semantic Error
Function 'cvLoadImage' could not be resolved main.cpp /deneme1/src line 14 Semantic Error
Type 'IplImage' could not be resolved main.cpp /deneme1/src line 14 Semantic Error
Symbol 'cv' could not be resolved main.cpp /deneme1/src line 11 Semantic Error
it is about cv and whan can I do :/
I suspect that this error is Eclipse related. Are you using Eclipse? Did you try to Google it?
DeleteThank you very much for the post!! I had no problems installing opencv following this guide.
ReplyDeleteGlad to hear, Fedra
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteI am in "build" and when i Configure Cmake , it says "cmake-D" command not found
ReplyDeletekindly help in this regard
Did you install cmake? Maybe you skipped this part:
Deletesudo apt-get install build-essential checkinstall cmake pkg-config yasm
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteEven , i went for this too , but this also stucks in cmake step
ReplyDeletehttp://www.raben.com/book/export/html/3
Kindly Help
@Rida Nisar: Please be careful while following instructions. Your first error was trying to untar the wrong file. Then you mistyped "make-D" instead of "make -D". Finally, the string "BUILD_EXAMPLES=ON.." is not supposed to be part of the path, but part of the input arguments to cmake. I would have to assume that you mistyped something again (probably skipped a space).
ReplyDeletePlease, avoid flooding the comment section. Try to only post something that will also help other people.
Very helpful. Thanks!!!
ReplyDeleteThank you so much Laz
ReplyDeleteHowever, I have problems.
At first install trial, it works well.
Test completed successfully.
However,
when I enter this,
$./facedetect.py (this is in the sample folder)
Traceback (most recent call last):
File "./facedetect.py", line 10, in
import cv2.cv as cv
ImportError: /usr/lib/i386-linux-gnu/libQtTest.so.4: undefined symbol: _ZN9QListData11detach_growEPii
And,
$ ./touching_object.py
Traceback (most recent call last):
File "./touching_object.py", line 5, in
from all_module import *
File "/home/gibeom/NAO/nao_murata/all_module.py", line 22, in
import cv
File "/usr/local/lib/python2.7/dist-packages/cv.py", line 1, in
from cv2.cv import *
ImportError: /usr/lib/i386-linux-gnu/libQtTest.so.4: undefined symbol: _ZN9QListData11detach_growEPii
This error message's printed
So I search the web, but I can't find answer.
Of course,
DeleteI also did it
Finally, make sure that your programs can link to the OpenCV library in run-time by adding the following line at the end of your /etc/ld.so.conf:
/usr/local/lib
And then configure dynamic linker run-time bindings:
sudo ldconfig
Below is my ld.so.conf
include /etc/ld.so.conf.d/*.conf
/usr/local/lib
Is there anything more that I have to do to point the PATH? I don't what is the problem.
I tried remove libQtTest.so.4
But he just printed I can't find libQtTest.so.4
Therefore, I try to uninstall
ReplyDeletesudo apt-get remove OpenCV-2.4.0
It didn't work
So try ./cmake_uninstall.cmake (in build folder)
It didn't work.
~/opencv/OpenCV-2.4.0/build$ ./cmake_uninstall.cmake
./cmake_uninstall.cmake: line 5: syntax error near unexpected token `NOT'
./cmake_uninstall.cmake: line 5: `IF(NOT EXISTS "/home/gibeom/opencv/OpenCV-2.4.0/build/install_manifest.txt")'
make clean did something but it seemed not working.
folder and file exist.
Anyway, I try to re-install opencv
ReplyDeleteBut, It printed error message
[ 22%] Building CXX object modules/imgproc/CMakeFiles/opencv_perf_imgproc.dir/perf/perf_precomp.cpp.o
Linking CXX executable ../../bin/opencv_perf_imgproc
/usr/lib/i386-linux-gnu/libQtOpenGL.so.4: undefined reference to `QTextureGlyphCache::populate(QFontEngine*, int, unsigned int const*, QFixedPoint const*)'
/usr/lib/i386-linux-gnu/libQtOpenGL.so.4: undefined reference to `QTextureGlyphCache::fillInPendingGlyphs()'
../../lib/libopencv_highgui.so.2.4.0: undefined reference to `QMutex::unlockInternal()'
/usr/lib/i386-linux-gnu/libQtOpenGL.so.4: undefined reference to `QStaticTextItem::setFontEngine(QFontEngine*)'
/usr/lib/i386-linux-gnu/libQtOpenGL.so.4: undefined reference to `QPaintEngineEx::drawPixmapFragments(QRectF const*, QRectF const*, int, QPixmap const&, QFlags)'
/usr/lib/i386-linux-gnu/libQtOpenGL.so.4: undefined reference to `QImageTextureGlyphCache::createTextureData(int, int)'
../../lib/libopencv_highgui.so.2.4.0: undefined reference to `QMutex::lockInternal()'
/usr/lib/i386-linux-gnu/libQtOpenGL.so.4: undefined reference to `QRadialGradient::focalRadius() const'
/usr/lib/i386-linux-gnu/libQtOpenGL.so.4: undefined reference to `QRadialGradient::centerRadius() const'
/usr/lib/i386-linux-gnu/libQtOpenGL.so.4: undefined reference to `QWidgetPrivate::hasHeightForWidth() const'
/usr/lib/i386-linux-gnu/libQtOpenGL.so.4: undefined reference to `QImageTextureGlyphCache::fillTexture(QTextureGlyphCache::Coord const&, unsigned int, QFixed)'
/usr/lib/i386-linux-gnu/libQtOpenGL.so.4: undefined reference to `QTextureGlyphCache::textureMapForGlyph(unsigned int, QFixed) const'
/usr/lib/i386-linux-gnu/libQtOpenGL.so.4: undefined reference to `QPixmapData::toImage(QRect const&) const'
/usr/lib/i386-linux-gnu/libQtOpenGL.so.4: undefined reference to `qt_painterPathFromVectorPath(QVectorPath const&)'
/usr/lib/i386-linux-gnu/libQtOpenGL.so.4: undefined reference to `QTextureGlyphCache::subPixelPositionForX(QFixed) const'
/usr/lib/i386-linux-gnu/libQtOpenGL.so.4: undefined reference to `QMetaType::registerTypedef(char const*, int)'
ReplyDelete/usr/lib/i386-linux-gnu/libQtOpenGL.so.4: undefined reference to `QStaticTextItem::~QStaticTextItem()'
/usr/lib/i386-linux-gnu/libQtOpenGL.so.4: undefined reference to `QImageTextureGlyphCache::glyphMargin() const'
/usr/lib/i386-linux-gnu/libQtOpenGL.so.4: undefined reference to `QListData::detach_grow(int*, int)'
/usr/lib/i386-linux-gnu/libQtOpenGL.so.4: undefined reference to `QGraphicsSystem::platformExtension()'
../../lib/libopencv_highgui.so.2.4.0: undefined reference to `QRadioButton::minimumSizeHint() const'
/usr/lib/i386-linux-gnu/libQtOpenGL.so.4: undefined reference to `QWindowSurface::QWindowSurface(QWidget*, bool)'
/usr/lib/i386-linux-gnu/libQtOpenGL.so.4: undefined reference to `QGraphicsSystem::createPixmapData(QPixmapData*)'
/usr/lib/i386-linux-gnu/libQtOpenGL.so.4: undefined reference to `QBezier::toPolygon(double) const'
/usr/lib/i386-linux-gnu/libQtOpenGL.so.4: undefined reference to `vtable for QImageTextureGlyphCache'
../../lib/libopencv_highgui.so.2.4.0: undefined reference to `QListData::detach(int)'
/usr/lib/i386-linux-gnu/libQtTest.so.4: undefined reference to `QElapsedTimer::msecsSinceReference() const'
/usr/lib/i386-linux-gnu/libQtOpenGL.so.4: undefined reference to `QImage::constBits() const'
/usr/lib/i386-linux-gnu/libQtTest.so.4: undefined reference to `QElapsedTimer::start()'
/usr/lib/i386-linux-gnu/libQtOpenGL.so.4: undefined reference to `QImageData::convertInPlace(QImage::Format, QFlags)'
/usr/lib/i386-linux-gnu/libQtOpenGL.so.4: undefined reference to `qt_isExtendedRadialGradient(QBrush const&)'
../../lib/libopencv_highgui.so.2.4.0: undefined reference to `QCheckBox::minimumSizeHint() const'
/usr/lib/i386-linux-gnu/libQtOpenGL.so.4: undefined reference to `typeinfo for QImageTextureGlyphCache'
/usr/lib/i386-linux-gnu/libQtOpenGL.so.4: undefined reference to `QPaintEngineEx::drawPixmapFragments(QPainter::PixmapFragment const*, int, QPixmap const&, QFlags)'
/usr/lib/i386-linux-gnu/libQtOpenGL.so.4: undefined reference to `QImageTextureGlyphCache::resizeTextureData(int, int)'
/usr/lib/i386-linux-gnu/libQtTest.so.4: undefined reference to `QElapsedTimer::elapsed() const'
/usr/lib/i386-linux-gnu/libQtOpenGL.so.4: undefined reference to `QPaintEngineEx::drawStaticTextItem(QStaticTextItem*)'
collect2: error: 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
How can I remove and re-install that thing.
And How can I solve import-cv and
undefined symbol.
Thank you very much again
Hey, after going through some 10 tutorials, finally got one that works. thanks a lot. Btw do you also have some instruction on how to install in Mac OS X. Please let me know if you have any. Great work
ReplyDeletehi,
ReplyDeletei have the some issues with he part :
>>Finally, make sure that your programs can link to the OpenCV library >>in run-time by adding the following line at the end of your
>>/etc/ld.so.conf:
>>/usr/local/lib
my problem is, when i go inside to /etc/ld.so.conf by vi
i get this error:
<< "/etc/ld.so.conf" E212: Can't open file for writing
-- kindly provide a solution , thanks in advance
cvUpdateBGStatModel() function is not working in the ubuntu 12.04LTS. opencv version is 2.3.1
ReplyDeletecompiler doesn't return any error and BG model is NOT updating. what to do???? plz reply
How to get MJPG stream video from android IPWebcam using opencv
ReplyDeleteI am using the IP Webcam program on android and receiving it on my PC by WiFi. What I want is to use opencv in Visual Studio, C++, to get that video stream, there is an option to get MJPG stream by the following URL: http://MyIP:port/videofeed How to get it using opencv?
Please direct questions about using OpenCV to the OpenCV mailing list. This post is about compiling and installing OpenCV.
ReplyDeleteThank you
Thanks alot for tutorial, very simple to do, btw i get following error when executing opencvtest:
ReplyDelete[----------] Global test environment tear-down
[==========] 109 tests from 85 test cases ran. (186339 ms total)
[ PASSED ] 108 tests.
[ FAILED ] 1 test, listed below:
[ FAILED ] Core_InputOutput.misc
Can anybody help me, tried to google it but no many explanations what is this, btw, I could successfully compile facedetection girl.
Regards Denis.
Hi Laz !
ReplyDeleteCan you tell me how to build Opencv-2.4 on windows 7 64bituse Microsoft visual Studio 2010 ?
Thanks!
Hi,
Deletethere's plenty of posts to help you on that. Do a Google search.
Hey guys!
ReplyDeleteCould you tell me how to extract the video capture as an output? If not, how to extract the frames captured?
Thank you very much in advanced for your help!
Thanks! :)
ReplyDeleteThanks for the tutorial, finally it's work :)
ReplyDeletebut, if i wanna use opencv on codeblocks, how is the step? i have already trying the tutorial from opencv site, its not work properly, do you have any idea?
and
if i want to remove/uninstall all installed program even all the library, how is the command? my friend ask it to me.
thanks 4 adv
and 1 more, i'm newbie in opencv, i have tried to make a simple program like this (copy from site) :
Delete#include
#include
int main() {
cv::Mat image = cv::imread("image.jpg");
cv::namedWindow("test one");
cv::imshow("test one", image);
cv::waitKey(500);
return 1;
}
then i call it using :
g++ -o tes tes.cpp 'pkg-config opencv --cflags --libs'
why it show error : no such file or directory? am i wrong? please give me solution..
thanks :)