Hello everyone,
Has anyone succeded to do object detection and good video recording at the same time on Jetson Nano?
What I would like to achieve is at least 30fps for recording.
The object detection could run slower (at 15Hz would be enought) - since the tracking target moves slow.
At the moment I’m using detection from :
Capturing the video with OpenCV and recording it.
The fraction of the code that I’m using is :
def gstreamer():
return ('v4l2src device=/dev/video0 ! '
'video/x-raw, format=YUY2, '
'width=640,height=480,framerate=30/1 ! '
'videoconvert ! video/x-raw, '
'format=BGR ! appsink drop=1 ')
def main():
net = jetson.inference.detectNet("ssd-mobilenet-v2", threshold=0.5)
cap = cv2.VideoCapture(gstreamer(), cv2.CAP_GSTREAMER)
w = cap.get(cv2.CAP_PROP_FRAME_WIDTH)
h = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
fps = cap.get(cv2.CAP_PROP_FPS)
print("w,h,fps ",w,h,fps)
gst_out = "appsrc ! video/x-raw, format=BGR ! queue ! videoconvert ! video/x-raw,format=BGRx ! nvvidconv ! nvv4l2h264enc ! h264parse ! matroskamux ! filesink location=test.mkv "
out = cv2.VideoWriter(gst_out, cv2.CAP_GSTREAMER, 0, float(fps), (int(w), int(h)))
if not out.isOpened():
print("Failed to open output")
exit()
if not cap.isOpened():
print("Cannot open camera")
exit()
time.sleep(2.0)
while True:
ret, frame = self.cap.read()
if not ret:
exit()
self.out.write(frame)
input_image = cv2.cvtColor(frame, cv2.COLOR_RGB2RGBA).astype(np.float32)
input_image = jetson.utils.cudaFromNumpy(input_image)
detections = self.net.Detect(input_image, frame.shape[1], frame.shape[0])
key = cv2.waitKey(1) & 0xFF
if key == ord("q"):
break
cap.release()
out.release()
cv2.destroyAllWindows()
What I have achieved so far was a recorded video, but the duration was approx. half of the time.
I also measured the time, which is needed for grabbing frame/ recording / object detection and are as follows:
(in seconds)
Grabbing took:
0.0004832744598388672
Recording took:
0.00046253204345703125
Detections took:
0.05196261405944824
So what I can see is that the object detection takes too long, so the cpu is unable to record video fast enough. Thats why some frames are skipped and the duration of the video is 1/2 of the real scene duration.
What could be a solution?
Do you suggest any other implementation?
Do you suggest the use of threads? How could I run object detection and recording video on separate processes?
p.s…I’m using the OV2710 camera, which for 30fps supports only 640x480 resolution :/
thank you for your help and time.