我想使用OpenCV2.0和Python2.6来显示调整大小的图像。我使用并采用了this示例,但不幸的是,这段代码是为OpenCV2.1编写的,似乎不适用于2.0。下面是我的代码:
import os, glob
import cv
ulpath = "exampleshq/"
for infile in glob.glob( os.path.join(ulpath, "*.jpg") ):
im = cv.LoadImage(infile)
thumbnail = cv.CreateMat(im.rows/10, im.cols/10, cv.CV_8UC3)
cv.Resize(im, thumbnail)
cv.NamedWindow(infile)
cv.ShowImage(infile, thumbnail)
cv.WaitKey(0)
cv.DestroyWindow(name)
因为我不能使用
cv.LoadImageM
我用过
cv.LoadImage
相反,这在其他应用程序中是没有问题的。然而,cv.iplimage没有属性行、列或大小。谁能给我一个提示,如何解决这个问题?
发布于 2011-11-21 06:23:33
您可以使用GetSize函数来获取这些信息,cv.GetSize(im)将返回一个带有图像宽度和高度的元组。您还可以使用im.depth和img.nChan获取更多信息。
为了调整图像的大小,我会使用一个略有不同的过程,使用另一个图像而不是矩阵。最好尝试使用相同类型的数据:
size = cv.GetSize(im)
thumbnail = cv.CreateImage( ( size[0] / 10, size[1] / 10), im.depth, im.nChannels)
cv.Resize(im, thumbnail)
希望这能有所帮助;)
朱利安
发布于 2018-07-21 06:49:50
def rescale_by_height(image, target_height, method=cv2.INTER_LANCZOS4):
"""Rescale `image` to `target_height` (preserving aspect ratio)."""
w = int(round(target_height * image.shape[1] / image.shape[0]))
return cv2.resize(image, (w, target_height), interpolation=method)
def rescale_by_width(image, target_width, method=cv2.INTER_LANCZOS4):
"""Rescale `image` to `target_width` (preserving aspect ratio)."""
h = int(round(target_width * image.shape[0] / image.shape[1]))
return cv2.resize(image, (target_width, h), interpolation=method)
https://stackoverflow.com/questions/4195453
复制相似问题