Hello,
this standard .py example exit with error, this is log dump:
python3 JetsonCamera.py
nvarguscamerasrc wbmode=5 ! video/x-raw(memory:NVMM), width=(int)1280, height=(int)720, format=(string)NV12, framerate=(fraction)30/1 ! nvvidconv flip-method=0 ! video/x-raw, width=(int)1280, height=(int)720, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink
nvbuf_utils: Could not get EGL display connection
GST_ARGUS: Creating output stream
CONSUMER: Waiting until producer is connected...
GST_ARGUS: Available Sensor modes :
GST_ARGUS: 3264 x 2464 FR = 21.000000 fps Duration = 47619048 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;
GST_ARGUS: 3264 x 1848 FR = 28.000001 fps Duration = 35714284 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;
GST_ARGUS: 1920 x 1080 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;
GST_ARGUS: 1280 x 720 FR = 59.999999 fps Duration = 16666667 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;
GST_ARGUS: 1280 x 720 FR = 120.000005 fps Duration = 8333333 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;
GST_ARGUS: Running with following settings:
Camera index = 0
Camera mode = 4
Output Stream W = 1280 H = 720
seconds to Run = 0
Frame Rate = 120.000005
GST_ARGUS: Setup Complete, Starting captures for 0 seconds
GST_ARGUS: Starting repeat capture requests.
CONSUMER: Producer has connected; continuing.
[ WARN:0] global /home/netmachine/opencv/modules/videoio/src/cap_gstreamer.cpp (935) open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1
GST_ARGUS: Cleaning up
CONSUMER: Done Success
GST_ARGUS: Done Success
(python3:9258): GStreamer-CRITICAL **: 12:41:26.731: gst_mini_object_unref: assertion 'GST_MINI_OBJECT_REFCOUNT_VALUE (mini_object) > 0' failed
QObject::~QObject: Timers cannot be stopped from another thread
this is the code
# MIT License
# Copyright (c) 2019 JetsonHacks
# See license
# Using a CSI camera (such as the Raspberry Pi Version 2) connected to a
# NVIDIA Jetson Nano Developer Kit using OpenCV
# Drivers for the camera and OpenCV are included in the base image
import cv2
import time
try:
from Queue import Queue
except ModuleNotFoundError:
from queue import Queue
import threading
import signal
import sys
def gstreamer_pipeline(
capture_width=1280,
capture_height=720,
display_width=1280,
display_height=720,
framerate=30,
flip_method=2,
):
return (
"nvarguscamerasrc wbmode=5 ! "
"video/x-raw(memory:NVMM), "
"width=(int)%d, height=(int)%d, "
"format=(string)NV12, framerate=(fraction)%d/1 ! "
"nvvidconv flip-method=%d ! "
"video/x-raw, width=(int)%d, height=(int)%d, format=(string)BGRx ! "
"videoconvert ! "
"video/x-raw, format=(string)BGR ! appsink"
% (
capture_width,
capture_height,
framerate,
flip_method,
display_width,
display_height,
)
)
class FrameReader(threading.Thread):
queues = []
_running = True
camera = None
def __init__(self, camera, name):
threading.Thread.__init__(self)
self.name = name
self.camera = camera
def run(self):
while self._running:
_, frame = self.camera.read()
while self.queues:
queue = self.queues.pop()
queue.put(frame)
def addQueue(self, queue):
self.queues.append(queue)
def getFrame(self, timeout = None):
queue = Queue(1)
self.addQueue(queue)
return queue.get(timeout = timeout)
def stop(self):
self._running = False
class Previewer(threading.Thread):
window_name = "Arducam"
_running = True
camera = None
def __init__(self, camera, name):
threading.Thread.__init__(self)
self.name = name
self.camera = camera
def run(self):
self._running = True
while self._running:
cv2.imshow(self.window_name, self.camera.getFrame(2000))
keyCode = cv2.waitKey(16) & 0xFF
cv2.destroyWindow(self.window_name)
def start_preview(self):
self.start()
def stop_preview(self):
self._running = False
class Camera(object):
frame_reader = None
cap = None
previewer = None
def __init__(self):
self.open_camera()
def open_camera(self):
conf = gstreamer_pipeline(flip_method=0)
print(conf)
self.cap = cv2.VideoCapture(conf, cv2.CAP_GSTREAMER)
if not self.cap.isOpened():
raise RuntimeError("Failed to open camera!")
if self.frame_reader == None:
self.frame_reader = FrameReader(self.cap, "")
self.frame_reader.daemon = True
self.frame_reader.start()
self.previewer = Previewer(self.frame_reader, "")
def getFrame(self):
return self.frame_reader.getFrame()
def start_preview(self):
self.previewer.daemon = True
self.previewer.start_preview()
def stop_preview(self):
self.previewer.stop_preview()
self.previewer.join()
def close(self):
self.frame_reader.stop()
self.cap.release()
if __name__ == "__main__":
camera = Camera()
camera.start_preview()
time.sleep(10)
camera.stop_preview()
camera.close()