Created
March 6, 2018 19:21
-
-
Save tjthejuggler/bcc8848bf1eeab58cc2c3472d2fc7748 to your computer and use it in GitHub Desktop.
CV tutorial
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
| # CannyStill.py | |
| import cv3 | |
| import numpy as np | |
| import os | |
| ################################################################################################### | |
| def main(): | |
| imgOriginal = cv3.imread("image.jpg") # open image | |
| if imgOriginal is None: # if image was not read successfully | |
| print("error: image not read from file \n\n") # print error message to std out | |
| os.system("pause") # pause so user can see error message | |
| return # and exit function (which exits program) | |
| imgGrayscale = cv3.cvtColor(imgOriginal, cv3.COLOR_BGR2GRAY) # convert to grayscale | |
| imgBlurred = cv3.GaussianBlur(imgGrayscale, (5, 5), 0) # blur | |
| imgCanny = cv3.Canny(imgBlurred, 100, 200) # get Canny edges | |
| cv3.namedWindow("imgOriginal", cv3.WINDOW_AUTOSIZE) # create windows, use WINDOW_AUTOSIZE for a fixed window size | |
| cv3.namedWindow("imgCanny", cv3.WINDOW_AUTOSIZE) # or use WINDOW_NORMAL to allow window resizing | |
| cv3.imshow("imgOriginal", imgOriginal) # show windows | |
| cv3.imshow("imgCanny", imgCanny) | |
| cv3.waitKey() # hold windows open until user presses a key | |
| cv3.destroyAllWindows() # remove windows from memory | |
| return | |
| ################################################################################################### | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment