opencv循环图片 python
时间: 2023-08-17 14:10:04 浏览: 160
要在Python中使用OpenCV循环显示图片,可以使用循环和OpenCV的imshow函数。以下是一个示例代码:
```python
import cv2
import os
# 图片文件夹路径
frame_path = "C:/Users/Administrator/Desktop/New_Study/IMAGE/Pictures"
# 获取文件夹中的所有图片文件名
filenames = os.listdir(frame_path)
# 循环显示图片
for filename in filenames:
# 读取图片
img = cv2.imread(os.path.join(frame_path, filename))
# 显示图片
cv2.imshow('Image', img)
# 等待按键,按下ESC键退出循环
if cv2.waitKey(0) == 27:
break
# 关闭窗口
cv2.destroyAllWindows()
```
这段代码会循环读取文件夹中的每张图片,并使用OpenCV的imshow函数显示图片。按下ESC键即可退出循环。
#### 引用[.reference_title]
- *1* [Python和OpenCV创建超快的“for”像素循环](https://blog.csdn.net/qq_40985985/article/details/125603129)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* *3* [Python OpenCV-循环播放图片](https://blog.csdn.net/weixin_41620184/article/details/115960887)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文