6-2Laplacian.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: img = cv2.cvtColor(src=img, code=cv2.COLOR_BGR2GRAY)
008: # ここで処理を実行する
009: “””CPUを使用”””
010: dst = cv2.Laplacian(src=img, ddepth=cv2.CV_32F, ksize=3) # ksize=1 3 5 7
011: dst = cv2.convertScaleAbs(src=dst) # 8ビット符号なし整数に変換
012:
013: cv2.imshow(‘Original’, org)
014: cv2.imshow(‘Final result’, dst)
015: cv2.waitKey(0)
016:
017: cv2.destroyAllWindows()
018:
019: def getResize(src):
020: basePixSize = 1280 # 縦横で大きい辺の変更したいサイズ
021: height = src.shape[0]
022: width = src.shape[1]
023:
024: largeSize = max(height, width) # 大きい方の辺のサイズ
025: resizeRate = basePixSize / largeSize # 変更比率を計算
026:
027: dst = cv2.resize(src, (int(width * resizeRate), int(height * resizeRate)), interpolation=None)
028:
029: return dst
030:
031: if __name__ == ‘__main__’:
032: print(cv2.__version__)
033:
034: __main()