1. ก่อนอื่นติดตั้ง package ที่จำเป็นดังนี้
sudo apt-get install g++
libgtk2.0-dev
2. จากนั้นทำการติดตั้ง package ดังต่อไปนี้
libcv4
libcv-dev
libcvaux4
libcvaux-dev
libhighgui4
libhighgui-dev
opencv-doc
(‘python-opencv’ not required)
3. จากนั้นทดลองทำการบันทึกไฟล์ hello.cpp ไว้ทดสอบ
[code lang=”c”]
#include <stdio.h>
using namespace std;
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
int main(int argc, char *argv[]) {
IplImage* img = 0; /* pointer to an image */
printf("Hello\n");
if (argv[1] != 0)
img = cvLoadImage(argv[1], 0); // 1 for color
else
printf("Enter filename\n");
if (img != 0) {
cvNamedWindow("Display", CV_WINDOW_AUTOSIZE); // create a window
cvShowImage("Display", img); // show image in window
cvWaitKey(0); // wait until user hits a key
cvDestroyWindow("Display");
} else
printf("File not found\n");
return 0;
}
[/code]
4. ตรวจสอบ path ต่างๆดังนี้
$ pkg-config --cflags opencv
(output will come as)
-I/usr/include/opencv
$ pkg-config --libs opencv
(output will come as)
-lcxcore -lcv -lhighgui -lcvaux -lml
5. ทำการ complie and run
$ g++ -I/usr/include/opencv -lcxcore -lhighgui -lm hello.cpp
$ ./a.out img_name
6. สร้าง alias เพื่อจะได้รันคำสั่งได้สะดวก โดยพิมพ์คำสั่งด้านล่างนี้ไว้ในไฟล์ /home/jack/.bashrc
$ alias gcv="g++ -I/usr/include/opencv -lcv -lcxcore -lcvaux -lhighgui -lm"
7. ปิด และเปิด Terminal ใหม่ก็จะใช้คำสั่งได้
$ gcv hello.cpp
$./a.out img_name
ที่มา: Abhishek
แต่ถ้าต้องการ Build เอง ให้ดูที่ sirivy2, webeng.cs.ait.ac.th