Running non-ros python programs with rosrun
I apologize if this isn't the right place for my question. I followed this guide https://www.pyimagesearch.com/2018/02/26/face-detection-with-opencv-and-deep-learning/ for face detection, and can run it using
python detect_faces_video.py --prototxt deploy.prototxt.txt \
--model res10_300x300_ssd_iter_140000.caffemodel
My goal now is to be able to run the detect_faces_video.py
program using rosrun (I've included it at the end of this post). I will list the steps I have taken so far.
I began by creating a workspace named opencv_ros and a src, and in opencv_ros/src running catkin_create_pkg facescan rospy.
These are the files from the original folder I downloaded, and I copied these into opencv_ros/src/facescan/src
, followed by running catkin_make at the base of the workspace:
sriram@sriram-ThinkPad-E580:~$ cd deep-learning-face-detection/
sriram@sriram-ThinkPad-E580:~/deep-learning-face-detection$ ls
deploy.prototxt.txt iron_chic.jpg
detect_faces.py res10_300x300_ssd_iter_140000.caffemodel
detect_faces_video.py rooster.jpg
In opencv_ros/src/facescan/src
, I ran chmod +x for all the files in the folder, then added #!/usr/bin/env python
to the top of the python program.
I then ran another catkin_make
, along with source ~/opencv_ros/devel/setup.bash
.
This shows my attempt to run the program using rosrun:
sriram@sriram-ThinkPad-E580:~/opencv_ros/src/facescan/src$ workon cv
(cv) sriram@sriram-ThinkPad-E580:~/opencv_ros/src/facescan/src$ rosrun facescan detect_faces_video.py --prototxt deploy.prototxt.txt --model res10_300x300_ssd_iter_140000.caffemodel
from: can't read /var/mail/imutils.video
import-im6.q16: not authorized `np' @ error/constitute.c/WriteImage/1037.
import-im6.q16: not authorized `argparse' @ error/constitute.c/WriteImage/1037.
import-im6.q16: not authorized `imutils' @ error/constitute.c/WriteImage/1037.
import-im6.q16: not authorized `time' @ error/constitute.c/WriteImage/1037.
import-im6.q16: not authorized `cv2' @ error/constitute.c/WriteImage/1037.
/home/sriram/opencv_ros/src/facescan/src/detect_faces_video.py: line 13: syntax error near unexpected token `('
/home/sriram/opencv_ros/src/facescan/src/detect_faces_video.py: line 13: `ap = argparse.ArgumentParser()'
The imports are not authorized, and I feel like I need to change the rights to read | write for these imports, but I am not certain. I could also be completely wrong and need to be using cv_bridge for this. I am using Ubuntu 18.04 with ROS Melodic and opencv 3.4. Any help would be greatly appreciated; I tried learning about rosrun from textbooks, but was not able to find the appropriate solution.
Main script code:
#!/usr/bin/env python
# USAGE
# python detect_faces_video.py --prototxt deploy.prototxt.txt --model res10_300x300_ssd_iter_140000.caffemodel
# import the necessary packages
from imutils.video import VideoStream
import numpy as np
import argparse
import imutils
import time
import cv2
# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-p", "--prototxt", required=True,
help="path to Caffe 'deploy' prototxt file")
ap.add_argument("-m", "--model", required=True,
help="path to Caffe pre-trained model")
ap.add_argument("-c", "--confidence", type=float, default=0.5,
help="minimum probability to filter weak detections")
args = vars(ap.parse_args())
# load our serialized model from disk
print("[INFO] loading model...")
net = cv2.dnn.readNetFromCaffe(args["prototxt"], args["model"])
# initialize the video ...