【问题标题】:Python - CV2 change dimension and qualityPython - CV2 改变维度和质量
【发布时间】:2012-10-10 21:19:38
【问题描述】:

我设法用 Python 和 CV2 库拍了一张照片,但我想改变图像的尺寸,得到一些质量不高的东西,并将其缩小到 640。

我的代码是:

cam = VideoCapture(0)   # 0 -> index of camera
s, img = cam.read()
    if s:    # frame captured without any errors
             imwrite(filename,img) #save image

我尝试过使用set的方法,但它不起作用。

【问题讨论】:

    标签: python dimension computer-vision


    【解决方案1】:

    您可以使用 opencv 调整大小:

    img = cv2.resize(img, (640, 640))
    

    将分辨率设置为 640x640,或

    img = cv2.resize(img, (0,0), fx = 0.5, fy = 0.5)
    

    将图像的每个维度减半。

    如果你想要更差的质量,你可以使用模糊(我推荐 Gaussian):

    img = cv2.GaussianBlur(img, (15,15), 0)
    

    如果您想要或多或少模糊,请更改 (15,15)(即内核大小)。

    如果您想了解有关图像处理的更多信息,我发现这些非常有用:

    OpenCV tutorials,

    OpenCV image processing

    【讨论】:

      【解决方案2】:

      【讨论】:

        猜你喜欢
        • 2019-02-21
        • 2014-08-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-10-04
        • 1970-01-01
        • 1970-01-01
        • 2019-06-05
        相关资源
        最近更新 更多