如何在cv2.pyrDown()或pyrUp()方法中指定自定义输出大小

2024-09-30 10:31:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在对图像应用cv2.pyrDown()时显式指定图像的输出大小。在

def gaussian_pyramid(image, scale=1.5, minSize=(30, 30)):
    yield image
    while True:
        w = int(image.shape[1] / scale)
        h = int(image.shape[0] / scale)
        image = cv2.pyrDown(image, dstsize=(w, h))
        if image.shape[0] < minSize[1] or image.shape[1] < minSize[0]:
            break
        yield image

但它抛出了一个与此类似的错误。在

^{pr2}$

知道如何将图像的输出大小指定为方法参数吗。在


Tags: 图像imagepyramidtruedefgaussiancv2int
2条回答

来自OpenCV 2.4教程:

pyrDown( tmp, dst, Size( tmp.cols/2, tmp.rows/2 )

tmp: The current image, it is initialized with the src original image.

dst: The destination image (to be shown on screen, supposedly half the input image)

Size( tmp.cols/2, tmp.rows/2): The destination size. Since we are downsampling, pyrDown expects half the size the input image (in this case tmp).

Notice that it is important that the input image can be divided by a factor of two (in both dimensions). Otherwise, an error will be shown.

这是从C++教程中获取的,但对于Python来说应该是一样的。在

对不起,我忘了给你正确的答案。在

pyrdown,pyrup的系数是2。因此,要计算奇数大小,我们必须调整dstsize是+1像素。在

def gaussian_pyramid(image, scale=2, minSize=(60, 60)):
   yield image
   while True:
     w = int(image.shape[1] / scale)
     h = int(image.shape[0] / scale)
     image = cv2.pyrDown(image, dstsize=(w,h))
     if image.shape[0] < minSize[1] or image.shape[1] < minSize[0]:
        break
     yield image

相关问题 更多 >

    热门问题