cv2.waitkey(0)当随机键按时不等待-OpenCV 3.1.0,python3,ubuntu
cv2.waitKey(0) not waiting when random key pressed - OpenCV 3.1.0, Python3, Ubuntu
所以我有一个程序,其中将不同的按键分配给不同的功能。我正在使用CV2.Waitkey(0)一个一个框架。但是,当按下未分配函数的键时,下一个帧仍会加载。如何防止未分配的键盘将下一帧加载到我的循环中?
谢谢!
while (cap.isOpened()):
frameclick = cv2.waitKey(0)
ret, frame = cap.read()
cv2.imshow('frame',frame)
if frameclick == ord('a'):
swingTag()
elif frameclick == ord('r'):
rewindFrames()
elif frameclick == ord('s'):
stanceTag()
elif frameclick == ord('d'):
unsureTag()
elif frameclick == ord('q'):
with open((selectedvideostring + '.txt'), 'w') as textfile:
for item in framevalues:
textfile.write("{}n".format(item))
break
问题与您的逻辑有关。您的程序进入WARE循环并等待键。然后,如果按下键,则读取下一帧,但目前您的程序不在乎按下哪个键。因此,您将有下一个帧,然后才能检查按下哪个按钮,这是迟到的。
,如 @ervin的答案中所述,尝试:
while (cap.isOpened()):
ret, frame = cap.read()
# check if read frame was successful
if ret == False: break;
# show frame first
cv2.imshow('frame',frame)
# then waitKey -- and make it <= 255
frameclick = cv2.waitKey(0) & 0xFF
if frameclick == ord('a'):
swingTag()
elif frameclick == ord('r'):
rewindFrames()
elif frameclick == ord('s'):
stanceTag()
elif frameclick == ord('d'):
unsureTag()
elif frameclick == ord('q'):
with open((selectedvideostring + '.txt'), 'w') as textfile:
for item in framevalues:
textfile.write("{}n".format(item))
break
相关文章:
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- 在编译C++代码(具有dlib和opencv)到WASM时面临问题
- 为什么我的C#代码在调用回C++COM直到Task时会暂停.等待/线程.加入
- 如何使用OpenCV将RBG图像转换为HSV,并将H、S和V值保存为C++中的3个独立图像
- OpenCV EqualizeHist()从彩色图像创建黑白图像
- 将OpenCV C++重写为EmguCV C#-如何使用指针
- OpenCV C++.快速计算混淆矩阵
- 如何让LLDB在成功时退出,在失败时等待
- 在C++代码中包含opencv时,使用ctypes创建.so文件
- 哪些库可以通过Opencv调整曝光率
- 安装opencv失败-粘贴CMakeError.log的内容
- C++中的openCV Mat访问冲突
- OpenCV Android C++ imwrite not found
- 未定义的引用 .. 使用 OpenCV 编译 C++ 代码时,从命令行
- 将 OpenCV 与 CMAKE 中的项目一起构建为第三方库的正确方法
- CV_OCL_RUN宏如何在OpenCV(版本3.4.5)的goodFeaturesToTrack实现中工作?
- cv2.waitkey(0)当随机键按时不等待-OpenCV 3.1.0,python3,ubuntu
- opencv :无法通过等待键读取大写字母
- 如何使linux系统等待OpenCV程序