9-1Blend.py

000: import cv2
001:
002: def __main():
003: img1 = cv2.imread(‘IMG_0260.JPG’)
004: img2 = cv2.imread(‘IMG_0181.JPG’)
005:
006: img1 = getResize(img1)
007: org = img1.copy()
008: img2 = getResize(img2)
009:
010: # ここで処理を実行
011: imgMask = getMaskImg(img1, img2)
012:
013: cv2.imshow(‘Original1’, img1)
014: cv2.imshow(‘Original2’, img2)
015: cv2.imshow(‘Final result’, imgMask)
016: cv2.waitKey(0)
017: cv2.destroyAllWindows()
018: # 合成実行
019: def getMaskImg(img1, img2):
020: compImg = cv2.addWeighted(src1=img1, alpha=1, src2=img2, beta=0.3, gamma=0)
021:
022: return compImg
023:
024: def getResize(src):
025: basePixSize = 1000 # 縦横で大きい辺の変更したいサイズ
026: height = src.shape[0]
027: width = src.shape[1]
028:
029: largeSize = max(height, width) # 大きい方の辺のサイズ
030: resizeRate = basePixSize / largeSize # 変更比率を計算
031: # shotSize = min(height, width) * resizeRate
032: dst = cv2.resize(src, (int(width * resizeRate), int(height * resizeRate)))
033:
034: return dst
035:
036: if __name__ == ‘__main__’:
037: print(cv2.__version__)
038:
039: __main()