I'm trying to pass a frame read from a camera using opencv as an argument to another python script but I cannot get it to work.
Running the following script stores a camera frame on my network every 5 seconds:
#!/usr/bin/python
import cv2
import threading
import subprocess
import time
import datetime
def camera():
camera = cv2.VideoCapture("/dev/video0")
if not camera.isOpened():
print("Cannot open camera.")
raise SystemExit
camera.set(cv2.CAP_PROP_FRAME_WIDTH, 320)
camera.set(cv2.CAP_PROP_FRAME_HEIGHT, 320)
camera.set(cv2.CAP_PROP_FPS, 15)
return camera
try:
camera = camera()
while True:
frame = camera.read()[1]
#subprocess.call(["python", "/home/user/test2.py", frame])
server = "/net/192.168.4.51/mnt/LAN4Storage/EC/Camera/"
cv2.imwrite(server + "temp.jpg", frame)
timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
cv2.imwrite(server + timestamp + ".jpg", frame)
time.sleep(5)
except Exception as error:
print(error)
finally:
camera.release()
If I uncomment the subprocess.call line and comment the next 4 lines I expect the frame to be passed to my test2.py script:
`
#/usr/bin/env python
import cv2
import sys
import os
import time
import datetime
try:
frame = cv2.imread(sys.argv[1])
server = "/net/192.168.4.51/mnt/LAN4Storage/EC/Camera/"
cv2.imwrite(server + "temp.jpg", frame)
timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
cv2.imwrite(server + timestamp + ".jpg", frame)
except Exception as error:
print(error)
finally:
pass
` But on starting test1.py, I get the following error:
`expected str, bytes or os.PathLike object, not ndarray`