Wrong perspective transform | OpenCV perspectiveTransform
Imtryingtodoperspectivetransformofanimagetorealigntheperspective.Thisistheinputimage.Iwanttotransformtheinputintoarectangle.Theold_ptsinthecoderefertothepointspointsofthequadrangle.new_ptsrefertotheboundingrectanglearoundold_pts.Icalculatedperspectivetransformfromthesepointsusing:M=cv2.getPerspectiveTransform(old_pts,new_pts)Itransformedtheoriginalimageusing:transformed_img=cv2.warpPerspective(new_img,M,(new_img.shape[1],new_img.shape[0]))ButImgettinganoutputthatisnotasexpected.Thisistheoutp...
Im trying to do perspective transform of an image to realign the perspective. This is the input image. I want to transform the input into a rectangle.
The old_pts in the code refer to the points points of the quadrangle. new_pts refer to the bounding rectangle around old_pts.
I calculated perspective transform from these points using:
M = cv2.getPerspectiveTransform(old_pts, new_pts)
I transformed the original image using:
transformed_img = cv2.warpPerspective(new_img, M, (new_img.shape[1], new_img.shape[0]))
But Im getting an output that is not as expected. This is the output image. I dont know what is it Im doing wrong. Any ideas ?
# new_img = cv2.imread(IMG_20180731_123517_HDR.jpg) # new_img = cv2.resize(new_img, (int(new_img.shape[2] / 10), int(new_img.shape[0] / 10))) old_pts = np.float32([[14, 163], [11, 301], [242, 294], [226, 166]] ...