Computer Vision/opencv(python)

[61] 7) 이미지 스티칭

jwjwvison 2021. 3. 25. 23:40
  • 이미지 스티칭(Image Stitching) 이란?
    • 동일 장면의 사진을 자연스럽게 붙여서 한 장의 사진으로 만드는 기술
    • 사진 이어 붙이기, 파노라마 영상

 

  • 이미지 스티칭 객체 생성
cv2.Stitcher_create(mode=None) -> retval

 • mode: 스티칭 모드 . cv2.PANORAMA 또는 cv2.SCANS 중 하나 선택. 기본값은 cv2.PANORMA

 • retval: cv2.Stitcher 클래스 객체

  • 이미지 스티칭 함수
cv2.Stitcher.stitch(images,pano=None) -> retval,pano

 • images: 입력 영상 리스트
 • retval: 성공하면 cv2.Stitcher_OK.
 • pano: 파노라마 영상

 

  • 이미지 스티칭 예제
import sys
import numpy as np
import cv2


img_names = ['img1.jpg', 'img2.jpg', 'img3.jpg']

imgs = []
for name in img_names:
    img = cv2.imread(name)

    if img is None:
        print('Image load failed!')
        sys.exit()

    imgs.append(img)

stitcher=cv2.Stitcher_create()
status,dst=stitcher.stitch(imgs)

if status != cv2.Stitcher_OK:
    print('Stitch failed!')
    sys.exit()

cv2.imwrite('output.jpg',dst)

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