开发者

Cannot compile mergevec.cpp from Haartraining tutorial

开发者 https://www.devze.com 2023-03-07 04:50 出处:网络
I have been following this tutorial ( http://note.sonots.com/SciSoftware/haartraining.html ) to do some Haar training.I am currently stuck on creating the training samples, specifically the combining

I have been following this tutorial ( http://note.sonots.com/SciSoftware/haartraining.html ) to do some Haar training. I am currently stuck on creating the training samples, specifically the combining of the .vec files. I am provided with this ( http://note.sonots.com/SciSoftware/haartraining/mergevec.cpp.html ) file and a description of how to build it for Linux (Ubuntu 11.04). 开发者_如何学编程Here lies my problem, I am unable to build the mergevec code. The only error is "fatal error: cvhaartraining.h: No such file or directory." I have checked to make sure that cvhaartraining.h is in the same directory as mergevec but have found everything to be right where I would expect it. At this point, I am at a loss of how to solve this, so any help would be greatly appreciated.


For building mergevec I found that the easiest way was to edit CMake configuration files. In OpenCV 2.3.1, the haartraining directory is in modules/haartraining whereas in 2.4.5 it is in apps/haartraining. Either way, the file you are interested in editing is called CMakeLists.txt.

The easiest thing to do is to add a special section for mergevec, as follows:

# -----------------------------------------------------------
#  mergevec
# -----------------------------------------------------------
add_executable(opencv_mergevec mergevec.cpp)
set_target_properties(opencv_mergevec PROPERTIES
                      DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
                      OUTPUT_NAME "opencv_mergevec")

You can add this right before the installation section. Then place mergevec.cpp into the haartraining directory, build OpenCV normally, and you will have an opencv_mergevec binary which is the mergevec.cpp executable.


For others struggling with this on Ubuntu, move the flags to the end of the invocation, like this:

g++ -I. -o mergevec mergevec.cpp cvboost.cpp cvcommon.cpp cvsamples.cpp cvhaarclassifier.cpp cvhaartraining.cpp `pkg-config --libs --cflags opencv`


To fix your problem type the following:

g++ `pkg-config --libs --cflags opencv` -I. -o mergevec mergevec.cpp cvboost.cpp cvcommon.cpp cvsamples.cpp cvhaarclassifier.cpp haartraining.cpp   -lopencv_core -lopencv_calib3d -lopencv_imgproc -lopencv_highgui -lopencv_objdetect

Good Luck Ibrahim

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号