3. Apply OpenCV
3-1 Install GTK + UVC viewer
sudo apt-get install guvcview
Install completed then setting.
sudo usermod -a -G video pi
sudo modprobe uvcvideo
3-2 Install OpenCV library
sudo
apt-get install libopencv-dev
very very long time~
3-3 Install Python-Opencv
sudo
apt-get install python-opencv
3-4 Install face recognition
face recognition API <<< click to link then download API
Unzip to home/pi/
You check bytefish-libfacerec folder
cd bytefish-libfacerec
sudo cmake .
sudo make
Check creation file libopencv_facerec.a
copy to /home/pi/camcv/libfacerec/
mkdir /home/pi/camcv/libfacerec
cd /home/pi/camcv/libfacerec
cp -r /home/pi/bytefish-libfacerec/* .
cd..
3-5 Add cmakelists.txt
nano cmakelists.txt
------------------------------------------------cmakelists.txt--------------------------------------------------------
cmake_minimum_required(VERSION 2.8)
project(camcv)
SET(COMPILE_DEFINITIONS -Werror)
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/)
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
/home/pi/camcv/libfacerec/libopencv_facerec.a ${OpenCV_LIBS})
--------------------------------------------------------------------------------------------------------------------------Red color is add code.
3-6 modify camcv.c
sudo nano camcv.c
Modify below code or click to link for download camcv.c
download camcv.c
-----------------------------------------------camcv.c----------------------------------------------------------------
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 : modif for demo purpose : smaller imagestate->timeout = 1000; // 5s delay before take imagestate->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 itcvNamedWindow(“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);
-------------------------------------------------------------------------------------------------------------------------
cmake .
make
./camcv
If you meet this error
---------------------------------------------------------------------------------------------
mmal: main: Failed to create camera component
mmal: Failed to run camera app. Please check for firmware updates
---------------------------------------------------------------------------------------------
Change Line 696
--------------------------------------------------------------------------------------------------------
else if (!raspipreview_create(&state.preview_parameters))
=>
else if ( (status = raspipreview_create(&state.preview_parameters)) != MMAL_SUCCESS)
--------------------------------------------------------------------------------------------------------
Re cmake~
If you completed all, open openCV window and display
No comments:
Post a Comment