Как сшить несколько изображений с помощью OpenCV?Python

Программы на Python
Anonymous
Как сшить несколько изображений с помощью OpenCV?

Сообщение Anonymous »

Я хочу создать панораму из нескольких изображений. По сути, камера будет линейно перемещаться в плоскости и непрерывно делать около 20-30 изображений. Мне нужно создать панораму из этих изображений. Я пробовал использовать функцию сшивания, а также традиционный способ поиска элементов и их сопоставления, а затем деформации. Но я не уверен, правильно ли я это делаю. Как мне действовать?

Код: Выделить всё

import imutils
import cv2
import glob

input_path = "/Users/akshayacharya/Desktop/Panorama/Raw
Data/riverside/*.jpg"

# input and sort the images
list_images = glob.glob(input_path)
list_sorted = sorted(list_images)
print(list_sorted)

# output path definition
output_path = "/Users/akshayacharya/Desktop/Panorama/Final
Panorama/finalpanoex1.jpg"

# initialize empty list and fill all images
images = []
for image in list_sorted:
image1 = cv2.imread(image)
image1 = cv2.resize(image1, (720, 480))
images.append(image1)

print("Read the images")
# this is the final list to stitch
final = [images[0]]
flag = True
print(len(images))
temp = [images[0]]
print(type(temp))

stitcher = cv2.createStitcher() if imutils.is_cv3() else
cv2.Stitcher_create()

i = 0
while(i < len(images)-1):
(status, stitched) = stitcher.stitch([temp[0], images[i+1]])
if status == 0:
final.append(images[i+1])
print(f"Succesfully stitch {i} to {i+1}")
i = i+1

temp[0] = stitched

continue
if status != 0:
print(f"Succesfully could not stitch {i} to {i + 1}")
for j in range(i+2, len(images)):
print(f"now trying {i} to {j}")
(status, stitchedd) = stitcher.stitch([temp[0], images[j]])
if status == 0:
print(f"Succesfully managed to stitch {i} to {j}")
final.append(images[j])
i=j
temp[0] = stitchedd
break
if status != 0:
print(f"Oops could not stitch {i} to {j}")
print(f"Will now see compatibility between {i} and {j+1}")

continue

i += 1
continue

cv2.imwrite(output_path, temp[0])
Выходное изображение:
Изображение
< /п>

Подробнее здесь: https://stackoverflow.com/questions/655 ... ing-opencv

Вернуться в «Python»