Installing OpenCV 2.3.1 in Ubuntu


Step 1:ダウンロード
からhttp://sourceforge.net/projects/opencvlibrary OpenCVソースをダウンロードし、ダウンロードファイルはOpenCV-2.3.1 a.tar.bz 2である.
cd ~ wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.1/OpenCV-2.3.1a.tar.bz2/download

Step 2:解凍、解凍後のフォルダはOpenCV-2.3.1
tar -xvf OpenCV-2.3.1a.tar.bz2

Step 3:構成の確認
cd OpenCV-2.3.1
cmake .


, ( , )

Installing OpenCV 2.3.1 in Ubuntu_ 1

step4:

make
Step 5:インストール
sudo make install
Step 6:
sudo gedit /etc/ld.so.conf.d/opencv.conf
いているテキストに/usr/local/libを
sudo ldconfig
sudo gedit /etc/bash.bashrc
いているファイルに した の PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/ local /lib/pkgconfig export PKG_CONFIG_PATH
Let’s check some demos included in OpenCV:1 cd   ~ 2 mkdir   openCV_samples 3 cp   OpenCV-2.1.0/samples/c/* openCV_samples 4 cd   openCV_samples/ 5 chmod   +x build_all.sh 6 ./build_all.sh
Some of the training data for object detection is stored in/usr/local/share/opencv/haarcascades. You need to tell OpenCV which training data to use. I will use one of the frontal face detectors available. Let’s find a face:1 ./facedetect --cascade= "/usr/local/share/opencv/haarcascades/haarcascade_frontalface_alt.xml" --scale=1.5 lena.jpg
Installing OpenCV 2.3.1 in Ubuntu_ 2
Note the scale parameter. It allows you to increase or decrease the size of the smallest object found in the image (faces in this case). Smaller numbers allows OpenCV to find smaller faces, which may lead to increasing the number of false detections. Also,
the computation time needed gets larger when searching for smaller objects.
In OpenCV 2.1, the grabcut algorithm is provided in the samples. This is a very nice segmentation algorithm that needs very little user input to segment  the objects in the image. For using the demo, you need to select a rectangle of the area you want to segment.
Then, hold the Control key and left click to select the background (in Blue). After that, hold the Shift key and left click to select the foreground (in Red). Then press the n key to generate the segmentation. You can press n again to continue to the next
iteration of the algorithm.1 ./grabcut lena.jpg
This image shows the initial rectangle for defining the object that I want to segment.
Installing OpenCV 2.3.1 in Ubuntu_ 3
Now I roughly set the foreground (red) and background (blue).
Installing OpenCV 2.3.1 in Ubuntu_ 4
When you are ready, press the n key to run the grabcut algorithm. This image shows the result of the first iteration of the algorithm.
Installing OpenCV 2.3.1 in Ubuntu_ 5
Now let’s see some background subtraction from a video. The original video shows a hand moving in front of some trees. OpenCV allows you to separate the foreground (hand) from the background (trees).
Installing OpenCV 2.3.1 in Ubuntu_ 6   1 ./bgfg_segm tree.avi
Installing OpenCV 2.3.1 in Ubuntu_ 7
There are many other samples that you can try.