Cannot compile mergevec.cpp from Haartraining tuto

2019-05-01 04:06发布

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.

3条回答
女痞
2楼-- · 2019-05-01 04:21

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

查看更多
爷、活的狠高调
3楼-- · 2019-05-01 04:23

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.

查看更多
老娘就宠你
4楼-- · 2019-05-01 04:23

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`
查看更多
登录 后发表回答