I’m using OpenCV in Python3 within a Linux Docker container. I’m capturing video in OpenCV with VideoCapture() and GStreamer like so:
cv2.VideoCapture("nvarguscamerasrc ! video/x-raw(memory:NVMM), width=3840, height=2160, framerate=60/1 ! nvvidconv ! video/x-raw, format=(string)I420, width=3840, height=2160 ! appsink", cv2.CAP_GSTREAMER)
This works well except sometimes nvargus has issues and needs to be restarted. I do this from the host system using
systemctl restart nvargus-daemon. Before restarting nvargus, I release the VideoCapture instance. This results in VideoCapture never working again in the Python instance without restarting python.
After releasing VideoCapture and restarting nvrargus I get the following error in my docker container:
(Argus) Error EndOfFile: Unexpected error in reading socket (in src/rpc/socket/client/ClientSocketManager.cpp, function recvThreadCore(), line 266) (Argus) Error EndOfFile: Receiving thread terminated with error (in src/rpc/socket/client/ClientSocketManager.cpp, function recvThreadWrapper(), line 368)
Stopping NVIDIA Argus daemon... CAM: serial no file already exists, skips storing again nvargus-daemon.service: Succeeded. Stopped NVIDIA Argus daemon. Started NVIDIA Argus daemon.
Attempting to open the VideoCapture again with
results in this error:
(Argus) Error InvalidState: Receive thread is not running cannot send. (in src/rpc/socket/client/ClientSocketManager.cpp, function send(), line 96) (Argus) Error InvalidState: (propagating from src/rpc/socket/client/SocketClientDispatch.cpp, function dispatch(), line 87)
The only fix to get gst working with VideoCapture again is to restart Python.
How can I close the VideoCapture correctly so I can restart nvargus then open VideoCapture again to be used?
OpenCv Version: OpenCV 4.5.0
GStreamer Version: 1.14.5