May 31, 2016

OPENCV RASPBERRY PI2 (JESSIE) 3 - OPENCV Library



This posting is prepare OPENCV.

Install library.

1. Install GTK + UVC viewer 

1
sudo apt-get install guvcview
cs



Config setting.

1
2
sudo usermod --G video pi
sudo modprobe uvcvideo
cs





2. Install OPENCV library

1
sudo apt-get install libopencv-dev
cs


Wait Long time~~~

3. Install Python Opencv

1
sudo apt-get install python-opencv
cs



4. Install face recognition 


If can't downloading use below link.


Extract to /home/pi/ (samba is useful)

You can see this folder bytefish-libfacerec-xxx

Changing folder name bytefish-libfacerec



cmake

1
2
3
cd ..
cd bytefish-libfacerec
sudo cmake .
cs


make

1
sudo make
cs


You can see libopencv_facerec.a 


If can't see libopencv_facerec.a downdload below link.


copy to /home/pi/camcv/libfacerec/ 

1
2
3
4
mkdir /home/pi/camcv/libfacerec
cd /home/pi/camcv/libfacerec
cp -/home/pi/bytefish-libfacerec/* .  
cd ..
cs



Editing code CMakeLists.txt

1
sudo nano CMakeLists.txt
cs

All code copy & paste

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
cmake_minimum_required(VERSION 2.8)
 project(camcv)
 SET(COMPILE_DEFINITIONS -Werror)
 
#OPENCV
find_package( OpenCV REQUIRED )
 
#except if you’re pierre, change the folder where you installed libfacerec
#optional, only if you want to go till step 6 : face recognition
link_directories( /home/pi/camcv/libfacerec)
 
 include_directories(/opt/vc/include)
 include_directories(/opt/vc/include/interface/vcos)
 include_directories(/opt/vc/include/interface/vcos/pthreads)
 include_directories(/opt/vc/include/interface/vmcs_host/linux)
 include_directories(.)
  
include_directories(/opt/vc/userland/host_applications/linux/libs/bcm_host/include)
 include_directories(/opt/vc/userland/interface/vcos)
 include_directories(/opt/vc/userland)
 include_directories(/opt/vc/userland/interface/vcos/pthreads)
 include_directories(/opt/vc/userland/interface/vmcs_host/linux)
 include_directories(/opt/vc/userland/interface/khronos/include)
 include_directories(/opt/vc/userland/interface/khronos/common)
 include_directories(/home/pi/camcv/)
 include_directories(/home/pi/camcv/gl_scenes/)
 include_directories(/home/pi/camcv/libfacerec/include/)
add_executable(camcv RaspiCamControl.c RaspiCLI.c RaspiPreview.c camcv.c RaspiTex.c RaspiTexUtil.c gl_scenes/teapot.c
gl_scenes/models.c gl_scenes/square.c gl_scenes/mirror.c gl_scenes/sobel.c gl_scenes/yuv.c tga.c )
target_link_libraries(camcv /opt/vc/lib/libmmal_core.so /opt/vc/lib/libmmal_util.so /opt/vc/lib/libmmal_vc_client.so /opt/vc/lib/libvcos.so /opt/vc/lib/libbcm_host.so /opt/vc/lib/libGLESv2.so /opt/vc/lib/libEGL.so libpthread.so libm.so /home/pi/camcv/libfacerec/libopencv_facerec.a ${OpenCV_LIBS})
cs

Editing camcv.c

1
sudo nano camcv.c
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Lines 61+ : add OpenCV Includes
// *** PR : ADDED for OPENCV
#include <cv.h>
#include <highgui.h>
 
Line 156 : modify init values for test (size of file)
// *** PR : modify for demo purpose : smaller image
state->timeout = 1000// 5s delay before 
take image
state->width = 320;//2592;
state->height = 200//1944;
 
Line 230+ : in static void encoder_buffer_callback function. 
This is the core of the modification. 
This function is a callback, call to get the image in the queue
buffer contains the picture from the camera.
 
// *** PR : OPEN CV Stuff here !
// create a CvMat empty structure, with size of the buffer.
CvMat* buf = cvCreateMat(1,buffer->length,CV_8UC1);
// copy buffer from cam to 
CvMatbuf->data.ptr = buffer->data;
// decode image (interpret jpg)
IplImage *img = cvDecodeImage(buf, CV_LOAD_IMAGE_COLOR);
// we can save it 
!cvSaveImage(“foobar.bmp”, img,0);
// or display it
cvNamedWindow(“camcvWin”, CV_WINDOW_AUTOSIZE);
cvShowImage(“camcvWin”, img );
cvWaitKey(0);
Line 711/726/823 : we remove the native preview window (replaced by opencv window)
// *** PR : we don’t want preview
camera_preview_port = NULL;
// PR : we don’t want preview
// status = connect_ports(camera_preview_port, preview_input_port, &state.preview_connection);
// mmal_connection_destroy(state.preview_connection);
cs

If difficult editing camcv.c download below link.


Cmake and make

1
2
sudo cmake .
sudo make
cs


Run camcv

1
./camcv
cs


You can see error message in dos mode.

Run window mode.

Checking bmp file!!





No comments:

Post a Comment