Archive for Agustus 2015
Face Tracking Haar Cascade Classifier menggunakan Pan/Tilt Camera OpenCV 2.4.9 pada Ubuntu 14.04
By : M yunusHaar Cascade Classifier adalah algoritma yang digunakan untuk mengenali fitur wajah manusia. Haar Cascade Classifier atau Penggolong Riam Haar mampu membedakan wajah dan bukan wajah. Haar Cascade Classifier mengklasifikasi gambar kedalam image positif dan image negatif. Image positif bernilai True, sedangkan image negatif bernilai False. Saat ada wajah yang sedang di jajaki oleh kamera dan di proses melalui OpenCV, maka OpenCV akan melakukan traini untuk mengukur image tersebit kedalam image positif dan negatif. keterangan lengkap dan bagaimana Haar Cascade Classifier bekerja dapat dilihat di docs.opencv.org
==================================================
skema rangkaian elektronik:
===================================================
CODE OPENCV:
===================================================
// Include header files
#include "cv.h"
#include "highgui.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <math.h>
#include <float.h>
#include <limits.h>
#include <time.h>
#include <ctype.h>
// Create memory for calculations
static CvMemStorage* storage = 0;
// Create a new Haar classifier
static CvHaarClassifierCascade* cascade = 0;
// Function prototype for detecting and drawing an object from an image
void detect_and_draw( IplImage* image );
// Create a string that contains the cascade name
const char* cascade_name =
"haarcascade_frontalface_alt.xml";
/* "haarcascade_profileface.xml";*/
// Main function, defines the entry point for the program.
int main( int argc, char** argv )
{
//Serial to Arduino
FILE *file;
file = fopen("/dev/ttyACM0","w");
// Structure for getting video from camera or avi
CvCapture* capture = 0;
/// Images to capture the frame from video or camera or from file
IplImage *frame, *frame_copy = 0;
// Used for calculations
int optlen = strlen("--cascade=");
// Input file name for avi or image file.
const char* input_name;
// Check for the correct usage of the command line
if( argc > 1 && strncmp( argv[1], "--cascade=", optlen ) == 0 )
{
cascade_name = argv[1] + optlen;
input_name = argc > 2 ? argv[2] : 0;
}
else
{
fprintf( stderr,
"Usage: facedetect --cascade=\"<cascade_path>\" [filename|camera_index]\n" );
return -1;
/*input_name = argc > 1 ? argv[1] : 0;*/
}
// Load the [[HaarClassifierCascade]]
cascade = (CvHaarClassifierCascade*)cvLoad( cascade_name, 0, 0, 0 );
// Check whether the cascade has loaded successfully. Else report and error and quit
if( !cascade )
{
fprintf( stderr, "ERROR: Could not load classifier cascade\n" );
return -1;
}
// Allocate the memory storage
storage = cvCreateMemStorage(0);
// Find whether to detect the object from file or from camera.
if( !input_name || (isdigit(input_name[0]) && input_name[1] == '\0') )
capture = cvCaptureFromCAM( !input_name ? 0 : input_name[0] - '0' );
else
capture = cvCaptureFromAVI( input_name );
// Create a new named window with title: result
cvNamedWindow( "result", 1 );
// Find if the capture is loaded successfully or not.
// If loaded succesfully, then:
if( capture )
{
// Capture from the camera.
for(;;)
{
// Capture the frame and load it in [[IplImage]]
if( !cvGrabFrame( capture ))
break;
frame = cvRetrieveFrame( capture );
// If the frame does not exist, quit the loop
if( !frame )
break;
// Allocate framecopy as the same size of the frame
if( !frame_copy )
frame_copy = cvCreateImage( cvSize(frame->width,frame->height),
IPL_DEPTH_8U, frame->nChannels );
// Check the origin of image. If top left, copy the image frame to frame_copy.
if( frame->origin == IPL_ORIGIN_TL )
cvCopy( frame, frame_copy, 0 );
// Else flip and copy the image
else
cvFlip( frame, frame_copy, 0 );
// Call the function to detect and draw the face
// detect_and_draw( frame_copy );
//==========================================================================//
int scale = 1;
// Create a new image based on the input image
IplImage* temp = cvCreateImage( cvSize(frame_copy->width/scale,frame_copy->height/scale), 8, 3 );
// Create two points to represent the face locations
CvPoint pt1, pt2;
int i;
// Clear the memory storage which was used before
cvClearMemStorage( storage );
// Find whether the cascade is loaded, to find the faces. If yes, then:
if( cascade )
{
// There can be more than one face in an image. So create a growable sequence of faces.
// Detect the objects and store them in the sequence
CvSeq* faces = cvHaarDetectObjects( frame_copy, cascade, storage,
1.1, 2, CV_HAAR_DO_CANNY_PRUNING,
cvSize(40, 40) );
// Loop the number of faces found.
for( i = 0; i < (faces ? faces->total : 0); i++ )
{
// Create a new rectangle for drawing the face
CvRect* r = (CvRect*)cvGetSeqElem( faces, i );
// Find the dimensions of the face,and scale it if necessary
pt1.x = r->x*scale;
pt2.x = (r->x+r->width)*scale;
pt1.y = r->y*scale;
pt2.y = (r->y+r->height)*scale;
//Serial to Arduino data transfer
int a=1,b=2,c=3,d=4;
if((pt1.x<320)&&(pt2.y<240)){
fprintf(file,"%d\n",a);
printf("a\n");
}
else if((pt1.x>320)&&(pt1.y<240)){
fprintf(file,"%d\n",b);
printf("b\n");
}
else if((pt1.x>320)&&(pt1.y>240)){
fprintf(file,"%d\n",c);
printf("c\n");
}
else if((pt1.x< 320)&&(pt1.y>240)){
fprintf(file,"%d\n",d);
printf("d\n");
}
// fclose(file);
// printf("x=%d y=%d\n", pt1.x, pt1.y);
// Draw the rectangle in the input image
cvRectangle( frame_copy, pt1, pt2, CV_RGB(255,0,0), 3, 8, 0 );
}
}
// Show the image in the window named "result"
cvShowImage( "result", frame_copy );
// Release the temp image created.
cvReleaseImage( &temp );
//=====================================================================//
// Wait for a while before proceeding to the next frame
if( cvWaitKey( 10 ) >= 0 )
break;
}
// Release the images, and capture memory
cvReleaseImage( &frame_copy );
cvReleaseCapture( &capture );
}
// If the capture is not loaded succesfully, then:
else
{
// Assume the image to be lena.jpg, or the input_name specified
const char* filename = input_name ? input_name : (char*)"lena.jpg";
// Load the image from that filename
IplImage* image = cvLoadImage( filename, 1 );
// If Image is loaded succesfully, then:
if( image )
{
// Detect and draw the face
// detect_and_draw( image );
// Wait for user input
cvWaitKey(0);
// Release the image memory
cvReleaseImage( &image );
}
}
fclose(file);
// Destroy the window previously created with filename: "result"
cvDestroyWindow("result");
// return 0 to indicate successfull execution of the program
return 0;
}
/*
// Function to detect and draw any faces that is present in an image
void detect_and_draw( IplImage* img )
{
int scale = 1;
// Create a new image based on the input image
IplImage* temp = cvCreateImage( cvSize(img->width/scale,img->height/scale), 8, 3 );
// Create two points to represent the face locations
CvPoint pt1, pt2;
int i;
// Clear the memory storage which was used before
cvClearMemStorage( storage );
// Find whether the cascade is loaded, to find the faces. If yes, then:
if( cascade )
{
// There can be more than one face in an image. So create a growable sequence of faces.
// Detect the objects and store them in the sequence
CvSeq* faces = cvHaarDetectObjects( img, cascade, storage,
1.1, 2, CV_HAAR_DO_CANNY_PRUNING,
cvSize(40, 40) );
// Loop the number of faces found.
for( i = 0; i < (faces ? faces->total : 0); i++ )
{
// Create a new rectangle for drawing the face
CvRect* r = (CvRect*)cvGetSeqElem( faces, i );
// Find the dimensions of the face,and scale it if necessary
pt1.x = r->x*scale;
pt2.x = (r->x+r->width)*scale;
pt1.y = r->y*scale;
pt2.y = (r->y+r->height)*scale;
//Serial to Arduino data transfer
int a=1,b=2,c=3,d=4;
if((pt1.x<320)&&(pt2.y<240)){
fprintf(file,"%d",a);
printf("a\n");
}
else if((pt1.x>320)&&(pt1.y<240)){
fprintf(file,"%d",b);
printf("b\n");
}
else if((pt1.x>320)&&(pt1.y>240)){
fprintf(file,"%d",c);
printf("c\n");
}
else if((pt1.x< 320)&&(pt1.y>240)){
fprintf(file,"%d",d);
printf("d\n");
}
// fclose(file);
// printf("x=%d y=%d\n", pt1.x, pt1.y);
// Draw the rectangle in the input image
cvRectangle( img, pt1, pt2, CV_RGB(255,0,0), 3, 8, 0 );
}
}
// Show the image in the window named "result"
cvShowImage( "result", img );
// Release the temp image created.
cvReleaseImage( &temp );
}
*/
==================================================
==================================================
ARDUINO CODE:
....>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<...............
#include <Servo.h>
Servo tilt;
Servo pan;
int i=90,j=90;
char incomingByte = 0; // for incoming serial data
void setup(){
tilt.attach(9);
pan.attach(10);
Serial.begin(9600);
tilt.write(90);
pan.write(90);
}
void satu(){
pan.write(i);
tilt.write(j);
i=i+1;
j=j-1;
}
void dua(){
pan.write(i);
tilt.write(j);
i=i-1;
j=j-1;
}
void tiga(){
pan.write(i);
tilt.write(j);
i=i-1;
j=j+1;
}
void empat(){
pan.write(i);
tilt.write(j);
i=i+1;
j=j+1;
}
void loop()
{
// send data only when you receive data:
if (Serial.available() > 0)
{
incomingByte = Serial.read();
switch (incomingByte)
{
case '1':
satu();
delay(10);
break;
case '2':
dua();
delay(10);
break;
case '3':
tiga();
delay(10);
break;
case '4':
empat();
delay(10);
break;
}
}
}
==================================================
==================================================
VIDEO DOKUMENTASI:
Sumber:
OpenCV 2.4.9 Tutorials (User Guide)
Object Tracking pan/Tilt Camera OpenCV 2.4.9 pada Ubuntu 14.04 dengan Arduino Mega
By : M yunusPeralatan yang dibutuhkan:
- Arduino Mega 2560
- Pan/Tilt Servo
- Cammera Webcam
- Laptop Ubuntu
- OpenCV yang sudah terinstal
Rangkaian:
Software:
Code untuk OpenCV:
#include <opencv/cvaux.h>
#include <opencv/highgui.h>
#include <opencv/cxcore.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <math.h>
#include <float.h>
#include <limits.h>
#include <time.h>
#include <ctype.h>
#include <unistd.h>
int main(int argc, char* argv[])
{
// Default capture size - 640x480
CvSize size = cvSize(640,480);
//CvSize size = cvSize(320,240);
// Open capture device. 0 is /dev/video0, 1 is /dev/video1, etc.
CvCapture* capture = cvCaptureFromCAM(1);
if( !capture )
{
fprintf( stderr, "ERROR: capture is NULL \n" );
getchar();
return -1;
}
// Create a window in which the captured images will be presented
cvNamedWindow( "Camera", CV_WINDOW_AUTOSIZE );
cvNamedWindow( "HSV", CV_WINDOW_AUTOSIZE );
cvNamedWindow( "EdgeDetection", CV_WINDOW_AUTOSIZE );
// Detect a red ball
CvScalar hsv_min = cvScalar(150, 84, 130, 0);
CvScalar hsv_max = cvScalar(358, 256, 255, 0);
IplImage * hsv_frame = cvCreateImage(size, IPL_DEPTH_8U, 3);
IplImage* thresholded = cvCreateImage(size, IPL_DEPTH_8U, 1);
while( 1 )
{
// Get one frame
IplImage* frame = cvQueryFrame( capture );
if( !frame )
{
fprintf( stderr, "ERROR: frame is null...\n" );
getchar();
break;
}
// Covert color space to HSV as it is much easier to filter colors in the HSV color-space.
cvCvtColor(frame, hsv_frame, CV_BGR2HSV);
// Filter out colors which are out of range.
cvInRangeS(hsv_frame, hsv_min, hsv_max, thresholded);
// Memory for hough circles
CvMemStorage* storage = cvCreateMemStorage(0);
// hough detector works better with some smoothing of the image
cvSmooth( thresholded, thresholded, CV_GAUSSIAN, 9, 9 );
CvSeq* circles = cvHoughCircles(thresholded, storage, CV_HOUGH_GRADIENT, 2,
thresholded->height/4, 100, 50, 10, 400);
for (int i = 0; i < circles->total; i++)
{
float* p = (float*)cvGetSeqElem( circles, i );
//int* p=(int*)b;
FILE *file;
file = fopen("/dev/ttyACM0","w");
//printf("Ball! x=%f y=%f r=%f\n\r",p[0],p[1],p[2] );
int a=1,b=2,c=3,d=4;
if((p[0]<320.000000)&&(p[1]<240.000000)){
fprintf(file,"%d",a);
printf("a\n");
}
else if((p[0]>320.000000)&&(p[1]<240.000000)){
fprintf(file,"%d",b);
printf("b\n");
}
else if((p[0]>320.000000)&&(p[1]>240.000000)){
fprintf(file,"%d",c);
printf("c\n");
}
else if((p[0]< 320.000000)&&(p[1]>240.000000)){
fprintf(file,"%d",d);
printf("d\n");
}
fclose(file);
//open serial
// fclose(file);
// sleep(0.5);
cvCircle( frame, cvPoint(cvRound(p[0]),cvRound(p[1])),
3, CV_RGB(0,255,0), -1, 8, 0 );
cvCircle( frame, cvPoint(cvRound(p[0]),cvRound(p[1])),
cvRound(p[2]), CV_RGB(255,0,0), 3, 8, 0 );
sleep(0.5);
}
cvShowImage( "Camera", frame ); // Original stream with detected ball overlay
cvShowImage( "HSV", hsv_frame); // Original stream in the HSV color space
cvShowImage( "After Color Filtering", thresholded ); // The stream after color filtering
cvReleaseMemStorage(&storage);
// Do not release the frame!
//If ESC key pressed, Key=0x10001B under OpenCV 0.9.7(linux version),
//remove higher bits using AND operator
if( (cvWaitKey(10) & 255) == 27 ) break;
}
// Release the capture device housekeeping
cvReleaseCapture( &capture );
cvDestroyWindow( "mywindow" );
return 0;
}
code untuk arduino:
#include <Servo.h>
Servo tilt;
Servo pan;
int i=90,j=90;
char incomingByte = 0; // for incoming serial data
void setup(){
tilt.attach(9);
pan.attach(10);
Serial.begin(9600);
tilt.write(90);
pan.write(90);
}
void satu(){
pan.write(i);
tilt.write(j);
i=i+1;
j=j-1;
}
void dua(){
pan.write(i);
tilt.write(j);
i=i-1;
j=j-1;
}
void tiga(){
pan.write(i);
tilt.write(j);
i=i-1;
j=j+1;
}
void empat(){
pan.write(i);
tilt.write(j);
i=i+1;
j=j+1;
}
void loop()
{
// send data only when you receive data:
if (Serial.available() > 0)
{
incomingByte = Serial.read();
switch (incomingByte)
{
case '1':
satu();
delay(10);
break;
case '2':
dua();
delay(10);
break;
case '3':
tiga();
delay(10);
break;
case '4':
empat();
delay(10);
break;
}
}
}
Hasil::
/*****************************************************************************************
* Name : Fast object tracking using the OpenCV library *
* Author : Lior Chen <chen.lior@gmail.com> *
* Notice : Copyright (c) Jun 2010, Lior Chen, All Rights Reserved *
* : *
* Site : http://www.lirtex.com *
* WebPage : http://www.lirtex.com/robotics/fast-object-tracking-robot-computer-vision *
* : *
* Version : 1.0 *
* Notes : By default this code will open the first connected camera. *
* : In order to change to another camera, change *
* : CvCapture* capture = cvCaptureFromCAM( 0 ); to 1,2,3, etc. *
* : Also, the code is currently configured to tracking RED objects. *
* : This can be changed by changing the hsv_min and hsv_max vectors *
* : *
* License : This program is free software: you can redistribute it and/or modify *
* : it under the terms of the GNU General Public License as published by *
* : the Free Software Foundation, either version 3 of the License, or *
* : (at your option) any later version. *
* : *
* : This program is distributed in the hope that it will be useful, *
* : but WITHOUT ANY WARRANTY; without even the implied warranty of *
* : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* : GNU General Public License for more details. *
* : *
* : You should have received a copy of the GNU General Public License *
* : along with this program. If not, see <http://www.gnu.org/licenses/> *
******************************************************************************************/
#include <opencv/cvaux.h>
#include <opencv/highgui.h>
#include <opencv/cxcore.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <math.h>
#include <float.h>
#include <limits.h>
#include <time.h>
#include <ctype.h>
int main(int argc, char* argv[])
{
// Default capture size - 640x480
CvSize size = cvSize(640,480);
// Open capture device. 0 is /dev/video0, 1 is /dev/video1, etc.
CvCapture* capture = cvCaptureFromCAM( 0 );
if( !capture )
{
fprintf( stderr, "ERROR: capture is NULL \n" );
getchar();
return -1;
}
// Create a window in which the captured images will be presented
cvNamedWindow( "Camera", CV_WINDOW_AUTOSIZE );
cvNamedWindow( "HSV", CV_WINDOW_AUTOSIZE );
cvNamedWindow( "EdgeDetection", CV_WINDOW_AUTOSIZE );
// Detect a red ball
CvScalar hsv_min = cvScalar(150, 84, 130, 0);
CvScalar hsv_max = cvScalar(358, 256, 255, 0);
IplImage * hsv_frame = cvCreateImage(size, IPL_DEPTH_8U, 3);
IplImage* thresholded = cvCreateImage(size, IPL_DEPTH_8U, 1);
while( 1 )
{
// Get one frame
IplImage* frame = cvQueryFrame( capture );
if( !frame )
{
fprintf( stderr, "ERROR: frame is null...\n" );
getchar();
break;
}
// Covert color space to HSV as it is much easier to filter colors in the HSV color-space.
cvCvtColor(frame, hsv_frame, CV_BGR2HSV);
// Filter out colors which are out of range.
cvInRangeS(hsv_frame, hsv_min, hsv_max, thresholded);
// Memory for hough circles
CvMemStorage* storage = cvCreateMemStorage(0);
// hough detector works better with some smoothing of the image
cvSmooth( thresholded, thresholded, CV_GAUSSIAN, 9, 9 );
CvSeq* circles = cvHoughCircles(thresholded, storage, CV_HOUGH_GRADIENT, 2,
thresholded->height/4, 100, 50, 10, 400);
for (int i = 0; i < circles->total; i++)
{
float* p = (float*)cvGetSeqElem( circles, i );
printf("Ball! x=%f y=%f r=%f\n\r",p[0],p[1],p[2] );
cvCircle( frame, cvPoint(cvRound(p[0]),cvRound(p[1])),
3, CV_RGB(0,255,0), -1, 8, 0 );
cvCircle( frame, cvPoint(cvRound(p[0]),cvRound(p[1])),
cvRound(p[2]), CV_RGB(255,0,0), 3, 8, 0 );
}
cvShowImage( "Camera", frame ); // Original stream with detected ball overlay
cvShowImage( "HSV", hsv_frame); // Original stream in the HSV color space
cvShowImage( "After Color Filtering", thresholded ); // The stream after color filtering
cvReleaseMemStorage(&storage);
// Do not release the frame!
//If ESC key pressed, Key=0x10001B under OpenCV 0.9.7(linux version),
//remove higher bits using AND operator
if( (cvWaitKey(10) & 255) == 27 ) break;
}
// Release the capture device housekeeping
cvReleaseCapture( &capture );
cvDestroyWindow( "mywindow" );
return 0;
}
Tutorial OpenCV Linux: #2 Load, Modify, and Save an Image
By : M yunusPada tutorial OpenCV kali ini anda akan mempelajari:
1. megambil gambar dari direktori anda dengan imread
2. merubah tampilan RGB menjadi keabuan (gratscale) dengan cvtColor
3. menyimpan hasil ubahan gambar dengan imwrite
Membuat file .cpp
buka terminal dan lakukan perintah berikut, setelah selesai menulis code simpan dengan perintah ctrl+x dan shift+y.
sudo nano RGBtoGrayscale.cpp
Code program
#include <cv.h>
#include <highgui.h>
using namespace cv;
int main(int argc, char ** argv){
char* imageName = argv[1];
Mat image;
image= imread( imageName, 1);
if(argc!=2 || !image.data)
{
printf( " No image data\n");
return -1;
}
Mat gray_image;
cvtColor( image, gray_image, CV_BGR2GRAY);
imwrite("/home/OPENCVlat/Gray_Image.jpg",gray_image);
namedWindow( imageName, CV_WINDOW_AUTOSIZE);
namedWindow("Gray_image", CV_WINDOW_AUTOSIZE);
imshow( imageName, image);
imshow( "Gray image", gray_image);
waitKey(0);
return 0;
}
Penjelasan Code Program:
terlebih dahulu masukan modul/library yang digunakan untuk mentransformasi image RGB ke Grayscale.
#include <cv.h>
#include <highgui.h>
pada program utama terlebih dahulu kita mengambil gambar pada direktori dan menyimpanya pada variabel dengan perintah imread.
Mat image;
image= imread( imageName, 1);
kita buat variabel lain untuk menyimpan gambar hasil transformasi ke grayscale dan dengan perintah cvtColor
Mat gray_image;
cvtColor( image, gray_image, CV_BGR2GRAY);
kita simpan hasil transformasi pada direktori anda dengan perintah imwrite
imwrite("/home/OPENCVlat/Gray_Image.jpg",gray_image);
kita akan menampilkan gambar RGB (asli) dengan gambar Grayscale (transformasi) pada window .
namedWindow( imageName, CV_WINDOW_AUTOSIZE);
namedWindow("Gray_image", CV_WINDOW_AUTOSIZE);
imshow( imageName, image);
imshow( "Gray image", gray_image);
Kompilasi program:
catatan:
pastikan pada folder anda membuat code program ini terdapat bash scrip build_all.sh. jika tidak copy paste saja dari direktori OpenCV anda pada folder samples/c/build_all.sh
lakukan perintah ini pada terminal:
chmod +x build_all.sh
./build_all.sh
jika tidak ada error maka anda dapat menjalankan code anda dengan perintah. (image name) --> sesuaikan dengan nama gambay yang anda dunakan dan pastikan berada dalam satu direktori yang sama dengan code program.
./RGBtoGrayscale (imagename).jpg
setelah itu anda akan mendapatkan gambar hasil transformasi dan gambar RGB seperti berikut.
Sumber:
Tutorials Opencv-2.4.9.pdf
Tutorial OpenCV Linux: #1 Installasi OpenCV di UBUNTU 14.04
By : M yunus
| sudo apt-get update |
| sudo apt-get upgrade |
sudo
apt-get
install
build-essential
libgtk2.0-dev libjpeg-dev libtiff4-dev libjasper-dev libopenexr-dev
cmake python-dev python-numpy python-tk libtbb-dev libeigen3-dev yasm
libfaac-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev
libvorbis-dev libxvidcore-dev libx264-dev libqt4-dev libqt4-opengl-dev
sphinx-common texlive-latex-extra libv4l-dev libdc1394-22-dev
libavcodec-dev libavformat-dev libswscale-dev default-jdk ant
libvtk5-qt4-dev
Sekarang kita akan men-download OpenCV.
| cd ~ |
| unzip opencv-2.4.9.zip |
| cd opencv-2.4.9 |
| mkdir build |
| cd build |
| cmake
-D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D
INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON
-D WITH_QT=ON -D WITH_OPENGL=ON -D WITH_VTK=ON .. |
| make |
sudo make install |
sudo
nano /etc/ld.so.conf.d/opencv.conf
setelah itu tambahkan script ini di dalamnya, save dan exit dengan ctrl+x , shift+y
/usr/local/lib
berikan perintah berikutsudo ldconfig
Buatlah bash script dengan perintah berikutsudo gedit /etc/bash.bashrc
setelah itu tambahkan script ini di dalamnya
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
kita buka folder sample, adabanyak pilihan bahasa pemograman yang digunakan, pilih folder c dengan perintah beriut dan compile script.c dan .cpp dalam folder tersebut
cd ~/opencv-2.4.9/samples/c
chmod +x build_all.sh
./build_all.sh
berikut adalah contoh image processing untuk face detection file berekstensi .c./facedetect --cascade="/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml" --scale=1.5 lena.jpg
Contoh lainya
./facedetect --cascade="/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml" --nested-cascade="/usr/local/share/OpenCV/haarcascades/haarcascade_eye.xml" --scale=1.5 lena.jpg
Untuk menggunakan file cpp lakukan perintah berikut
~/opencv-2.4.9/build/bin/cpp-example-grabcut ~/opencv-2.4.9/samples/cpp/lena.jpg
Contoh lainya
~/opencv-2.4.9/build/bin/cpp-example-calibration_artificial
Untuk menggunakan file python OpenCV, gunakan perintah berikut.python ~/opencv-2.4.9/samples/python2/turing.py
Untuk menggunakan file Java OpenCV, gunakan perintah berikut.
cd ~/opencv-2.4.9/samples/java/ant
ant -DocvJarDir=/home/samontab/opencv-2.4.9/build/bin -DocvLibDir=/home/samontab/opencv-2.4.9/build/lib
sekarang kita menbaca sebuah video dan menggunakan OpenGL dengan Qt untuk membangun citra 3D cd ~/opencv-2.4.9/samples/cpp/Qt_sample
mkdir build
cd build
cmake ..
make
./OpenGL_Qt_Binding
Untuk membuat visualisasi 3D animasi lakukan perintah berikut cd ~/opencv-2.4.9/samples/cpp/tutorial_code/viz
g++ -o widget_pose `pkg-config opencv --cflags` widget_pose.cpp `pkg-config opencv --libs`
./widget_pose
Sumber:http://www.samontab.com/web/2014/06/installing-opencv-2-4-9-in-ubuntu-14-04-lts/ |