python图片压缩不失真,调整图像大小而不失真OpenCV

在尝试使用OpenCV将图像调整为28x28尺寸时,原始图像发生严重失真。解决方法是使用保留原图纵横比的resize函数进行图像缩放,避免失真。提供了一个名为image_resize的函数示例,可以调整图像大小同时保持其原有的清晰度。
摘要由CSDN通过智能技术生成

I am using python 3 and latest version of openCV. I am trying to resize an image using the resize function provided but after resizing the image is very distorted. Code :

import cv2

file = "/home/tanmay/Desktop/test_image.png"

img = cv2.imread(file , 0)

print(img.shape)

cv2.imshow('img' , img)

k = cv2.waitKey(0)

if k == 27:

cv2.destroyWindow('img')

resize_img = cv2.resize(img , (28 , 28))

cv2.imshow('img' , resize_img)

x = cv2.waitKey(0)

if x == 27:

cv2.destroyWindow('img')

The original image is 480 x 640 (RGB therefore i passed the 0 to get it to grayscale)

Is there any way i could resize it and avoid the distortion using OpenCV or any other library perhaps? I intend to make a handwritten digit rec

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值