2-4Separation.py

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