ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

issue on compiling package using opencv

asked 2012-05-27 21:16:25 -0500

clark gravatar image

updated 2012-05-28 19:56:51 -0500

I am trying the HOG based human detection algorithm under ros, and following the source file of opencv/samples/cpp/peopledetect.cpp (This source file can be compiled using g++ without issue on my computer, g++ -o output peopledetect.cpp pkg-config opencv --cflags --libs).

But after putting into an ros package, I can't get the similar codes to compile successfully. I did follow the instructions at to set CMakeLists.txt and manifest.xml. But I still keep getting the following compile error,

/home/ros/spyrobot/human_detect/src/human_detect.cpp:27:1: error: ‘hog’ does not name a type make[2]: * [CMakeFiles/human_detect.dir/src/human_detect.o] Error 1 make[1]: * [CMakeFiles/human_detect.dir/all] Error 2 make:* [all] Error 2

The error refers to the following two lines which are copied from the peopledetect.cpp source file,

HOGDescriptor hog;


My current environment, ubuntu 12.04, ROS fuerte, ros-fuerte-opencv2 2.4.0, ros-fuerte-vision-opencv 1.8.2

thanks for your advice in advance



The tricky thing is that I can manually compile the sample peopledetect.cpp file (which also use HOGDescriptor) using, g++ -o test peopledetect.cpp -lopencv_objdetect -lopencv_core -lopencv_highgui -lopencv_imgproc or simply g++ -o test peopledetect.cpp pkg-config opencv --cflags --libs

but why ROS can't compile the package with the similar function call?

PS: Some further info on my pc,

pkg-config --cflags --libs opencv

-I/opt/ros/fuerte/include/opencv -I/opt/ros/fuerte/include -L/opt/ros/fuerte/lib -lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_objdetect -lopencv_photo -lopencv_stitching -lopencv_ts -lopencv_video -lopencv_videostab

Any further suggestions are welcome.


My mistake! I originally wanted to decleare hog as a global variable but put not only its declaration but also the function call


right after the #include (s)... and it is this silly mistake that caused the compile error.

Anyway, thank Kevin again for the help.


edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2012-05-28 00:58:31 -0500

Kevin gravatar image

updated 2012-05-28 07:00:28 -0500

I think you are missing an include file that defines hog ... double check CMakeLists.txt and your cpp file


error: ‘hog’ does not name a type

I think the error is with hog not with opencv? The error message makes no mention of opencv errors. Are you including hog's includes and linking correctly to the right libraries?

Also, why are you not using the opencv 2 headers:

#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>

Don't mix and match OpenCV 1 and 2 headers ... you can get errors.

edit flag offensive delete link more


I have strictly followed the sample file and included the following header files

include <opencv/cv.h>

include <opencv/highgui.h>

include <opencv2/imgproc/imgproc.hpp>

include <opencv2/highgui/highgui.hpp>

include <opencv2/objdetect/objdetect.hpp>

Can't figure out which file I still miss

clark gravatar image clark  ( 2012-05-28 03:57:49 -0500 )edit

Kevein, thanks for the advice. The HOGDescriptor definition is inside <opencv2/objdetect/objdetect.hpp>, and the related lib is -lopencv_objdetect, which is part of opencv2. So the header and library shouldn't be the reason. I also replaced all opencv 1 headers, but the compile is still the same

clark gravatar image clark  ( 2012-05-28 16:36:10 -0500 )edit

Question Tools


Asked: 2012-05-27 21:16:25 -0500

Seen: 1,851 times

Last updated: May 28 '12