forked from spmallick/learnopencv
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixing homography_book.py for opencv 2.4.x
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env python | ||
|
||
import cv2 | ||
import numpy as np | ||
|
||
if __name__ == '__main__' : | ||
|
||
# Read source image. | ||
im_src = cv2.imread('book2.jpg') | ||
# Four corners of the book in source image | ||
pts_src = np.array([[141, 131], [480, 159], [493, 630],[64, 601]], dtype=float) | ||
|
||
|
||
# Read destination image. | ||
im_dst = cv2.imread('book1.jpg') | ||
# Four corners of the book in destination image. | ||
pts_dst = np.array([[318, 256],[534, 372],[316, 670],[73, 473]], dtype=float) | ||
|
||
# Calculate Homography | ||
h, status = cv2.findHomography(pts_src, pts_dst) | ||
|
||
# Warp source image to destination based on homography | ||
im_out = cv2.warpPerspective(im_src, h, (im_dst.shape[1],im_dst.shape[0])) | ||
|
||
# Display images | ||
cv2.imshow("Source Image", im_src) | ||
cv2.imshow("Destination Image", im_dst) | ||
cv2.imshow("Warped Source Image", im_out) | ||
|
||
cv2.waitKey(0) |