We saved jpg file in Previous posting.
This posting is about OpenCV.
1. Install OpenCV and related packages.
Install GTK + UVC viewer.
1
|
sudo apt-get install guvcview
| cs |
Setting uvcvideo.
1
2
|
sudo usermod -a -G video pi
sudo modprobe uvcvideo
| cs |
Install OPENCV library.
1
|
sudo apt-get install libopencv-dev
| cs |
Install Python-Opencv.
1
|
sudo apt-get install python-opencv
| cs |
Install face recognition
If above link is didn't download, use below link.
Extract to home/pi/ (using samba is easy)
You can see 'bytefish-libfacerec-xxx' folder in extract folder.
You move to /home/pi/ and rename 'bytefish-libfacerec '.
2. BUILD
cmake
1
2
3
|
cd ..
cd bytefish-libfacerec
sudo cmake .
| cs |
make
1
|
sudo make
| cs |
If build is success, make this file libopencv_facerec.a
move folder to /home/pi/camcv/libfacerec/
1
2
3
4
|
mkdir /home/pi/camcv/libfacerec
cd /home/pi/camcv/libfacerec
cp -r /home/pi/bytefish-libfacerec/* .
cd ..
| cs |
Editing makelist
1
|
sudo nano CMakeLists.txt
| cs |
Recommend all text copy.
- 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})
Editing camcv.c
1
|
sudo nano camcv.c
| cs |
- 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);
Recommend download below file.
Editing Line 696
- else if (!raspipreview_create(&state.preview_parameters))
- => else if ( (status = raspipreview_create(&state.preview_parameters)) != MMAL_SUCCESS)
Build
1
2
|
sudo cmake .
sudo make
| cs |
Run
1
|
./camcv
| cs |
If you see above message, run in x-window.
And change image file, 'bmp'
No comments:
Post a Comment