본문 바로가기
OpenCV/OpenCV-Chapter

CH09 OpenCV-Python 스티칭 Stitching(PANORAMA)

by kiimy 2021. 12. 25.
728x90

이미지 스티칭(Image Stitching)이란?

• 동일 장면의 사진을 자연스럽게(seamless) 붙여서 한 장의 사진으로 만드는 기술

• 사진 이어 붙이기, 파노라마 영상(Panorama image)

- 기본적으로 SULF or ORB를 사용

 

양쪽에서 특징점을 잡고 공통이 되는 특징점들만 남김
매칭이 되는 결과의 정보를 이용하여 두 영상간 Perspective Trans 관계 추출 후 warping

But
단순히 이어붙이기만하면 밝기가 급격하게 바뀌는 부자연스러운 부분이 생긴다 
==> 밝기를 smooth하게 변화시키는 blending이 내부에서 적용됨
images = ['img1.jpg', 'img2.jpg', 'img3.jpg']

imgs= []
for name in images:
    img = cv2.imread(f'ch09\\images\\{name}')

    if img is None:
        print('Images load failed')
        sys.exit()
    imgs.append(img)

# class 객체 불러오기
stitcher = cv2.Stitcher_create()
'''
cv2.Stitcher_create(, mode=None) -> retval

mode: 스티칭 모드. cv2.PANORAMA 또는 cv2.SCANS 중 하나 선택
# mode = cv2.SCANS(영상의 밝기가 균일할때, Affine의 형태만 가능)
'''

ret, dst = stitcher.stitch(imgs)
'''
cv2.Stitcher.stitch(images, pano=None) -> retval, pano

retval: 성공하면 cv2.Stitcher_OK. 
pano: 파노라마 영상
'''
if ret != cv2.Stitcher_OK:
    print('Stitch failed')
    sys.exit()

# 스트칭 파일 저장
# cv2.imwrite('PANO', dst) == 확장자 설정해줘야해(.jpg)
cv2.imwrite('ch09\\images\\PANO.jpg', dst)

cv2.namedWindow('dst', cv2.WINDOW_NORMAL)
cv2.imshow('dst', dst)
cv2.waitKey()

PANORAMA

728x90

댓글