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

Revision history [back]

As you have noticed your code is failing because it cannot open the cascade file "haarcascade_frontalface_alt.xml". Your error handling code is not ideal, because although it reports the error it doesn't stop execution. This means that it prints out the "cannot load cascade file" message but then continues with the algorithm anyway.

If you add the line

exit(1);

after printing the message within the if statement then the error will not only be reported but OpenCV won't then crash afterwards.

Your program will look for the cascade file in its current working directory, what this is will depend on how it is being run, using rosrun or roslaunch. if you change the "haarcascade_frontalface_alt.xml" string to the full path of the file on your system then it should solve this problem. Also if you use rosrun to start your know from the same directory as the cascade file that should also work because the node's working directory will be the same as the file you're trying to load.