我编写了以下代码来过滤来自摄像机的视频馈送,以仅显示光线或反射中的亮点。当我运行它时,窗口打开,但是它没有响应,什么也没显示。
import cv2
import numpy as np
import keyboard
#Starts capturing video in a VideoCapture object called cap
cap = cv2.VideoCapture(0)
#While the q button is not pressed, the while loop runs
while not keyboard.is_pressed('q'):
#ret is a placeholder (not used)
ret, frame = cap.read()
#Sets the range of acepted colors in HSV
whiteRange = np.array([[0, 0, 200], [255, 40, 255]])
#Blurs the image to remove noise and smooth the details
gaussianBlur = cv2.GaussianBlur(frame, (5,5), 0)
#Converts from BGR to HSV to filter colors in the next step
hsvFrame = cv2.cvtColor(gaussianBlur, cv2.COLOR_BGR2HSV)
#Filters for white only and turns other colors black
whiteFilter = cv2.inRange(hsvFrame, whiteRange[0], whiteRange[1])
#Display the final image
cv2.imshow('Tape-Detection', whiteFilter)
#Ends the capture and destroys the windows
cap.release()
cv2.destroyAllWindows()
任何建议也都很好,我是OpenCV Python的新手。
答案 0 :(得分:0)
没有cv2.imshow()
,就不能使用cv2.waitKey()
。等待时的备用循环用于更新显示。