-
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.
Improved code quality based on PEP-8
- Loading branch information
1 parent
a269851
commit 1dfc172
Showing
10 changed files
with
398 additions
and
232 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 |
---|---|---|
@@ -1,4 +1,168 @@ | ||
imutils/.DS_Store | ||
# Created by https://www.gitignore.io | ||
|
||
### Python ### | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
env/ | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*,cover | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
|
||
### PyCharm ### | ||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm | ||
|
||
*.iml | ||
|
||
## Directory-based project format: | ||
.idea/ | ||
# if you remove the above rule, at least ignore the following: | ||
|
||
# User-specific stuff: | ||
# .idea/workspace.xml | ||
# .idea/tasks.xml | ||
# .idea/dictionaries | ||
|
||
# Sensitive or high-churn files: | ||
# .idea/dataSources.ids | ||
# .idea/dataSources.xml | ||
# .idea/sqlDataSources.xml | ||
# .idea/dynamic.xml | ||
# .idea/uiDesigner.xml | ||
|
||
# Gradle: | ||
# .idea/gradle.xml | ||
# .idea/libraries | ||
|
||
# Mongo Explorer plugin: | ||
# .idea/mongoSettings.xml | ||
|
||
## File-based project format: | ||
*.ipr | ||
*.iws | ||
|
||
## Plugin-specific files: | ||
|
||
# IntelliJ | ||
/out/ | ||
|
||
# mpeltonen/sbt-idea plugin | ||
.idea_modules/ | ||
|
||
# JIRA plugin | ||
atlassian-ide-plugin.xml | ||
|
||
# Crashlytics plugin (for Android Studio and IntelliJ) | ||
com_crashlytics_export_strings.xml | ||
crashlytics.properties | ||
crashlytics-build.properties | ||
|
||
|
||
### OSX ### | ||
.DS_Store | ||
MANIFEST | ||
dist | ||
.AppleDouble | ||
.LSOverride | ||
|
||
# Icon must end with two \r | ||
Icon | ||
|
||
|
||
# Thumbnails | ||
._* | ||
|
||
# Files that might appear in the root of a volume | ||
.DocumentRevisions-V100 | ||
.fseventsd | ||
.Spotlight-V100 | ||
.TemporaryItems | ||
.Trashes | ||
.VolumeIcon.icns | ||
|
||
# Directories potentially created on remote AFP share | ||
.AppleDB | ||
.AppleDesktop | ||
Network Trash Folder | ||
Temporary Items | ||
.apdisk | ||
|
||
|
||
### Windows ### | ||
# Windows image file caches | ||
Thumbs.db | ||
ehthumbs.db | ||
|
||
# Folder config file | ||
Desktop.ini | ||
|
||
# Recycle Bin used on file shares | ||
$RECYCLE.BIN/ | ||
|
||
# Windows Installer files | ||
*.cab | ||
*.msi | ||
*.msm | ||
*.msp | ||
|
||
# Windows shortcuts | ||
*.lnk | ||
|
||
|
||
### Linux ### | ||
*~ | ||
|
||
# KDE directory preferences | ||
.directory | ||
|
||
# Linux trash folder which might appear on any partition or disk | ||
.Trash-* |
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
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 |
---|---|---|
@@ -1,43 +1,45 @@ | ||
# author: Adrian Rosebrock | ||
# website: http://www.pyimagesearch.com | ||
# author: Adrian Rosebrock | ||
# website: http://www.pyimagesearch.com | ||
|
||
# import the necessary packages | ||
import cv2 | ||
|
||
|
||
def sort_contours(cnts, method="left-to-right"): | ||
# initialize the reverse flag and sort index | ||
reverse = False | ||
i = 0 | ||
# initialize the reverse flag and sort index | ||
reverse = False | ||
i = 0 | ||
|
||
# handle if we need to sort in reverse | ||
if method == "right-to-left" or method == "bottom-to-top": | ||
reverse = True | ||
|
||
# handle if we need to sort in reverse | ||
if method == "right-to-left" or method == "bottom-to-top": | ||
reverse = True | ||
# handle if we are sorting against the y-coordinate rather than | ||
# the x-coordinate of the bounding box | ||
if method == "top-to-bottom" or method == "bottom-to-top": | ||
i = 1 | ||
|
||
# handle if we are sorting against the y-coordinate rather than | ||
# the x-coordinate of the bounding box | ||
if method == "top-to-bottom" or method == "bottom-to-top": | ||
i = 1 | ||
# construct the list of bounding boxes and sort them from top to | ||
# bottom | ||
boundingBoxes = [cv2.boundingRect(c) for c in cnts] | ||
(cnts, boundingBoxes) = zip(*sorted(zip(cnts, boundingBoxes), | ||
key=lambda b: b[1][i], reverse=reverse)) | ||
|
||
# construct the list of bounding boxes and sort them from top to | ||
# bottom | ||
boundingBoxes = [cv2.boundingRect(c) for c in cnts] | ||
(cnts, boundingBoxes) = zip(*sorted(zip(cnts, boundingBoxes), | ||
key=lambda b:b[1][i], reverse=reverse)) | ||
# return the list of sorted contours and bounding boxes | ||
return cnts, boundingBoxes | ||
|
||
# return the list of sorted contours and bounding boxes | ||
return (cnts, boundingBoxes) | ||
|
||
def label_contour(image, c, i, color=(0, 255, 0), thickness=2): | ||
# compute the center of the contour area and draw a circle | ||
# representing the center | ||
M = cv2.moments(c) | ||
cX = int(M["m10"] / M["m00"]) | ||
cY = int(M["m01"] / M["m00"]) | ||
# draw the contour and label number on the image | ||
cv2.drawContours(image, [c], -1, color, thickness) | ||
cv2.putText(image, "#{}".format(i + 1), (cX - 20, cY), cv2.FONT_HERSHEY_SIMPLEX, | ||
1.0, (255, 255, 255), 2) | ||
# return the image with the contour number drawn on it | ||
return image | ||
# compute the center of the contour area and draw a circle | ||
# representing the center | ||
M = cv2.moments(c) | ||
cX = int(M["m10"] / M["m00"]) | ||
cY = int(M["m01"] / M["m00"]) | ||
|
||
# draw the contour and label number on the image | ||
cv2.drawContours(image, [c], -1, color, thickness) | ||
cv2.putText(image, "#{}".format(i + 1), (cX - 20, cY), cv2.FONT_HERSHEY_SIMPLEX, | ||
1.0, (255, 255, 255), 2) | ||
|
||
# return the image with the contour number drawn on it | ||
return image |
Oops, something went wrong.