Reputation: 153
I am kind of new to opencv and image processing. I was trying out this code which I found on pyimagesearch.com. I resized the image to a height of 500 pixels to perform edge detection and to find contours.
r = 500.0 / image.shape[1]
dim = (500,int(image.shape[0] * r))
image = cv2.resize(image,dim,interpolation = cv2.INTER_AREA)
ratio = image.shape[0] /500.0
Again, I multiply the processed image with the ratio( so that changes are made w.r.t the original image)
warped = four_point_transform(orig,screenCnt.reshape(4,2)*ratio)
r = 500.0 / warped.shape[1]
dim = (500,int(warped.shape[0] * r))
warped = cv2.resize(warped,dim,interpolation = cv2.INTER_AREA)
cv2.imshow("Perspective Transform",warped)
After this, what results I am getting is somewhat like this Image. Only some part of the image is visible and I am unable to see the rest of the image. Please help me. Thanks!
Upvotes: 4
Views: 4590
Reputation: 336
If you want a really easy way to upsize or downsize your image, use pyrUp and pyrDown.
http://docs.opencv.org/2.4/doc/tutorials/imgproc/pyramids/pyramids.html
imageSmall = cv2.pyrDown(image) # make image smaller
imageLarger = cv2.pyrUp(image) # make image larger
Upvotes: 0
Reputation: 2022
It seems to me that you are mixing width and height.
For a regular image image.shape[]
will give you height, width and channels, in that order.
So it should probably look like:
newHeight = 500.0
oldHeight = image.shape[0]
oldWidth = image.shape[1]
r = newHeight / oldHeight
newWidth = int(oldWidth * r)
dim = (newHeight, newWidth)
image = cv2.resize(image, dim, interpolation = cv2.INTER_AREA)
aspectRatio = image.shape[1] / image.shape[0]
Upvotes: 2