Created
November 8, 2017 21:01
-
-
Save cipher982/13adbc72199256255a5964578d85e607 to your computer and use it in GitHub Desktop.
opencv warp transform
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def toWarp(img,src,dst): | |
| # Grab the image shape | |
| if len(np.shape(img)) > 2: | |
| img_size = (toGray(img).shape[1], toGray(img).shape[0]) | |
| else: | |
| img_size = (img.shape[1], img.shape[0]) | |
| #im2 = img.reshape(img.shape[0], img.shape[1]) | |
| plt.suptitle('Before Warped', fontsize=14, fontweight='bold') | |
| plt.imshow(img) | |
| plt.show() | |
| #print(np.shape(gray)) | |
| # Given src and dst points, calculate the perspective transform matrix | |
| M = cv2.getPerspectiveTransform(src, dst) | |
| # Warp the image using OpenCV warpPerspective() | |
| warped = cv2.warpPerspective(img, M, img_size) | |
| plt.suptitle('After Warped', fontsize=14, fontweight='bold') | |
| plt.imshow(warped) | |
| plt.show() | |
| return warped, M |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment