MasteringOpenCV / code

Code for the book "Mastering OpenCV with Practical Computer Vision Projects" by Packt Publishing 2012.
Other
2.73k stars 1.65k forks source link

Chapter 8 How to run #21

Closed DangThu closed 10 years ago

DangThu commented 10 years ago

Excuse me. Anyone can help me how to run clearly by the main program Visual Studio 2010? If i build the "main.cpp", where must i put the files: detectoject.h, detectOject.cpp,... and the other files in the list of codes? I try to build, but the program reported the error:

"Error 1 error LNK2019: unresolved external symbol "class cv::Mat cdecl reconstructFace(class cv::Ptr,class cv::Mat)" (?reconstructFace@@YA?AVMat@cv@@V?$Ptr@VFaceRecognizer@cv@@@2@V12@@Z) referenced in function "void cdecl recognizeAndTrainUsingWebcam(class cv::VideoCapture &,class cv::CascadeClassifier &,class cv::CascadeClassifier &,class cv::CascadeClassifier&)" (?recognizeAndTrainUsingWebcam@@YAXAAVVideoCapture@cv@@AAVCascadeClassifier@2@11@Z) C:\Users\El Nino\Documents\Visual Studio 2010\Projects\facerecmain\facerecmain\facerec.obj" Thanks so much. and how can i use the cmake to run the program as the read me file tell ?

shervinemami commented 10 years ago

Hi DangThu, you should follow the steps in the README file for that project. It shows how to generate a Visual Studio solution file using CMake, and then you open that solution file with Visual Studio. Then you use Visual Studio to build (compile & link) the code. To run the program, follow the README file because it explains the arguments needed to run it.

DangThu commented 10 years ago

Thanks for your help. :) when i install the VS 2010, i used cmake to install open cv 2.4.6. Following the step in README is for this solution only or for VS 2010? I don't understand clearly. Could you show me how to open CMAKE command-line mode ? I use Cmake 2.8. By the way, could you upload the file in this link again? I found it in your text at shervinemami.info.

https://sourceforge.net/projects/facerec/

I really need it. Thank you.

shervinemami commented 10 years ago

The first step is that you install VS 2010, then you use CMake to generate OpenCV build files, and open the generated project in Visual Studio (ie: double-click the SLN file or similar) and click on "Build Solution" to compile the OpenCV library using Visual Studio, and then also build the "Install" project to copy the OpenCV library to your Windows system folder. Now you would have OpenCV correctly installed.

The next step is to do similar for this face recognition project: follow the steps in the README file to generate the build files for this project, then open the generated project in Visual Studio, then build the project in Visual Studio. Now you should have the face recognition program.

Finally, follow the instructions at the bottom of the README file to see how to actually run the program.

DangThu commented 10 years ago

Thanks. i'll try again. But i don't understand the tutorial: "Building the project using CMake from the command-line"

I configure the program and run it on windows 7. The Cmake program has to be run in the mode command line (DOS) ? Because the CMAke on windows i see it run with a gui, not command mode ? Thanks for comments ! :)

DangThu commented 10 years ago

I tried running the command in the tutorial "Building the project using CMake from the command-line" for windows on cmd.exe. But at the 2 last commands: "cmake -G "Visual Studio 9 2008" -D OpenCV_DIR=%OpenCV_DIR% .. start WebcamFaceRec.sln " the errors "Cmake Error: Could not create named generator Visual Studio 9 2008" and "The system cannot find the file Webcamfacerec.sln" I put all the file .h and .cpp you upload in the folder in C:\OpenCV\facerec. So the first command: " set OpenCV_DIR="C:\OpenCV\build" I wrote: set OpenCV_DIR="C:\OpenCV\facerec"

Did i have any mistakes ? WHere do i have to put the .h and .cpp files you upload in ?

Thank you very much.

shervinemami commented 10 years ago

You shouldn't need to move any files at all! But yes you can use the graphical CMake instead of the command-line cmake. It looks like maybe you have changed the original folder structure, so to be safe you should delete the "C:\OpenCV\facerec" folder, and extract the code again to somewhere new, like "C:\MasteringOpenCV\" and so you would have something like a "C:\MasteringOpenCV\Chapter 8" folder. Then open the graphical Cmake, it should show 2 folder locations at the top. For the first entry, tell it to open the project at "C:\MasteringOpenCV\Chapter 8", and for the 2nd entry, tell it to generate a folder at "C:\MasteringOpenCV\Chapter 8\build". Now in the configuration options below it, there should be an option for "OpenCV_DIR", and you should set that to the place where you installed OpenCV, such as "C:\OpenCV" or C:\OpenCV\install" or wherever you installed OpenCV to. Then you tell it to Configure, and Generate, for your compiler (Visual Studio 10 2010). It should generate a project solution for the facerec project at "C:\MasteringOpenCV\Chapter 8\build". So then you double-click the project in that folder, and it should open in VS2010. Then switch to Release mode instead of Debug mode, and click on "Build All" or similar to build the facerec project. Then if it has succesfully built, follow the instructions in the README to run the project.

DangThu commented 10 years ago

Thanks so much. I run the program successfully . The last problem is my web camera. I used the laptop with an integrated web camera. When i run the program, it reported "Couldn't grap the next camera frame", the window showing image from camera apeared then disappeared immediatly. I plug another web camera to connect with laptop by the USB. But the same error occured. How can i fix this problem ? And how i choose one of 2 cameras ? THanks.