我正在播放一段视频,其中我试图检测一些东西,每当我检测到我感兴趣的区域时,我想显示它几秒钟。
import cv2
capture = cv2.VideoCapture(path)
while True:
ret,frame = capture.read(0)
region_of_interest = detect(frame)
if region_of_interest != 0:
cv2.imshow('Image',region_of_interest)
cv2.waitKey(2000)
cv2.destroyWindow('Image')
cv2.imshow('Normal Video',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
capture.release()
cv2.destroyAllWindows()
问题是当它发现什么东西时,它会弹出很多窗口,然后它就崩溃了。
你正在为每一个循环创建和销毁窗口,试试这样做
import cv2
capture = cv2.VideoCapture(path)
while True:
ret,frame = capture.read(0)
region_of_interest = detect(frame)
if region_of_interest != 0:
# if you want to show somenthing better put a text
cv2.putText(frame, data, (cord1, cord2), cv2.FONT_HERSHEY_SIMPLEX,0.5, (0, 255, 0), 2)
cv2.imshow('Normal Video',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
capture.release()
cv2.destroyAllWindows()