This is my english engineering blog. If you want korean, visit my korean blog. My korean blog is answerofgod.tistory.com
Sep 17, 2015
Sep 15, 2015
RaspiberryPi openCV with wiringPi
My last post GPIO control for raspberry openCV is use system() function.
This post use wiringpi library.
I forgot wiringPi initialize.
If you added wiringPiSetup(), wiringPi is work.
You can download my changed code.
Backup your camcv_vid1.cpp and CMakeLists.txt files.
Extract zip files
And compile and build(cmake and make.)
RUN
If you see this error
Need a root.
So, you will typing this.
1
|
sudo ./camcv others/csv.txt l 2000
| cs |
GPIO control for raspberry openCV
There are many library for GPIO control.
Usually we use wiringPi.
But difficult compile wiringPi in cmake of camcv.
Compile is ok but code does not run.
I added CmakeList.txt
CmakeList.txt
1
2
3
|
SET(CMAKE_CXX_FLAGS "-pthread -I/usr/local/include -L/usr/local/lib -lwiringPi")
include_directories(/usr/local/include/)
target_link_libraries(/usr/local/lib/libwiringPi.so /usr/local/lib/libwiringPiDev.so )
| cs |
Added camcv_vid1.cpp
1
|
#include <wiringPi.h>
| cs |
Added main() function code
1
2
|
pinMode(0, OUTPUT); // output mode
digitalWrite(0, 0); //output low
| cs |
Added in recognize function code
1
|
digitalWrite(0, 1); //output high
| cs |
But doesn't run. So I tried another method.
shell command!!
I referred digipine.com
system() function is shell command function.
Added main() function code.
1
2
|
system("gpio mode 0 out"); //ans
system("gpio write 0 0"); //ans
| cs |
GPIO 0 -> output
GPIO 0 -> low
Added in recognize function code
1
2
3
4
5
6
7
8
|
// display name of the guy on the picture
string box_text;
if (prediction<MAX_PEOPLE)
{
box_text = "Id="+people[prediction];
if (prediction == P_NATACHA) //ans
system("gpio write 0 1"); //ans
}
| cs |
If recognized natacha, gpio 0 is high.
I use code is
1
2
3
|
gpio mode 0 out //gpio 0 output
gpio write 0 0 //gpio 0 low
gpio write 0 1 //gpio 0 high
| cs |
Sep 14, 2015
[ Raspberry Pi2 ] OpenCV using Picam Final
This posting is final.
We will face detect and recognize.
OpenCV Download
Extract file and move folder OpenCV-2.3.1/data/harrcascades to
usr/share/opencv/haarcascades
new camcv file download
Editing cmakelists.txt
- sudo nano CMakeLists.txt
remove camcv.c and add camcv_vid1.cpp
Editing camcv_vid1.cpp
- sudo nano camcv_vid1.cpp
- Line 59
- ----------------------------------------------------------------------------------------------
- #include "/home/pi/pierre/libfacerec-0.04/include/facerec.hpp"
- =>#include "/home/pi/camcv/libfacerec/include/facerec.hpp"로 수정
- ----------------------------------------------------------------------------------------------
- face recognition API
- Line 681
- ---------------------------------------------------------------------------------------------------
- fn_haar = "/usr/share/opencv/haarcascades/lbpcascade_frontalface.xml";
- =>fn_haar = "/usr/share/opencv/lbpcascades/lbpcascade_frontalface.xml";
- ---------------------------------------------------------------------------------------------------
- face detect lib
- Line 764
- ---------------------------------------------------------------------------------------------------
- else if (!raspipreview_create(&state.preview_parameters))
- =>else if ( (status = raspipreview_create(&state.preview_parameters)) != MMAL_SUCCESS)
- ---------------------------------------------------------------------------------------------------
Downloading for test sample image
Copy to /home/pi/camcv/others/
You can see 400's image file and 1 txt file.
open csv.txt
left ';' is image file name, right is id number.
opencv compare this image file and getting id number.
open camcv_vid1.cpp Line 65
define ID number.
go to Line 661
You can see display name.
build
- sudo cmake .
- sudo make
If you see below error
copy contrib.hpp file.
copy to /usr/include/opencv2/contrib/contrib.hpp
RUN
1
|
/camcv others/csv.txt l 5500
| cs |
Many image file is need long time.
If not display id name, reduce parameter
1
|
/camcv others/csv.txt l 3000
| cs |
but, lower the recognition rate.
[ Raspberry Pi2 ] OpenCV using Picam 4
This posting is using not still-shot but video.
copy camcv.c to RaspiVid.c
Editing RaspiVid.c file.
- We delete- all lines related to the preview component,
- - all lines related to the encoder component.
- - all lines related to inline command parsing and picture info…
- We change :
- - add the callback directly to the video_port (line 286)
- - create and attach the pool (to get/send message) to the video port… (line 320)
- - change format encoding to ENCODING_I420 in line (268) (instead of OPAQUE)
But, recommend down load raspiVid.c file
and editing Line 489
- else if (!raspipreview_create(&state.preview_parameters))
- => else if ( (status = raspipreview_create(&state.preview_parameters)) != MMAL_SUCCESS)
rename raspiVid.c to camcv.c
(If you download above link, you getting camcv_vid0.c )
- mv RaspiVid.c camcv.c
build
RUN (using xrdp or rasberry pi x-window)
1
|
./camcv
| cs |
If you change color or gray and frame, see Line 124 and Line 119~120.
picam FPS in Pi 1
picam FPS in Pi 2
maybe fps limit 29.9
Subscribe to:
Posts (Atom)