max*_*246 1 python dimension computer-vision
我设法用 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
Run Code Online (Sandbox Code Playgroud)
我曾尝试使用该方法,set但它不起作用。
您可以使用 opencv 调整大小:
img = cv2.resize(img, (640, 640))
Run Code Online (Sandbox Code Playgroud)
将分辨率设置为 640x640,或
img = cv2.resize(img, (0,0), fx = 0.5, fy = 0.5)
Run Code Online (Sandbox Code Playgroud)
到图像每个维度的一半。
如果你想要更差的质量,你可以使用模糊(我会推荐高斯):
img = cv2.GaussianBlur(img, (15,15), 0)
Run Code Online (Sandbox Code Playgroud)
如果您想要或多或少模糊,请更改 (15,15)(这是内核大小)。
如果您想了解有关图像处理的更多信息,我发现这些非常有用: