I want to explicitly specify the output size of the image when applying cv2.pyrDown() on images.
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
But it is throwing an error something similar to this.
OpenCV Error: Assertion failed (ssize.width > 0 && ssize.height > 0 && std::abs(dsize.width*2 - ssize.width) <= 2 && std::abs(dsize.height*2 - ssize.height) <= 2) in pyrDown_, file /io/opencv/modules/imgproc/src/pyramids.cpp, line 873
Any idea how to specify the output size of the image as a method argument.
From OpenCV 2.4 Tutorial:
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.
This was taken from the C++ tutorial but it should apply just the same for Python.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With