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(00);    //output low
cs

Added in recognize function code
1
    digitalWrite(01);    //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 referred wiringpi.com 

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
  1. sudo nano CMakeLists.txt

remove camcv.c and add camcv_vid1.cpp

Editing camcv_vid1.cpp

  1. sudo nano camcv_vid1.cpp

  1. Line 59
  2. ----------------------------------------------------------------------------------------------
  3. #include "/home/pi/pierre/libfacerec-0.04/include/facerec.hpp"
  4. =>#include "/home/pi/camcv/libfacerec/include/facerec.hpp"로 수정
  5. ----------------------------------------------------------------------------------------------
  6. face recognition API
  7.  
  8. Line 681
  9. ---------------------------------------------------------------------------------------------------
  10. fn_haar = "/usr/share/opencv/haarcascades/lbpcascade_frontalface.xml";
  11. =>fn_haar = "/usr/share/opencv/lbpcascades/lbpcascade_frontalface.xml"; 
  12. ---------------------------------------------------------------------------------------------------
  13. face detect lib
  14.  
  15. Line 764
  16. ---------------------------------------------------------------------------------------------------
  17. else if (!raspipreview_create(&state.preview_parameters))
  18. =>else if ( (status = raspipreview_create(&state.preview_parameters)) != MMAL_SUCCESS) 
  19. ---------------------------------------------------------------------------------------------------



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

  1. sudo cmake .
  2. 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. 
  1. We  delete- all lines related to the preview component,
  2. - all lines related to the encoder component.
  3. - all lines related to inline command parsing and picture info…
  4. We change :
  5. - add the callback directly to the video_port  (line 286)
  6. - create and attach the pool (to get/send message)  to the video port… (line 320)
  7. - change format encoding to ENCODING_I420 in line (268) (instead of OPAQUE)
But, recommend down load raspiVid.c file

and editing Line 489
  1. else if (!raspipreview_create(&state.preview_parameters))
  2. => 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 )
  1. 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

  • 320×240 color : FPS = 27,2
  • 320×240 gray : FPS = 28,6
  • 640×480 color : FPS = 8
  • 640×480 gray : FPS = 17

  • picam FPS in Pi 2

  • 320×240 color : FPS = 29.9
  • 320×240 gray : FPS = 29.9
  • 640×480 color : FPS = 24.3
  • 640×480 gray : FPS = 29.9
  • 1280x960 color : FPS=6.6
  • 1280x960 gray : FPS=15

  • maybe fps limit 29.9