This step is easy : we reuse the source code of previous step 6 and we add the OpenCV face recognition treatment of step 6 of “Mirror Magic”.
Watch this video to see result (http://www.youtube.com/watch?v=yzYIxNgDZu4).
Source code modification
Except some new #include statements and some global variables, all modification are in the callback function video_buffer_callback
For face recognition, gray pictures are required. Thus, once we get the I420 frame, we don’t need to extract color information. This is a great new, since we saw on last post, that this step takes a lot of cpu !
Make it simple : we forget the pu and pv channels, we only keep the “py” IplImage (gray channel) and convert it to a Mat object.
The face detection is made by the detectMultiScale function. This call requires most of the cpu needed in a loop, it’s important to optimize it.
- Let’s use the LBP cascade (Local Binaries Patterns) instead of the Haar cascade file (haarcascade_frontalface_alt.xml). Modify the fn_haar variable to link to lbpcascade_frontalface.xml. Response time is much more faster but less accurate. Sometimes, (and you can see exemple on the video), the soft gives wrong predictions
- Let’s increase the size of minimum rectangle to search size(80,80) instead of size(60,60) as last parameter of the call.
- I read on the “blog de remi” a way to optimize this function, using an alternative home-made function smartDetect. Unfortunatly, but I didn’t notice any improvment. Thus, I removed it. (perhaps I did a mistake or a misuse ?)
Results
- With a 320×240 frame, I’m between 8 and 17 FPS with almost no lag (17 FPS = no face to detect and to analyse. 8 FPS = analyse face at each loop)
- With a 640×480 frame, I’m around 4-5 FPS whith a small lag (1 s)
Conclusions
For me, these results are very good for a such affordable computer like Rasperry Pi. Of course, for a real-time use like RC robot or vehicle it’s too slow (need to detect quickly an obstacle, except if you build a RPCS (Raspberry Pi Controlled Snail) ;-).
But for most of others uses like domotic or education it’s fine.
Anyway, it’s far better than my USB webcam : I was even unable to do face recognition in 640×480 !
Download the source code here (http://raufast.org/download/camcv_vid1.cpp). It’s really a quick&dirty code, don’t be offended by non-respect of C++ state-of-the-art coding rules !
At this stage, you should be able to detect Mona Lisa, in case of she rings at your door tonight 😉
Pingback: OpenCV and Pi Camera Board ! | Think RPI
jack said:
It is cruel to post video without code.
Pierre said:
😉 patience… I was far away from my home. Now, you can download it, enjoy !
Ouille Grospaysan said:
Bravo !
jack said:
thank you very much.
i think many robots makers will apreciate your job.
jack said:
bravo pierre.desole m’exprimer en anglais m’est trop penible.
J’ai bien compile ton programme, compile “prepare” et obtennu quelques photos de comparaison, mais je ne sait pas comment en faire le fichier a donner en ligne de commande.
Si tu as quelques minutes pour m’eclairer, je t’en serai reconnaissant.
merci. , jacques
Pierre said:
This a csv file , first field is full filename (including path) ; and second field is id of the person
Exemple here :
http://docs.opencv.org/trunk/modules/contrib/doc/facerec/tutorial/facerec_video_recognition.html
Caio Porto said:
So hard to make it compile, 3 days already trying…
Pierre said:
😦 yes it’s not trivial. Have you followed all the 7 step ? (and perhaps the step of the previous post : magic mirror ?)
perfo said:
hello , its me again. I manged to get magic mirror version 1 working ok and I’ve got this far on magic mirror 2. If I use camcv_vid0.c and cmake . make then it ‘ll compile and run no problem but I i swap camcv_vid0.c for camcv_vid1.c in the make file I get the following errors.
pi@Mirror ~/camcv $ make
Scanning dependencies of target camcv
[ 7%] Building C object CMakeFiles/camcv.dir/RaspiCamControl.c.o
[ 15%] Building C object CMakeFiles/camcv.dir/RaspiCLI.c.o
[ 23%] Building C object CMakeFiles/camcv.dir/RaspiPreview.c.o
[ 30%] Building CXX object CMakeFiles/camcv.dir/camcv_vid1.cpp.o
[ 38%] Building C object CMakeFiles/camcv.dir/RaspiTex.c.o
[ 46%] Building C object CMakeFiles/camcv.dir/RaspiTexUtil.c.o
[ 53%] Building C object CMakeFiles/camcv.dir/gl_scenes/teapot.c.o
[ 61%] Building C object CMakeFiles/camcv.dir/gl_scenes/models.c.o
[ 69%] Building C object CMakeFiles/camcv.dir/gl_scenes/square.c.o
[ 76%] Building C object CMakeFiles/camcv.dir/gl_scenes/mirror.c.o
[ 84%] Building C object CMakeFiles/camcv.dir/gl_scenes/yuv.c.o
[ 92%] Building C object CMakeFiles/camcv.dir/gl_scenes/sobel.c.o
[100%] Building C object CMakeFiles/camcv.dir/tga.c.o
Linking CXX executable camcv
CMakeFiles/camcv.dir/camcv_vid1.cpp.o: In function `default_status(RASPIVID_STATE*)’:
camcv_vid1.cpp:(.text+0x798): undefined reference to `raspipreview_set_defaults(RASPIPREVIEW_PARAMETERS*)’
So it gets all the way to the linking part and then fails as it can’t find the references. There are a lot more than the undefined reference I’ve shown above but I guess they are all part of the same problem.
I changed the path to the facerec.hpp as instructed.
Can any one offer any words of advice ? I’ve been at this for a few day snow and can’t bottom it. Any help will be appreciated as I’m sooo close to getting this working..
Thanks Pierre for the project.
perfo said:
not sure how it happened but I’ve wasted days over not having
/home/pi/bytefish-libfacerec-e1b143d/libopencv_facerec.a in my target_link_libraries line.
It compiles ok now. 🙂
cgs said:
I’m planning to use your efforts into my own car computing project. Now I can send GPS location through 3G when anyone is driving, but I will try to do so only when my Raspberry detects a person different than me. Merci Pierre!
Ken said:
Thank you, Pierre.
I tried Magic Mirror 2.
It’s wonderful.
Wes Lowe said:
Running into an issue with the make of the final code. Not quite sure what I am missing… and noticed someone has an issue like it with Magic Mirror 1 (but they said it wasn’t needed)… so any thoughts as to why I might have this issue?
pi@raspberrypi ~/camcv $ cmake .
— Configuring done
— Generating done
— Build files have been written to: /home/pi/camcv
pi@raspberrypi ~/camcv $ make
Scanning dependencies of target camcv
[ 25%] Building C object CMakeFiles/camcv.dir/RaspiCamControl.c.o
[ 50%] Building C object CMakeFiles/camcv.dir/RaspiCLI.c.o
[ 75%] Building C object CMakeFiles/camcv.dir/RaspiPreview.c.o
[100%] Building CXX object CMakeFiles/camcv.dir/camcv_vid1.cpp.o
In file included from /home/pi/camcv/camcv_vid1.cpp:59:0:
/home/pi/libfacerec-master/include/facerec.hpp:73:41: error: expected class-name before ‘{‘ token
/home/pi/camcv/camcv_vid1.cpp:79:1: error: ‘Eigenfaces’ does not name a type
/home/pi/camcv/camcv_vid1.cpp: In function ‘void video_buffer_callback(MMAL_PORT_T*, MMAL_BUFFER_HEADER_T*)’:
/home/pi/camcv/camcv_vid1.cpp:319:3: error: ‘model’ was not declared in this scope
/home/pi/camcv/camcv_vid1.cpp: In function ‘int main(int, const char**)’:
/home/pi/camcv/camcv_vid1.cpp:711:5: error: ‘model’ was not declared in this scope
make[2]: *** [CMakeFiles/camcv.dir/camcv_vid1.cpp.o] Error 1
make[1]: *** [CMakeFiles/camcv.dir/all] Error 2
make: *** [all] Error 2
Here is my CMakeLists.txt file:
Cmake_minimum_required(VERSION 2.8)
project( camcv )
SET(COMPILE_DEFINITIONS -Werror)
#OPENCV
find_package( OpenCV REQUIRED )
link_directories( /home/pi/libfacerec-master )
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)
add_executable(camcv RaspiCamControl.c RaspiCLI.c RaspiPreview.c camcv_vid1.cpp)
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 ${OpenCV_LIBS})
Pierre said:
humm, in the code, you need to change some hard-coded path.
For example: #include “/home/pi/pierre/libfacerec-0.04/include/facerec.hpp” //<– to modify
have you modified it ?
Wes Lowe said:
Sure did – actually even searched the file for anything ‘pierre’ and only find your name in the comments or the user list. Plus, all of the directories listed in the errors are all valid. I have a feeling I missed a step or my CMakeLists file is incorrect (maybe I am missing something in there)? I really appreciate your help Pierre. From what I have seen so far – this is really awesome!
Pierre said:
libfacerec-master
Are you sure you installed the version 0.04 as explained in step 3 : https://thinkrpi.wordpress.com/2013/04/05/step-3-install-softwares-for-webcam-and-computer-vision/
Majid said:
Wes Lowe
Hi;
what have you done about your problem ?
would appreciate to share with me. I have same problem. But no one help me !
regards
Rémi Auguste said:
Hello,
I wrote smartdetect mostly for processing Full-HD and HD-Ready videos. I don’t think it would really improve anything on low resolution video. You can improve the detection by setting the number of persons you expect to find and their size.
Best regards,
Rémi
Pierre said:
thank you Rémi for your comment ! (I was sure it was working somehow :-))
jack said:
hy pierre.i have made everythings and have this result when launching it:
pi@raspi ~/camcv $ ./camcv recophotos.txt 1 5500
start
(init) People initialized
(init) 8 pictures read to train
(init) 5 pictures of Jacques (0) read to train
(init) 3 pictures of Nathalie (1) read to train
(init) 0 pictures of Mona Lisa (2) read to train
(init) 0 pictures of Lisa (3) read to train
(init) taille images ok
(init) start train images
OpenCV Error: Unsupported format or combination of formats (In the Eigenfaces method all input samples (training images) must be of equal size! Expected 10000 pixels, but was 0 pixels.) in train, file /home/pi/libfacerec/src/facerec.cpp, line 60
terminate called after throwing an instance of ‘cv::Exception’
what(): /home/pi/libfacerec/src/facerec.cpp:60: error: (-210) In the Eigenfaces method all input samples (training images) must be of equal size! Expected 10000 pixels, but was 0 pixels. in function train
Abandon______
i dont know where is my error.
sorry for dirty english
Wes Lowe said:
I had the same issue and (not that I fully remember now) I think I had to modify the cpp code to remove the extra users that didn’t have any pictures in your CSV file. In your error above it is showing 0 pictures for Mona Lisa and Lisa – remove them from the code, recompile and try again.
pierre said:
hello. It says that one picture is 0x0 pixel = empty file. It looks like your csv file contains a blank line (certainely the last one). Check it.
jack said:
i do it but same result (exept the 2 lines with mona lisa and lisa).
perhaps a jpeg issue because my jpegs photos from “Windows” have JPG ext and i change it for jpg for use it with ” prepare photos”.
Thanks for your help.I search again (3 days i’m searching)
jack said:
pierre. it is that.
i have 1 blank line.
now it is the lbp cascade_ frontface.xml not loaded.
i have changed the path :
fn_haar= “/usr/share/opencv/haarcascades/lbpcascade_frontalface.xml”
with:
fn_haar = “/usr/share/opencv/lbpcascades/lbpcascade_frontalface.xml”
Now it is working ……………..thanks very much
jack said:
i have changed the #define MAX_PEOPLE 4 too for 2.
i have an mmal error message : failed to run camera app.
but the application is running.
just the text is missing in the image, perhaps because it can’t reconise my face.
jack said:
hi pierre.
is a relation with your job in the MMAL PARAMETER FACE TRACK fonctions and structures (in mmal parameters camera.h lines 400/440) or it is an MMAL fonctionnality ,?
Amogh Gudi said:
Yes, I have the same question! From what I understand, this code does not make use of these seemingly “inbuild” MMAL function whose names suggest that it can track and identify faces. I would assume using MMAL functions to do this can increase the speed because it utilizes the GPU optimally? Pierre, please respond! 🙂
Pierre said:
yes, I used MMAL function because it gives quick access to the cam. (and by the way the only way to access to the built-in cam, since the standard opencv function can’t see the built-in RPI cam…
Amogh Gudi said:
Yay, a fast response!
Yes, I know you used MMAL functions to access the cam. But I was referring to the parameters mentioned in mmal_parameters_camera.h file: Things like MMAL_PARAMETER_FACE_TRACK, MMAL_PARAMETER_FACE_TRACK_T, MMAL_PARAMETER_DRAW_BOX_FACES_AND_FOCUS, MMAL_PARAMETER_FACE_TRACK_RESULTS, MMAL_PARAM_FACE_DETECT_ON etc.
(Link: https://github.com/raspberrypi/userland/blob/master/interface/mmal/mmal_parameters_camera.h#L407)
So my question is: Are there in-build MMAL functions for face detection/recognition and tracking? If so, how can we use them? Again, I’m assuming that using these MMAL functions for face tracking can be much faster than using OpenCV functions because MMAL can use GPU better? Correct me if I’m wrong: I totally could be!
Cheers!
Tim said:
It looks very promising and it recognises both myself and mona lisa BUT… almost any other male person also get recognised as “Tim”. And tuning up the level of certainty only makes it harder to recognise myself instead of seeing the difference between people. Did you manage to increase this recognition performance yet?
Pierre said:
Tim,
in order to be recognized, you must first be learnt… If you only put 2 pictures (Tim and Mona), the soft will have only 2 choices and thus will propose “Tim” for all others male “by default”. If you want to improve your system : 1) learn as many people the system will meet (complex) 2) or do a collection of male picture called “others”. Thus, the soft will now know 3 people Tim, Mona and others male. Same for a group of “others” female pictures. Is that clear ?
Tim said:
Very clear, thanks for the quick response! I wouldn’t expect this behavior because it also has a ‘face but not identified’ status (just the white box). Are you sure it works like that? I’ll try later by deleting my pics and see if i’ll become mona 🙂
Tim said:
I’ve tested around a bit with different source images, prepared faces, 1/0 histo equalisation etc. but my conclusion is that it simply sees way too little unique characteristics in faces. Other males who aren’t enrolled get similair confidence scores with my pictures as I get. And when I do enroll these other males it recognises us almost randomly as each other, even as mona lisa.
So to use it for example as access control (when you definately want to exclude unknown people) it’s unsuitable in this state. I’ll test further with the other cascades now.
Pierre said:
I must admit you’re right : and for my own usage, I’m back to haarcascade_frontalface_alt. Response time is worst, but results are far better…
joefly said:
ok, I downloaded the code and compiled it and got
pi@raspberrypi ~/camcv $ ./camcv
start
usage: ./camcv ext_files seuil(opt)
files.ext histo(0/1) 5000
i downloaded camcv-vid1.cpp and altered the makefile. Is this all I needed to do? A step by step would be appreciated
jack said:
look at the magic Mirror project to understand .
it is a program to prepare photos and you need a csv file (ext_file in comman line) with path for every train photos.
my command line is :./camcv recophotos.txt 1 5500
recophotos.txt is my csv file, 5500 is seuil value.
Nishaad Salvapantula said:
Hi Pierre,
I am using your C++ code to enable me to use an image processing program of my own for an object finding application.
I was wondering how i turn off the timeout that causes the program to stop at 65 seconds.
gugahoi said:
Just wandering why YCrCb is used when grabbing image from the camera? Is there a way to use RGB or even better for me HSV?
Cheers
xicota said:
I’m getting following error :
……..
(init) Load module : ok
mmal: main: failed to create preview component
mmal: failed to run camera app. please check for firmware updates
2654878406 seconds for 0 feames : FPS = 0.000000
i did an upgrade/update twice and rebooted…
Hope you can help
iruvang said:
hi xicota, I have same problem, how to fix this problem?
dubis said:
Hi,
change the following line inside the camcv_vid1.cpp file:
else if (!raspipreview_create(&state.preview_parameters))
to:
else if ((raspipreview_create(&state.preview_parameters) != MMAL_SUCCESS))
Yu said:
Hello, Pierre.
I appreciate your project so much.
But when i entered ./camcv faces 1 5800 it occurred an error as following:
OpenCV Error: Insufficient memory (Failed to allocate 362797060 bytes) in OutOfMemoryError, file /build/opencv-XZa2gn/opencv-2.3.1/modules/core/src/alloc.cpp, line 52
terminate called after throwing an instance of ‘cv::Exception’
what(): /build/opencv-XZa2gn/opencv-2.3.1/modules/core/src/alloc.cpp:52: error: (-4) Failed to allocate 362797060 bytes in function OutOfMemoryError
do you have any idea with it?
thx
Spencer said:
Is all this fine on the rapsberry pi? I’m having trouble with step 2
Scott Winterrigner said:
I would love a prebuilt image file, it would really benefit many users as some of the source for these projects is disappearing.
Dennis van Elteren said:
Pierre, I made a csv file, I put 3 jpg’s in a folder called mona and they are read in the train. Then all the sudden I get an error that I do not see in the post nor in the replies on this page: error: (-13) :the matrix is not continuous
Do you or any reader have a clue how to solve this…?
Roman said:
Hi Pierre,
nice tutorial! Thanks for your effort to build and share that project.
Now as i want to some other stuff beside facerecon, i need a bigger FPS and also a higher resolution.
For that i was thinking why not just grab raw rgb frames instead of the i420 (as a memcpy would likely be faster than the transformation vrom YUV to RGB).
This ofcorse leads me to the problem, that I have to know how data are stored in the buffer->data section. For that I was hoping you could tell me how you knew how the i420 buffer->data section is organized?
Do you have any ohter Idea how to increas FPS and resolution for an openCV processing?
Thanks again for your effort and sharing! I appreciate it!
thx
Pierre said:
Hello
well, it was the purpose of its blog to explain how to get a high FPS with a RPI.
unfortunatly, I met the same limits as you : I don’t know how data are stored in data buffer.
Yas said:
Hi Pierre,
First of all, awesome tutorial! There were some gaps but the comments section on here helped me through each of them. I’ve tried other tutorials and none were as thorough and easy to follow as yours. Good job!
Now what I’m trying to is 2 things.
1. How can I make this program run without exiting? Currently camcv_vid01 runs for a certain amount of time which is passed to it via the command line. I want it to run perpetually.
2. Is there a good way of getting the x and y coordinates of the center of the square (face)? As you may have guessed, I want to put servos on this and make a face tracking thing where the face is always in the center of the camera 🙂
Help would be truly appreciated.
Pierre said:
Hi Yas,
1. play with state->timeout and vcos_sleep(state.timeout); Add a command line parameter to change this value. Should be easy.
2. face_i is a rectangle. To find the center, just use the 2 corners face_i.tl() and face_i.br(). Something like Cx = (face_i.tl().x + face_i.tl().x)/2; same for Cy. (if you are in an Euclidian world, which is still to be proven).
Yan said:
Hi Pierre,
pi@raspberrypi ~/camcv $ sudo ./camcv_vid1 abc.txt 1 5500
start
(init) People initialized
(init) 2 pictures read to train
(init) 2 pictures of Pierre (0) read to train
(init) 0 pictures of Natacha (1) read to train
(init) 0 pictures of Mona Lisa (2) read to train
(init) 0 pictures of Lisa (3) read to train
(init) taille images ok
(init) start train images
OpenCV Error: Image step is wrong (The matrix is not continuous, thus its number of rows can not be changed) in reshape, file /build/opencv-XZa2gn/opencv-2.3.1/modules/core/src/matrix.cpp, line 750
terminate called after throwing an instance of ‘cv::Exception’
what(): /build/opencv-XZa2gn/opencv-2.3.1/modules/core/src/matrix.cpp:750: error: (-13) The matrix is not continuous, thus its number of rows can not be changed in function reshape
Can you help me to solve this problem?
Thanks a lot!!!
Pierre said:
are you sure image have same size ?
anyway, it’s an opencv error code, maybe you will find solution using google.
Yan said:
oh ~ I change the image and then it works!!!
I am so excited!
You are so great!
zineb said:
how did you change the image , i have the same problem
thank you
Manjunath Joshi said:
OpenCV Error: Image step is wrong (The matrix is not continuous, thus its number of rows can not be changed) in reshape, file /build/opencv-XZa2gn/opencv-2.3.1/modules/core/src/matrix.cpp, line 750
terminate called after throwing an instance of ‘cv::Exception’
what(): /build/opencv-XZa2gn/opencv-2.3.1/modules/core/src/matrix.cpp:750: error: (-13) The matrix is not continuous, thus its number of rows can not be changed in function reshape
can any one explain how to fix this??? please…
Dennis said:
Hi Pierre and the others
In the mean time (after my previous post) I got it all up and running. I did an improvement like Pierre suggested: add pictures of other males (others). I found an archive with 40 persons each 10 pics and edited nicely to 100×100 jpg so its the same size and format as Pierre’s nice picture tool. Now I get much much better results. I thought I share the pics and csv file with you (csv with that many pics is quite some work).
Oh, the csv file has only 50 pics, the facerec software could not handle 400 of them. I works nicely with 50. You have to edit the cpp file, I changed lise in “others” and display a text “unidentified other male person”. Enjoy!
http://www.4shared.com/zip/6ywGF1dB/100×100.html
Pierre said:
Thank you for the work ! It’s a very good news for everybody, it ‘ll help us a lot !
Dennis said:
Tnx Pierre, and many tnx to you for making face recognition on the Pi possible, it almost looks easy!
ds said:
I get the same error as xicota:
mmal: main: failed to create preview component
mmal: failed to run camera app. please check for firmware updates
But raspistill works, camcv_vid0 too…
Pierre (and the others), have you any suggestion?
Ian said:
Hi, i have the same problem with you. did you know how to solve it?
Jennifer Dos Reis said:
I’ve got segmentation fault. It appears when I do the model.train(images, labels); instruction.
I don’t understand why =/ .. Hope you can help me please!
Pierre said:
hello. Certainly because pictures have not all the same size or not jpg format… perhaps one is empty ?
Dennis said:
Try it with my pictures, there is a link to 4shared.com in my post above, those pictures are all the same size 100×100 pixels and are jpg so then size or format problems can be ruled out
Jennifer Dos Reis said:
Thanks for your answers!
I checked my pictures and all have the same size, none is empty, but I realized they are in JPEG format. It is fine?
I tried also with 39 firsts Dennis’ pics (also are in JPEG format).
In both cases I’ve got segmentation fault:
start
(init) People initialized
(OK) csv=csv.txt
(init) 39 pictures read to train
(init) 39 pictures of Pierre (0) read to train
(init) 0 pictures of Natacha (1) read to train
(init) 0 pictures of Mona Lisa (2) read to train
(init) 0 pictures of Lisa (3) read to train
(OK) read CSV ok
(init) taille images ok
(init) start train images
Segmentation fault
I’m working with opencv-2.4.7 and the previous steps worked fine
Dennis said:
Jennifer, then I don’t know whats wrong, hopefully Pierre?
perfo said:
With Magic Mirror version 1 (with USB cam) when ever I got a segment fault it was always down to something wrong with my pictures.. Try just two pics and if that works build up to the full amount. I haven’t got MM version 2 working yet so can’t tell you if it’s the same as ver 1 with this fault but I’m guessing it will be.
Larry said:
Does anyone have a fully working version of this they would be willing to create a .img of, so I can see where I’m going wrong?
philsprojects said:
I was getting the error:
(E) face cascade model not loaded :/usr/share/opencv/haarcascades/lbpcascade_frontalface.xml
until I searched camcv_vid1.cpp and replaced:
/usr/share/opencv/haarcascades/lbpcascade_frontalface.xml
with
/usr/share/opencv/lbpcascades/lbpcascade_frontalface.xml
Misscy said:
Hi Pierre and the others, many thanks for your work and sharing !
Everything works fine until I try to compile the “Step 7 – Face Regognition”….
I got the following errors:
//——————————————————-
CMakeFiles/camcv.dir/camcv.cpp.o: In function `default_status(RASPIVID_STATE*)’:
camcv.cpp:(.text+0x798): undefined reference to `raspipreview_set_defaults(RASPIPREVIEW_PARAMETERS*)’
camcv.cpp:(.text+0x7a8): undefined reference to `raspicamcontrol_set_defaults(RASPICAM_CAMERA_PARAMETERS*)’
CMakeFiles/camcv.dir/camcv.cpp.o: In function `create_camera_component(RASPIVID_STATE*)’:
camcv.cpp:(.text+0x16c4): undefined reference to `raspicamcontrol_set_all_parameters(MMAL_COMPONENT_T*, RASPICAM_CAMERA_PARAMETERS const*)’
CMakeFiles/camcv.dir/camcv.cpp.o: In function `main’:
camcv.cpp:(.text+0x2028): undefined reference to `raspipreview_create(RASPIPREVIEW_PARAMETERS*)’
camcv.cpp:(.text+0x225c): undefined reference to `raspipreview_destroy(RASPIPREVIEW_PARAMETERS*)’
camcv.cpp:(.text+0x227c): undefined reference to `raspicamcontrol_check_configuration(int)’
collect2: ld returned 1 exit status
make[2]: *** [camcv] Error 1
make[1]: *** [CMakeFiles/camcv.dir/all] Error 2
make: *** [all] Error 2
//——————————————————-
Here is my CMakeLists.txt
//——————————————————-
cmake_minimum_required(VERSION 2.8)
project(camcv)
SET(COMPILE_DEFINITIONS -Werror)
find_package( OpenCV REQUIRED )
link_directories( /home/pi/libface )
include_directories(/opt/vc/userland)
include_directories(/opt/vc/userland/host_applications/linux/libs/bcm_host/include)
include_directories(/opt/vc/userland/interface/vcos)
include_directories(/opt/vc/userland/interface/vcos/pthreads)
include_directories(/opt/vc/userland/interface/vmcs_host/linux)
add_executable(camcv RaspiCamControl.c RaspiCLI.c RaspiPreview.c camcv.cpp)
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 /home/pi/libface/libopencv_facerec.a ${OpenCV_LIBS})
//——————————————————-
What’s wrong ?! Thanks for the help 😉 !
Shivu said:
Hi Pierre and others,
I am getting the “Image Step is wrong” error. I tried everything but am not able to overcome this. Can anybody help out in solving this. Thanks a lot.
Nate said:
Shivu did you figure this out? I keep getting the same error as well
OpenCV Error: Image step is wrong (The matrix is not continuous, thus its number of rows can not be changed) in reshape, file /build/opencv-XZa2gn/opencv-2.3.1/modules/core/src/matrix.cpp, line 750
I have googled and used .jpg and .png images, I have used the sample images shown above (downloaded them) and my own pictures with pierre’s resizing code without success. I have checked the .csv file, I have changed the # of pictures trained from 1 up to 10. Any other ideas?
Michael said:
Just FYI if you are still checking this there is now a much easier way to get the camera up and running by using UV4L driver here – http://www.linux-projects.org/modules/sections/index.php?op=viewarticle&artid=14
This then works natively with OpenCV just like a usb webcam would. There are some more examples here – http://www.linux-projects.org/modules/sections/index.php?op=viewarticle&artid=16
Nate said:
Thank you for the reply Michael, I will look into that! I really appreciate the tip!
jschilen said:
Hello,
I’m receiving the following error when trying to compile. I downloaded camcv_vid1.cpp and changed the name to camcv.c.
pi@raspberrypi ~/camcv $ make
[ 7%] Building C object CMakeFiles/camcv.dir/RaspiCamControl.c.o
[ 15%] Building C object CMakeFiles/camcv.dir/RaspiCLI.c.o
[ 23%] Building C object CMakeFiles/camcv.dir/RaspiPreview.c.o
[ 30%] Building C object CMakeFiles/camcv.dir/camcv.c.o
/home/pi/camcv/camcv.c:28:8: error: expected identifier or ‘(‘ before string constant
/home/pi/camcv/camcv.c:49:20: fatal error: iostream: No such file or directory
compilation terminated.
make[2]: *** [CMakeFiles/camcv.dir/camcv.c.o] Error 1
make[1]: *** [CMakeFiles/camcv.dir/all] Error 2
make: *** [all] Error 2
Thanks
rayrenteria said:
Rename camcv.c to camcv.cpp . The .cpp extension is important.
Anup said:
Hi all, I am trying to rotate the video by 180 degrees. I tried adding the code
state->camera_parameters.rotation = 180;
It compiles but does not work. Any ideas ?
Matthew said:
Hello when i Compile this last part…. camcv_vid1.cpp i receive this error.
Scanning dependencies of target camcv
[ 7%] Building C object CMakeFiles/camcv.dir/RaspiCamControl.c.o
[ 15%] Building C object CMakeFiles/camcv.dir/RaspiCLI.c.o
[ 23%] Building C object CMakeFiles/camcv.dir/RaspiPreview.c.o
[ 30%] Building CXX object CMakeFiles/camcv.dir/camcv_vid1.cpp.o
In file included from /home/pi/camcv/camcv_vid1.cpp:59:0:
/home/pi/libfacerec-0.04/include/facerec.hpp:33:7: error: redefinition of ‘class cv::FaceRecognizer’
/usr/local/include/opencv2/contrib/contrib.hpp:921:24: error: previous definition of ‘class cv::FaceRecognizer’
make[2]: *** [CMakeFiles/camcv.dir/camcv_vid1.cpp.o] Error 1
make[1]: *** [CMakeFiles/camcv.dir/all] Error 2
make: *** [all] Error 2
I haven’t seen any issues like it above (which i might have overlooked but i looked 3 times through) I was curious what the error meant by redefinition of ‘class cv::FaceRecognizer’
Thank you
jinda said:
hello Matthew i am stuck at same error i tired to change facerec.hpp & contrib.hpp but could not fix the problem. if u have fixed the error please help me out.
Philip said:
Hi Matthew,
Did you solve this issue as I am getting the same error
Philip said:
For others who have the same issue, I solved it by replacing the contrib.hpp file downloaded with “sudo apt-get install libopencv-dev” with the contrib.hpp file extracted from version 2.3 of the opencv library downloaded from here: http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.3.1/OpenCV-2.3.1a.tar.bz2/download
Works a treat now – however just need to get it to id me not “an unknown male”
Cheers
Simone said:
Hi Philip, I can’t find the contrib.hpp file in the archive you linked to. Has it changed? What were the changes from the apt-get version?
DomoJimbo said:
Hi Pierre,
I would like to thank you for your amazing work.
I managed to get camcv_vid1 up and running, but I have a lot of false detection.
It seems that you have shared some training pictures, but the file is no more there on http://www.4shared.com/zip/6ywGF1dB/100×100.html.
=> does it possible to share again ?
What are you advices ? I want to detect 4 different people, and I have put 10 pictures of each faces. Is that right ? shall I add or remove pictures ? remove one or two people ? Is there an issue with people with glasses ?
Thank you in advance.
Perfo said:
I’m afraid there doesn’t seem to be a way of not getting false detection. I’ve had it up and running for some time now and included over 50 pics of each of my subjects. If you turn up the validation rules it will recognise no one and turn it down it’ll be 20% accurate. Don’t get me wrong it is a fantastic little bit of programming and does work but I think you have to be realistic on the accuracy of it. I had hoped for in the 90’s % accuracy but alas I haven’t achieved it. Of course if I’m the odd one out and some one has some suggestions then I’ll only be too happy to try them..
DomoJimbo said:
Perfo, don’t get me wrong also, this piece of code is amazing ! I just wanted to get tips to get it to work as perfect as possible.
By the way, do you have the zip sent of training faces (was shared on http://www.4shared.com/zip/6ywGF1dB/100×100.html but no more available here)
Thanks !
Perfo said:
I may still have it on my PC at home. I wont be there for about a week but I’ll have a look then if you haven’t managed to find it anywhere.
DomoJimbo said:
No way to find it ! then thanks in advance if you can find it and share it back.
DomoJimbo said:
Pierre has shared back the zip file on https://thinkrpi.wordpress.com/2013/11/05/40-anonymous-pictures-for-a-better-recognition/.
Thank you
Perfo said:
Thanks Pierre. That saved me trying to hunt it down I know I included a lot od pics on my PI so not sure if I had the original.
Realistically Mr Pierre how accurate did you manage to get this thing to work ?
As said above I only have four people I’d like to identify A woman , man and two kids with very different features (distance between eyes facial hair etc etc) but I can’t get reliable enough to use.
I still thinks its a very cool project though….Thanks…
Guillaume said:
Thank you so much Pierre.
All is okay for me, it works !
You gauged your explanations just right in this tutorial.
I think I understand the major part of what you did.
I will continue with robotics projects.
Merci encore.
Chris said:
Hi Pierre,
how can the Programm be stopped when there is a face detected?
It should stop after the timeout OR when a face is detected.
A solution with goto or changing vcos_sleep dident’t work.
Any Idea?
Thanks very much 🙂
Chris said:
Hi Pierre,
is there a way of stopping the program when a face has been detected?
I tried solutions with “goto” and changing “vcos_sleep” but it diden’t work 😦
Thank you very much 🙂
Chris
ehk said:
hi. pierre and other.
I have some problem on following your blog.
/////////
pi@raspberrypi ~/camcv $ sudo ./camcv_vid1 abc.txt 1 5500
start
(init) People initialized
(init) 8 pictures read to train
(init) 2 pictures of Pierre (0) read to train
(init) 2 pictures of Natacha (1) read to train
(init) 2 pictures of Mona Lisa (2) read to train
(init) 2 pictures of Lisa (3) read to train
(init) taille images ok
(init) start train images
OpenCV Error: Image step is wrong (The matrix is not continuous, thus its number of rows can not be changed) in reshape, file /build/opencv-XZa2gn/opencv-2.3.1/modules/core/src/matrix.cpp, line 750
terminate called after throwing an instance of ‘cv::Exception’
what(): /build/opencv-XZa2gn/opencv-2.3.1/modules/core/src/matrix.cpp:750: error: (-13) The matrix is not continuous, thus its number of rows can not be changed in function reshape
////
I took photos(10 photos) and then use “raspistill -t 2000 -o 001.jpg -w 100 -h 100” runnning camcv. but I still got same problem. what should I do? : (
dubis said:
Hi,
I’ve got the video and the face are inside a scare, but there is no ID detected.
Do you have any idea where is from ?
Here my cvs file where I put 3 pictures in BW sized 100x100px of myself.
/home/pi/Faces/dubis/dubis_1.jpg;0
/home/pi/Faces/dubis/dubis_2.jpg;0
/home/pi/Faces/dubis/dubis_3.jpg;0
/home/pi/Faces/monalisa/monalisa.jpg;1
Nadine said:
Hey
I had this matrix is not continuous error – it was a wrong path on the csv file ( /home/pi/camcv/….jpg;0 worked for me)
However, having this solved I end up with a mmal error
(mmal: main: Failed to create preview component
mmal: Failed to run camera app. Please check for firmware updates)
I know we solved this problem in earlier steps by changing a line in the code (else if (status = raspipreview_create(&state.preview_parameters) != MMAL_SUCCESS ) but if I do this with the vid1 file it won’t compile…
So I seem to be stuck either with a non compiled version or the version where everything works (including raining of pictures is prompted ok, but with a mmal error after the successful training).
Any ideas?
Thank you very much (and thanks for the great blog and all your helpful comments – I would certainly not be with the code where I am without you!)
Cheers
Nadine
Kurt Liebenberg said:
I installed opencv 2.4.9 on my raspberry and everything worked until this step. If i want to build the camcv_vid1.cpp I receive the following errors:
[ 7%] Building CXX object CMakeFiles/camcv.dir/camcv_vid1.cpp.o
/root/camcv/camcv_vid1.cpp:79:1: error: âEigenfacesâ does not name a type
/root/camcv/camcv_vid1.cpp: In function âvoid video_buffer_callback(MMAL_PORT_T*, MMAL_BUFFER_HEADER_T*)â:
/root/camcv/camcv_vid1.cpp:319:3: error: âmodelâ was not declared in this scope
/root/camcv/camcv_vid1.cpp: In function âint main(int, const char**)â:
/root/camcv/camcv_vid1.cpp:711:5: error: âmodelâ was not declared in this scope
make[2]: *** [CMakeFiles/camcv.dir/camcv_vid1.cpp.o] Error 1
make[1]: *** [CMakeFiles/camcv.dir/all] Error 2
make: *** [all] Error 2
It looks like there is a library missing. If I wouldn’t use opencv 2.4.9 I would say the facerec part is missing, but this part should be included in my opencv installation.
So can someone help me?
metso said:
I get a fairly similar type of error. Please help.
..
Linking CXX executable camcv_vid1
CMakeFiles/camcv_vid1.dir/camcv_vid1.cpp.o: In function `video_buffer_callback(MMAL_PORT_T*, MMAL_BUFFER_HEADER_T*)’:
camcv_vid1.cpp:(.text+0xb90): undefined reference to `cv::Eigenfaces::predict(cv::_InputArray const&, int&, double&) const’
collect2: ld returned 1 exit status
CMakeFiles/camcv_vid1.dir/build.make:407: recipe for target ‘camcv_vid1’ failed
make[2]: *** [camcv_vid1] Error 1
CMakeFiles/Makefile2:60: recipe for target ‘CMakeFiles/camcv_vid1.dir/all’ failed
make[1]: *** [CMakeFiles/camcv_vid1.dir/all] Error 2
Makefile:72: recipe for target ‘all’ failed
make: *** [all] Error 2
metso said:
To reply myself, I found the solution! A bit similar to what Perfo did earlier I added /libopencv_facerec.a to the list of target_link_libraries of CMakeLists.txt. Compiles ok now!