Note for English Readers

If I write the articles in Indonesian, I will write a summary in English so that you can read my articles too. After you read the summary and you feel that you need more information about that, please do not hesitate to contact me via e-mail that can be found in my profile.

Thank you for reading my blogs.

Monday, October 12, 2009

Kompilasi dan Instalasi OpenCV 2.0.0 pada Linux -- Compiling & Installing OpenCV 2.0.0 on Linux --

Seperti yang telah saya janjikan pada tulisan sebelumnya, sekarang saya ingin membagikan pengalaman saya saat melakukan kompilasi dan instalasi OpenCV 2.0.0 di laptop saya. Distro Linux yang saya gunakan adalah Slackware64 13.0, tapi, menurut saya, pengalaman saya ini merupakan pengalaman untuk Linux secara umum, tidak tergantung distro. OK, kita mulai ...

Langkah pertama, sudah pasti, kita harus memastikan semua dependencies dari OpenCV 2.0.0 telah terinstall dengan baik pada PC/Laptop kita. Biasanya, untuk OpenCV, saya inginnya yang lengkap. Ada beberapa program yang merupakan dependencies dari OpenCV 2.0.0 yang "harus ada" (menurut kebutuhan dan mau saya), antara lain: xinelib, ffmpeg, libdc1394, v4l, swig, python, libjpeg, zlib, libpng, libtiff, libjasper. Untuk Slackware/Slackware64 13.0, beberapa dependencies seperti xinelib, swig, python, libjpeg, zlib, libpng, libtiff, dan libjasper telah terinstall; saya hanya perlu menambahkan ffmpeg, libdc1394, dan v4l. Mengenai cara mencari dan menambahkan dependencies, silakan dibaca pada manual distro masing-masing.

Setelah semua dependencies sudah terinstall, langkah kedua adalah kompilasi OpenCV 2.0.0. Untuk versi 2.0.0 ini, ada 2 cara kompilasi, yang pertama, cara klasik, menggunakan configure dan make; cara yang kedua adalah menggunakan cmake dan make. Saya telah mencoba kedua cara tersebut. Untuk yang menggunakan cmake, sebenarnya cara ini lebih mudah dan user-friendly (sejauh yang saya rasakan) tapi saat saya coba, setelah 85% proses kompilasi, muncul error.

# cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON -D BUILD_LATEX_DOCS=ON ..

Jika tidak ada error, lalu:

# make

Error yang muncul:

...
Linking CXX shared library ../../lib/libcvaux.so
[ 84%] Built target cvaux
Scanning dependencies of target cvhaartraining
[ 84%] Building CXX object apps/haartraining/CMakeFiles/cvhaartraining.dir/cvboost.o
[ 84%] Building CXX object apps/haartraining/CMakeFiles/cvhaartraining.dir/cvcommon.o
[ 85%] Building CXX object apps/haartraining/CMakeFiles/cvhaartraining.dir/cvhaarclassifier.o
[ 85%] Building CXX object apps/haartraining/CMakeFiles/cvhaartraining.dir/cvhaartraining.o
[ 85%] Building CXX object apps/haartraining/CMakeFiles/cvhaartraining.dir/cvsamples.o
Linking CXX static library ../../lib/libcvhaartraining.a
[ 85%] Built target cvhaartraining
Scanning dependencies of target createsamples
[ 85%] Building CXX object apps/haartraining/CMakeFiles/createsamples.dir/createsamples.o
Linking CXX executable ../../bin/opencv_createsamples
../../lib/libhighgui.so.2.0.0: undefined reference to `cvCreateCameraCapture_V4L(int)'
collect2: ld returned 1 exit status
make[2]: *** [bin/opencv_createsamples] Error 1
make[1]: *** [apps/haartraining/CMakeFiles/createsamples.dir/all] Error 2
make: *** [all] Error 2

Sampai sekarang, saya masih belum tahu sebabnya. Saya telah menanyakan ke forum OpenCV, belum ada jawaban, mungkin tidak ada yang mengalaminya, karena jika saya amati dari respon anggota forum, mayoritas bukan pengguna Linux.
Akhirnya, saya pakai cara klasik:

$ ./configure --with-xine --with-ffmpeg --with-1394libs --with-v4l --with-gtk --without-quicktime --enable-sse --with-swig --with-python --with-gthread

Jika tidak ada error, lalu:

$ make

Kompilasi sukses.

Langkah ketiga, install hasil kompilasi tersebut menggunakan make install. Pastikan Anda telah menjadi root user atau superuser saat menginstall:

# make install

Langkah terakhir adalah mencoba OpenCV 2.0.0. Kebetulan, 2 tahun lalu, saya pernah menulis di blog ini tentang cara membuat program dengan library OpenCV pada Linux. Program-program tersebut saya coba untuk di-compile ulang menggunakan library OpenCV versi 2.0.0 dan hasil kompilasinya dapat berjalan mulus pada laptop saya. Sekedar mengingatkan, cara kompilasi menggunakan library OpenCV adalah sebagai berikut:

$ g++ -Wall [nama_file].cpp -o [nama_file_output] `pkg-config opencv --cflags --libs`

Contoh:

$ g++ -Wall trial1.cpp -o trial1 `pkg-config opencv --cflags --libs`


Referensi:


Summary:
This article describes about compiling and installing OpenCV on Linux in general, not depending on Linux distros. All writings of this article are based on reference at OpenCV wiki site that you can find the link on Referensi. There are 4 steps that I've been worked that I will discuss.

First, make sure all dependencies of OpenCV have been installed properly. By my experience, I need xinelib, ffmpeg, libdc1394, v4l, swig, python, libjpeg, zlib, libpng, libtiff, and libjasper. For how to add dependencies, please consult to each distro's manual.

Second, compiling OpenCV. There are 2 methods, classical method (configure then make) and cmake method. When I tried cmake method using this command:

# cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON -D BUILD_LATEX_DOCS=ON ..

I found an error when the process has been 85% finished.

...
Linking CXX shared library ../../lib/libcvaux.so
[ 84%] Built target cvaux
Scanning dependencies of target cvhaartraining
[ 84%] Building CXX object apps/haartraining/CMakeFiles/cvhaartraining.dir/cvboost.o
[ 84%] Building CXX object apps/haartraining/CMakeFiles/cvhaartraining.dir/cvcommon.o
[ 85%] Building CXX object apps/haartraining/CMakeFiles/cvhaartraining.dir/cvhaarclassifier.o
[ 85%] Building CXX object apps/haartraining/CMakeFiles/cvhaartraining.dir/cvhaartraining.o
[ 85%] Building CXX object apps/haartraining/CMakeFiles/cvhaartraining.dir/cvsamples.o
Linking CXX static library ../../lib/libcvhaartraining.a
[ 85%] Built target cvhaartraining
Scanning dependencies of target createsamples
[ 85%] Building CXX object apps/haartraining/CMakeFiles/createsamples.dir/createsamples.o
Linking CXX executable ../../bin/opencv_createsamples
../../lib/libhighgui.so.2.0.0: undefined reference to `cvCreateCameraCapture_V4L(int)'
collect2: ld returned 1 exit status
make[2]: *** [bin/opencv_createsamples] Error 1
make[1]: *** [apps/haartraining/CMakeFiles/createsamples.dir/all] Error 2
make: *** [all] Error 2

Until now, I still don't know how to solve it. There is no response from OpenCV forum, perhaps, nobody got this error when compiling OpenCV 2.0.0.

I switched the method using classical method:

$ ./configure --with-xine --with-ffmpeg --with-1394libs --with-v4l --with-gtk --without-quicktime --enable-sse --with-swig --with-python --with-gthread

If no error, lalu:

$ make

I found no error until compilation finished.

Third, install the compiled OpenCV using (note: make sure you have been a root user or superuser when execute this command):

# make install

The last step is try to make a simple program that needs OpenCV library then compile it using:

$ g++ -Wall [input_file].cpp -o [output_file] `pkg-config opencv --cflags --libs`

2 comments:

infoGue said...

Hai, salam kenal, artikel anda ada di

sini

ayo gabung bersama kami dan promosikan artikel anda ke semua pembaca. Terimakasih ^_^

Masoud_mj said...

Use this cmake code:
cmake -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=OFF -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON .