2-5NegaPosi.py

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