I have a Django + Python application. I have a python script that takes requirements as command line options.
The issue for me is that when I try to put in the command line arguments the script fails to execute. When I take out the command line arguments, it runs fine. I need those command line arguments.
I am using node JS with Python Shell to execute the python script when the button is clicked in the django HTML front page.
Here is my code:
let {PythonShell} = require('python-shell')
var path = require("path")
function track_object() {
//document.getElementById("detect").value = "One moment please ..."
var python = require("python-shell")
var path = require("path")
//let {PythonShell} = require('python-shell')
var options = {
scriptPath : path.join(__dirname, '/../engine/opencv-object-tracking/'),
pythonPath : '/usr/bin/python'
}
**//let pyshell = new PythonShell("opencv_object_tracking.py --video dashcam_boston.mp4 --tracker csrt", options);
let pyshell = new PythonShell("opencv_object_tracking.py", options);**
}
Note: the two lines in bold are show the calling of the script with and without arguments
Please let me know what is the correct way to pass command line arguments with Python Shell.
***** EDIT ****** here is my edit argparse:
# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-v", "--video", type=str,
help="path to input video file")
ap.add_argument("-t", "--tracker", type=str, default="csrt",
help="OpenCV object tracker type")
args = vars(ap.parse_args())
# extract the OpenCV version info
(major, minor) = cv2.__version__.split(".")[:2]
# if we are using OpenCV 3.2 OR BEFORE, we can use a special factory
# function to create our object tracker
if int(major) == 3 and int(minor) < 3:
tracker = cv2.Tracker_create(args["tracker"].upper())