ros人脸识别问题OpenCV Error: Assertion failed (!empty()) in detectMultiScale,

 问题:

ERROR: Could not load classifier cascade
OpenCV Error: Assertion failed (!empty()) in detectMultiScale, file /tmp/binarydeb/ros-kinetic-opencv3-3.3.1/modules/objdetect/src/cascadedetect.cpp, line 1698
terminate called after throwing an instance of 'cv::Exception'
  what():  /tmp/binarydeb/ros-kinetic-opencv3-3.3.1/modules/objdetect/src/cascadedetect.cpp:1698: error: (-215) !empty() in function detectMultiScale

解决方案:

OpenCV级联检测器Cascadedetect出现错误,可知是xml路径读取错误,发现在原始代码中face_cascade没有读取.xml文件。

首先安装OpenCV:

sudo apt-get install libopencv-*
sudo apt-get install python-opencv
sudo apt-get install python-imaging

找到程序中加载xml的地方,例如本人代码中错误位置是:

haar_file_face = "/home/dobot/face_detect_ws/src/face_tracker_pkg/data/face.xml";
string cascadeName = haar_file_face;
CascadeClassifier cascade;
if( !cascade.load( cascadeName ) )
{
  cerr << "ERROR: Could not load classifier cascade" << endl;
}

ros中的opencv默认安装的是opencv.3.3.1,其位置为:/usr/share/opencv/haarcascades/

将第一行代码进行修改,修改为:

string cascadeName = "/usr/share/opencv/haarcascades/haarcascade_frontalface_default.xml";
//string cascadeName = haar_file_face;
CascadeClassifier cascade;
if( !cascade.load( cascadeName ) )
{
  cerr << "ERROR: Could not load classifier cascade" << endl;
}

这里的xml文件也可以进行选择,识别眼睛可以选择haarcascade_eye.xml等等。

你可能感兴趣的:(Ubuntu,c++,ros,人脸识别,linux,opencv)