I am currently using Opencv with gstreamer to display a video feed from ethernet cameras through a managed switch with significant tearing issues which I believe are down to high CPU usage.
My python script is as follows:
import numpy as np
import cv2
pipe = "udpsrc multicast-iface=eth0 address=239.192.1.32 port=5004 ! application/x-rtp, media=(string)video, clockrate=(int)90000, encoding-name=(string)RAW, sampling=(string)YCbCr-4:2:2, depth=(string)8, width=(string)640, height=(string)480 ! rtpvrawdepay ! videoconvert ! appsink"
pipe0 = "udpsrc multicast-iface=eth0 address=239.192.1.150 port=5004 ! application/x-rtp, media=(string)video, clockrate=(int)90000, encoding-name=(string)RAW, sampling=(string)YCbCr-4:2:2, depth=(string)8, width=(string)1024, height=(string)768 ! queue ! rtpvrawdepay ! videoconvert ! appsink"
pipe1 = "udpsrc multicast-iface=eth0 address=239.192.7.150 port=5004 ! application/x-rtp, media=(string)video, clockrate=(int)90000, encoding-name=(string)RAW, sampling=(string)YCbCr-4:2:2, depth=(string)8, width=(string)1024, height=(string)768 ! queue ! rtpvrawdepay ! videoconvert ! appsink"
cap = cv2.VideoCapture(pipe1)
cap0 = cv2.VideoCapture(pipe0)
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
ret, frame0 = cap0.read()
# Display the resulting frame
cv2.imshow('frame',frame)
cv2.imshow('frame0',frame0)
if cv2.waitKey(10) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
While running this script the CPU usage on the first three cores is upwards of 95% with the other three being upwards of 60%. Limiting the script to manage one video feed reduces the tearing and load on the CPU though still has slight issues.
This is the result of displaying two cameras within opencv.
I have created a pcap file with two incoming udp streams that when played back has no issues implying the network is not an issue.
My TX2 is set to nvmodel 0 with all 6 cores running 2ghz.
performing this task on a laptop with an i5 processor performs significantly better.
Any suggestions on how to improve performance ?