import cv2
from matplotlib import pyplot as plt
import queue
import threading
import time
class VideoCapture:
def __init__(self, name):
self.cap = cv2.VideoCapture(name)
self.q = queue.Queue()
t = threading.Thread(target=self._reader)
t.daemon = True
t.start()
# read frames as soon as they are available, keeping only most recent one
def _reader(self):
while True:
ret, frame = self.cap.read()
if not ret:
break
if not self.q.empty():
try:
self.q.get_nowait() # discard previous (unprocessed) frame
except queue.Empty:
pass
self.q.put(frame)
def read(self):
return self.q.get()
cap = cv2.VideoCapture('rtsp://admin:Admin1234@192.168.1.146:554/cam/realmonitor?channel=1&subtype=0')
while True:
start = time.time()
_,frame = cap.read()
w,h, _ = frame.shape
end = time.time()
tmp = end-start
print(1/tmp)
#print(w,h)
frame = cv2.resize(frame, (h//2, w//2), interpolation=cv2.INTER_AREA)
cv2.imshow('frME',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
放久沒有錯誤突然過幾天就卡在一個畫面然後就掛了,請問有什麼可能性??
問一下 GPT4 如何 https://sharegpt.com/c/gKDWfjP