OpenCV显示图像时 实现键盘控制的开始,暂停与退出
import os
import cv2
images_path = r""
for file in os.listdir(images_path):
img = cv2.imread(os.path.join(images_path,file))
cv2.imshow("Images",img)
keyValue = cv2.waitKey(10) # 捕获键值
if keyValue & 0xFF == ord(' '): # 空格键实现暂停与开始
cv2.waitKey(0)
elif keyValue & 0xFF == ord('q'): # ‘q’键实现退出
exit(0)
# cv2.waitKey(10)
print(file_name)