6-1Canny.py

000: import cv2
001:
002: def __main():
003: img = cv2.imread(‘IMG_0260.JPG’)
004: img = getResize(img)
005: org = img.copy()
006:
007: “””CPUを使用”””
008: dst = cv2.Canny(image=img, threshold1=100, threshold2=200)
009:
010: cv2.imshow(‘Original’, org)
011: cv2.imshow(‘Final result’, dst)
012: cv2.waitKey(0)
013:
014: cv2.destroyAllWindows()
015:
016: def getResize(src):
017: basePixSize = 1280 # 縦横で大きい辺の変更したいサイズ
018: height = src.shape[0]
019: width = src.shape[1]
020:
021: largeSize = max(height, width) # 大きい方の辺のサイズ
022: resizeRate = basePixSize / largeSize # 変更比率を計算
023:
024: dst = cv2.resize(src, (int(width * resizeRate), int(height * resizeRate)), interpolation=None)
025:
026: return dst
027:
028: if __name__ == ‘__main__’:
029: print(cv2.__version__)
030:
031: __main()