【问题标题】:OpenCV imshow() function shows a single colored window instead of an imageOpenCV imshow() 函数显示单个彩色窗口而不是图像
【发布时间】:2022-11-28 00:49:14
【问题描述】:

我一直试图用 OpenCV 拍照,但 imshow() 返回的是一张彩色图像。 它不返回任何错误。

import cv2
from time import sleep

camera = cv2.VideoCapture(0)

ret, frame = camera.read()
sleep(1)
cv2.imshow("frame", frame)
cv2.waitKey(0)
cv2.imwrite("image.jpg", frame)
cv2.destroyAllWindows()

Here is the window created while running this code

我的摄像头完全可以与其他程序和 python 程序一起使用,但我无法完成这项工作。 我试过更改摄像头端口、重新运行 pycharm 甚至重新启动我的计算机和摄像头,但效果不佳。 当我尝试使用 imwrite() 保存图像时,它也不起作用。

image saved with imwrite()

帮助?

【问题讨论】:

    标签: python opencv cv2 imshow


    【解决方案1】:

    1.'''你必须在其中给出相对路径'''

    image = ('图片相对路径')

    cv2.imwrite(图像,帧)

    【讨论】:

    • 鉴于 OP 上传了使用 imwrite 编写的图像,这似乎完全没有抓住要点。
    猜你喜欢
    • 2021-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-17
    • 1970-01-01
    相关资源
    最近更新 更多