NorthStarUAS / ImageAnalysis

Aerial imagery analysis, processing, and presentation scripts.
MIT License
156 stars 44 forks source link

Panorama from video #9

Open akshayacharya97 opened 3 years ago

akshayacharya97 commented 3 years ago

Hi, I see that your project has similarity with what i want to achieve. I have a video obtained by placing a camera on a robot and recoding a particlar row of plants. I want to break this video into frames and then stitch this to create a long panorama of the row. How do I go about it using your code? Do you ave any other method you would suggest?

clolsonus commented 3 years ago

This project strongly depends on being able to geotag images or video frames before processing them. This way items found in the final stitch can be geolocated accurately. If you capture camera location and orientation along with the video, it's possible to add geotag info to the video frames as you extract them from the video. (Then stitch those frames together.) One trick to doing this with dji videos is to enable captions when recording and the location of the drone is recorded in the caption files and can be used later when extracting video frames. I do this when flying very low altitude survey missions by hand (sometimes flying under tree branches and following tricky terrain contours.)

akshayacharya97 commented 3 years ago

This project strongly depends on being able to geotag images or video frames before processing them. This way items found in the final stitch can be geolocated accurately. If you capture camera location and orientation along with the video, it's possible to add geotag info to the video frames as you extract them from the video. (Then stitch those frames together.) One trick to doing this with dji videos is to enable captions when recording and the location of the drone is recorded in the caption files and can be used later when extracting video frames. I do this when flying very low altitude survey missions by hand (sometimes flying under tree branches and following tricky terrain contours.)

Hi, I am doing a ground mission. Its just a regular horizontal video. I want to break the adjacent frames such that there is an overlap. And then i want to stitch these to get one long image. I will show you the kind of output I am getting right now. Also, I will attach the source code for reference. finalpanoex1

I want something like this miyoshitotal

` 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

print("Now stitching the final") (status, stitches) = stitcher.stitch(final) print(status)

save it if succesfully stitched

if status == 0:

write the output stitched image to disk"""

cv2.imwrite(output_path, temp[0])`