import time
import cv2
def _gst_str_filter(self):
return ' v4l2src device=/dev/video1 \
! image/jpeg,width=1280,height=720,framerate=30/1 \
! jpegdec \
! videoconvert \
! videoscale \
! video/x-raw,width=300,height=200 \
! gdkpixbufoverlay location=filter.png offset-x=100 offset-y=100 overlay-width=100 overlay-height=100 \
! appsink'
cap = []
count = []
now = []
start_time = []
for i in range(1):
cap.insert(i,cv2.VideoCapture(_gst_str_filter(), cv2.CAP_GSTREAMER))
count.insert(i, 0)
start_time.insert(i, time.time())
now.insert(i, time.time())
while(True):
for i in range(len(cap)):
ret, frame = cap[i].read()
if ret == 1:
count[i] += 1
now[i] = time.time()
cv2.imshow('usb camera {}'.format(i),frame)
if now[i] - start_time[i] > 1.0:
print("camera {} fps: {}".format(i, count[i]))
count[i] = 0
start_time[i] = now[i]
if cv2.waitKey(1) & 0xFF == ord('q'):
break
for i in range(len(cap)):
cap[i].release()
cv2.destroyAllWindows()