【发布时间】:2014-07-09 22:16:44
【问题描述】:
我有以下代码来获取图像的纵横比
img0 = color.rgb2gray(io.imread("C:\\work\\TRAIN\\SET1\\bus.jpg"))
img0 = resize(img0, (40, 116))
ar = 1.0 * (img0.shape[1]/img0.shape[0])
print "aspect ratio: "
print ar
输出为2.0。但事实并非如此。
对于宽度为 116、高度为 40 的图像,纵横比应为 116/40 = 2.9。
我的计算哪里出错了?
【问题讨论】:
-
116/40将在 Python 2.7 上执行 floor division(向下舍入到下一个整数)。使用float(img0.shape[1]) / img0.shape[0]之类的东西来获得浮点除法。 -
成功了!如果您将其添加为答案,我会选择它。
标签: python image-processing floating-accuracy aspect-ratio