Skip to content

Instantly share code, notes, and snippets.

@cipher982
Created November 8, 2017 21:01
Show Gist options
  • Select an option

  • Save cipher982/13adbc72199256255a5964578d85e607 to your computer and use it in GitHub Desktop.

Select an option

Save cipher982/13adbc72199256255a5964578d85e607 to your computer and use it in GitHub Desktop.
opencv warp transform
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