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

Face detection with usb_cam

asked 2020-04-09 22:33:15 -0500

jesusy gravatar image

updated 2020-04-09 22:39:13 -0500

Hello, I'm following this video on How to use ros usb cam for face detection. In the las part, when I run:

rosrun detect_face

And yes, I changed the location of the haar cascades files. It gives me this error:

yepez@user:~/catkin_ws$ rosrun detect_face

[rosrun] Couldn't find executable named below /home/yepez/catkin_w/src/RobotOperatingSystem/detect_face
[rosrun] Found the following, but they're either not files
[rosrun] or not executable:
[rosrun]   /home/yepez/catkin_ws/src/RobotOperatingSystem/detect_face/src/`

This is the file:

 -----#!/usr/bin/env python

   import rospy
   import cv2
   from std_msgs.msg import String
   from sensor_msgs.msg import Image
   from cv_bridge import CvBridge, CvBridgeError
   import sys
   import numpy as np

   bridge = CvBridge()
   face_cascade = cv2.CascadeClassifier('/home/yepez/catkin_ws/src/RobotOperatingSystem/detect_face/src/haarcascade_frontalface_default.xml')
   eye_cascade = cv2.CascadeClassifier('/home/yepez/catkin_ws/src/RobotOperatingSystem/detect_face/src/haarcascade_eye.xml')

  def image_callback(ros_image):
  print ('got an image')
  global bridge
  #convert ros_image into an opencv-compatible image
      img = bridge.imgmsg_to_cv2(ros_image, "bgr8")
  except CvBridgeError as e:
  #from now on, you can work exactly like with opencv

  gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

  faces = face_cascade.detectMultiScale(gray, 1.3, 5)
  for (x,y,w,h) in faces:
      img = cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
      roi_gray = gray[y:y+h, x:x+w]
      roi_color = img[y:y+h, x:x+w]
      eyes = eye_cascade.detectMultiScale(roi_gray)
      for (ex,ey,ew,eh) in eyes:
  cv2.putText(img,'Face Detection with ROS & OpenCV!',(15,450), font, 1,(255,255,255),2,cv2.LINE_AA)

 def main(args):
  rospy.init_node('image_converter', anonymous=True)
  #for turtlebot3 waffle
  #for usb cam
  image_sub = rospy.Subscriber("/usb_cam/image_raw",Image, image_callback)
  except KeyboardInterrupt:
   print("Shutting down")

if __name__ == '__main__':

Thanks in advance for the help.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-04-09 23:42:17 -0500

Did you chmod +x the file to make it an executable?

Also roscd detect_face and make sure that the file exists in the package in that directory to be found. If you messed up install rules it could not be copied. Please add cmakelists. But I'm pretty sure its an executable issue.

edit flag offensive delete link more


Thank you, I had not done chmod +x the file, beginner mistake.

jesusy gravatar image jesusy  ( 2020-04-10 00:44:15 -0500 )edit

Question Tools

1 follower


Asked: 2020-04-09 22:33:15 -0500

Seen: 485 times

Last updated: Apr 09 '20