-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added functions to perform automatic Canny edge detection, convert a …
…URL to image, apply a 4-point perspective transform, and sort contours
- Loading branch information
Showing
6 changed files
with
152 additions
and
100 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
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
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 @@ | ||
# author: Adrian Rosebrock | ||
# website: http://www.pyimagesearch.com | ||
|
||
# USAGE | ||
# BE SURE TO INSTALL 'imutils' PRIOR TO EXECUTING THIS COMMAND | ||
# python perspective_transform.py | ||
|
||
# import the necessary packages | ||
from imutils import perspective | ||
import numpy as np | ||
import cv2 | ||
|
||
# load the notecard code image, clone it, and initialize the 4 points | ||
# that correspond to the 4 corners of the notecard | ||
notecard = cv2.imread("../demo_images/notecard.png") | ||
clone = notecard.copy() | ||
pts = np.array([(73, 239), (356, 117), (475, 265), (187, 443)]) | ||
|
||
# loop over the points and draw them on the cloned image | ||
for (x, y) in pts: | ||
cv2.circle(clone, (x, y), 5, (0, 255, 0), -1) | ||
|
||
# apply the four point tranform to obtain a "birds eye view" of | ||
# the notecard | ||
warped = perspective.four_point_transform(notecard, pts) | ||
|
||
# show the original and warped images | ||
cv2.imshow("Original", clone) | ||
cv2.imshow("Warped", warped) | ||
cv2.waitKey(0) |
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,45 @@ | ||
# author: Adrian Rosebrock | ||
# website: http://www.pyimagesearch.com | ||
|
||
# USAGE | ||
# BE SURE TO INSTALL 'imutils' PRIOR TO EXECUTING THIS COMMAND | ||
# python sorting_contours.py | ||
|
||
# import the necessary packages | ||
from imutils import contours | ||
import imutils | ||
import cv2 | ||
|
||
# load the shapes image clone it, convert it to grayscale, and | ||
# detect edges in the image | ||
image = cv2.imread("../demo_images/shapes.png") | ||
orig = image.copy() | ||
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) | ||
edged = imutils.auto_canny(gray) | ||
|
||
# find contours in the edge map | ||
(cnts, _) = cv2.findContours(edged.copy(), cv2.RETR_EXTERNAL, | ||
cv2.CHAIN_APPROX_SIMPLE) | ||
|
||
# loop over the (unsorted) contours and label them | ||
for (i, c) in enumerate(cnts): | ||
orig = contours.label_contour(orig, c, i, color=(240, 0, 159)) | ||
|
||
# show the original image | ||
cv2.imshow("Original", orig) | ||
|
||
# loop over the sorting methods | ||
for method in ("left-to-right", "right-to-left", "top-to-bottom", "bottom-to-top"): | ||
# sort the contours | ||
(cnts, boundingBoxes) = contours.sort_contours(cnts, method=method) | ||
clone = image.copy() | ||
|
||
# loop over the sorted contours and label them | ||
for (i, c) in enumerate(cnts): | ||
sortedImage = contours.label_contour(clone, c, i, color=(240, 0, 159)) | ||
|
||
# show the sorted contour image | ||
cv2.imshow(method, sortedImage) | ||
|
||
# wait for a keypress | ||
cv2.waitKey(0) |
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
Binary file not shown.