OpenStitching / stitching

A Python package for fast and robust Image Stitching
Apache License 2.0
2.11k stars 162 forks source link

Affine Stitching works on horizontal alignment but fails with the same images on vertical alignment #125

Open mcranium opened 1 year ago

mcranium commented 1 year ago

Dear developers,

thank you for this very useful tool! I will definitively use it a lot for my projects.

I just ran into an issue when trying to assemble an affine panorama that is not horizontal but vertical (i.e. the numebr of rows is bigger than the number of columns). This can be reproduced with the following images.

horizontal_left horizontal_mid horizontal_right

The horizontal panorama worksusing this command:

stitch --affine --detector sift *.png

vertical_lower vertical_mid vertical_upper

With the same images rotated 90 degrees I get the following error message after a long computation time:

stitching vertical_lower.png vertical_mid.png vertical_upper.png into result.jpg
Traceback (most recent call last):
  File "/home/mario/.local/bin/stitch", line 8, in <module>
    sys.exit(main())
  File "/home/mario/.local/lib/python3.8/site-packages/stitching/cli/stitch.py", line 278, in main
    panorama = stitcher.stitch(img_names)
  File "/home/mario/.local/lib/python3.8/site-packages/stitching/stitcher.py", line 117, in stitch
    self.blend_images(imgs, seam_masks, corners)
  File "/home/mario/.local/lib/python3.8/site-packages/stitching/stitcher.py", line 230, in blend_images
    for idx, (img, mask, corner) in enumerate(zip(imgs, masks, corners)):
  File "/home/mario/.local/lib/python3.8/site-packages/stitching/stitcher.py", line 202, in compensate_exposure_errors
    for idx, (corner, img) in enumerate(zip(corners, imgs)):
  File "/home/mario/.local/lib/python3.8/site-packages/stitching/cropper.py", line 66, in crop_images
    for idx, img in enumerate(imgs):
  File "/home/mario/.local/lib/python3.8/site-packages/stitching/warper.py", line 41, in warp_images
    yield self.warp_image(img, camera, aspect)
  File "/home/mario/.local/lib/python3.8/site-packages/stitching/warper.py", line 45, in warp_image
    _, warped_image = warper.warp(
cv2.error: OpenCV(4.7.0) /io/opencv/modules/imgproc/src/imgwarp.cpp:1724: error: (-215:Assertion failed) dst.cols < SHRT_MAX && dst.rows < SHRT_MAX && src.cols < SHRT_MAX && src.rows < SHRT_MAX in function 'remap'

I think it would be great if this inconvenience could be solved, maybe even in a way that would allow the program to rotate all images in steps of 90 degrees, if doing so without fails.

Best wishes, Mario

lukasalexanderweber commented 1 year ago

Could you follow the tutorial with affine settings to find out where the problem is with the vertical images? If it's already in the feature detection / matching or later during warping. In homography mode you can set wave_correct_kind to vert as input that images are vertical, but we don't do wave correction for affine images.

I suggest you rotate the images by yourself or dig deeper on why it fails and how it could be resolved (you would probably need to check in OpenCV itself rather than this wrapper)

lukasalexanderweber commented 1 year ago

Additionally I noticed that the order of the vertical images is wrong (or is it?). While order shouldn't be an issue it might also be worth investigating

mstenta commented 1 month ago

Maybe this is fixed now? See #244

@mcranium Can you test this again and see if #244 helped?