ultramango / gear360pano

Simple script to create equirectangular panorama by stitching images from Samsung Gear 360
MIT License
225 stars 55 forks source link

Linux: Image join issue while stitching using command #27

Open juniorwebunitygames opened 7 years ago

juniorwebunitygames commented 7 years ago

When i am trying to stitch gear360 image using command from linux. Image not join properly. image

ultramango commented 7 years ago

Is the image coming from first or second generation of Gear360? For the second generation of Gear360 the template is still far from perfect.

And anyway - I would expect the template not to fit all photos properly.

evertvorster commented 7 years ago

I suspect that the Gear360 cameras are not 100% exactly same placed in all the cameras. I'm working on making a tutorial to calibrate the .pto for each camera

ultramango commented 7 years ago

Correct.

I was also thinking about a tutorial how to tune the .pto but you might actually beat me to it.

There's also a possibility to try make Hugin to automatically adjust the lens' parameters, but I expect the result to be poor.

neuhaus commented 7 years ago

Such a tutorial would be great. I sometimes take hundreds of pictures with a car rooftop mount so creating a pto for this purpose would be worthwhile.

ftoledo commented 7 years ago

very good!

evertvorster commented 7 years ago

Hugin video template generation.txt

Lens_Calibrations.zip

That is the beginnings of the guide on how to calibrate lenses to your Samsung Gear360.

-Evert-

utack commented 6 years ago

Can this optimizer step be included in the .cmd? I am not educated about hugin exactly works, but could you use the control points from the preset .pto, apply the transformation to get the approximate results, as it is done right now, and then run an additional hugin step that optimizes the initial estimate further, based on how well the content at the border matches? Or is there some fundamental flaw in my expectation of what hugin does/can do? Thanks

ultramango commented 6 years ago

Hi,

You can't use control points from pto file to get better alignment (1). If you try to do it you would end-up with the same or similar alignment. Think about it that Hugin doesn't know anything about the image(s) behind the control points - all it does it tries its best to transform (think: adjusting some numbers) _the_controlpoints from both images so that they fit well. So... having the same control points you will end up with same/similar transformation (1) ergo same problem with alignment.

Generic solution would be to detect control points on both halves of the photo - unfortunately for double circular fish-eye it doesn't work very well (it doesn't work) - so control points have to be placed manually.

The pto files are based (mostly) on my camera, I suppose it works well for most of them, but, as someone already mentioned somewhere, every camera will differ a bit and for you the difference.

Please use this video as a starting guide: https://www.youtube.com/watch?v=QKQGT8VUN8g using your photo and add more control points, then play with optimise.

After your post I will try harder to create a better guide to creation of control points and what effect each parameter has in the optimisation pane.

(1) to be 100% correct it is theoretically possible that you could end-up with a better fit, i.e. "better" optimum solution for this optimisation problem.

L.

ultramango commented 6 years ago

To extend a bit more the part about the control points, for things to work the way you think you'd have to know how those pieces have to match together to make the alignment better - for human it's easy to say, for machine - that's a pretty hard problem.

utack commented 6 years ago

oh yes, that makes a lot of sense what you explained, thank you! What I mostly saw as disturbing artifarct was, that horizontal lines do not match Do you think there is a way to transform all control points in one hemisphere slightly up or down based on a parameter, to account for that, without going through the entire process of re-calibrating for every camera?
It sounds complicated though, because you can't just add a single offset to all points

ultramango commented 6 years ago

There are a couple of parameters that can be adjusted and "straighten" the photo (not sure if it is always possible). But it is beyond this commend to explain it (various distortions, rotations, etc.). It looks like one lens needs more "distortion" + slight position adjustment.

What you can do - use the video tutorial, stop at the moment when two photos are added (as separate lenses) then select from File "Apply template" and select pto file apprioprate for your camera. Then select "Fast Preview panorama" (toolbar icon with "GL") and then select "Move/Drag" tab - you will be then able to move photos around by dragging them (left-click and hold).

L.

utack commented 6 years ago

Can I also open the pto in hugin an manually adjust the control points, based on images from my camera?

ultramango commented 6 years ago

Hmm... yes.

There are two ways of doing it (sorry, not verified, straight from my memory).

Method 1.

  1. Inspect .pto file what's the name of the image (I think it is dummy.jpg).
  2. Rename your image file to file from point 1.
  3. Open .pto file in Hugin.
  4. You should see the .ptos control points.

Method 2.

  1. Open Hugin.
  2. Add image file twice (follow the video tutorial) - images have to have separate lenses.
  3. File -> Apply Template and then select the template file.
  4. Original control points from .pto file will not be visible.

L.

utack commented 6 years ago

@ultramango i have gotten that far, and adjusted a few control points so far i see no effect on the outcome, but i guess once i adjusted them all correctly, it should show good results?

ultramango commented 6 years ago

Once you have control points - play with "optimisation" tab/options. Or just find "Optimise" button - this should find new, hopefully, better panorama parameters.

utack commented 6 years ago

can I also move the existing ones, by eye?

ultramango commented 6 years ago

Well, best if you removed existing (I mean the "old" ones) datapoints as they apply for a different photo, not yours.

utack commented 6 years ago

I moved some of them to better match my image, but the stitched result from your script using the new pto is exactly the same Am I missing something here?

ultramango commented 6 years ago

Ensure new .pto file is saved. Check output file(s) date and time (has they really been updated)? Use "-a" parameter that will force regeneration of the files.

utack commented 6 years ago

Edit: Works now Maybe @juniorwebunitygames my file works better for your camera too

gear360sm-c200_.zip

evertvorster commented 6 years ago

Hi there, utack.

Once the control points are adusted, you have to run the optimize algorithms in Hugin.

Inside the .pto file there are also positions of photos relative to the anchor photo, and these values are which is used in stitching, and also are the values that are adjusted when you optimize the .pto.

Kind regards, -Evert-

On 12 December 2017 at 18:49, utack notifications@github.com wrote:

Is there some sort of cache somewhere in the chain? Because I can delete ALL control points in the pto, and it still stitches the output the same way But when I delete the .pto itself, it complains it cannot find the pto and stops

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ultramango/gear360pano/issues/27#issuecomment-351112115, or mute the thread https://github.com/notifications/unsubscribe-auth/ALfL1avVv75R2UTXNFbXWiKo9Bo8-8voks5s_q6ogaJpZM4OGWH0 .

-- Evert Vorster Isometrix Acquistion Superchief

utack commented 6 years ago

Is it possible my lens is poorly shaped?
I have tried to set control points and optimize twice, from scratch, and wasted about 4h with this.
Every time i got a fit that worked perfectly on one stitch side, but had quite the offset on the other stitch side

evertvorster commented 6 years ago

Hi there.

I am sorry that you are struggling with this. My usual method for calibrating is something like this:

  1. Go somewhere where there is a lot of space between you and the horizon. In a pinch a football field will work, but a wide open grasslands with trees on the horizon works best.
  2. Raise the camera on a selfie stick to well above head height.
  3. If doing calibrations for photo, take a picture with both lenses at every 45 degrees. eg. 0, 45, 90, 135, 180, 225, 270, 315.
  4. If doing video calibrations, take a video while slowly rotating the camera. From the raw footage, extract a frame at approximately the same angles.
  5. Using the .pto file as a start, delete the images and associates control point.
  6. Import the 8 images produced in step 3 into hugin twice. Once for the left lens, and once for the right. Make sure that circular fisheye is selected as lens type, and that field of view is 360 (don't ask)
  7. Selecting the left lens images, modify the lens parameters to shift the center of the image to the center of the left lens.
  8. Create a mask for the left images. It should look like a circle and fit over the left lens image.
  9. Repeat steps 6 & 7 for the right images, but this time make sure the center of the lens and mask is over the right lens in the image.
  10. Modify the positional parameters for the first left hand image: set yaw to 180 (this makes the stitch look like the ActionDirector)
  11. Let Hugin automatically detect control points with CPfind. If this goes well, you should have a few thousand control points.
  12. Run the optimizer, positions only.
  13. Select all images, right-click and select clean control points. This should remove the worst fitting control points automatically.
  14. Run the optimizer, positions and view, then clean control points.
  15. Run optimizer, positions and barrel distortion. Clean control points.
  16. Run optimizer, everything without translation, Clean control points.
  17. Keep repeating step 15 until the average error is less than 1.
  18. Save your project as "Calibration" or something.
  19. Delete all images except the first image for the left and first image for the right lens.
  20. Save your project as "Calibrated_Photo" or video, or whatever.

With a bit of practice, this will take a lot less than the four hours you already spent tryin to manually find control points. You can now check the fit but doing a stitch, and if good, you can replace the default .pto file in the ultramango with yours. I recommend making a backup of the original, of course.

-Evert-

On 15 December 2017 at 19:10, utack notifications@github.com wrote:

Is it possible my lens is poorly shaped? I have tried to set control points and optimize twice, from scratch, and wasted about 4h with this. Every time i got a fit that worked perfectly on one stitch side, but had quite the offset on the other stitch side

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ultramango/gear360pano/issues/27#issuecomment-352059759, or mute the thread https://github.com/notifications/unsubscribe-auth/ALfL1fzbZbsE8IdTkQjWYhF0borzrr5cks5tAqgRgaJpZM4OGWH0 .

-- Evert Vorster Isometrix Acquistion Superchief

utack commented 6 years ago

@evertvorster I finally got it
Thank you for writing up this tutorial again 👍

utack commented 6 years ago

Can I just copy and paste my custom viewfield, pitch/roll/yaw and d parameter from my photo .pto into the 4k video.pto, or is it more tricky to adopt that file? I noticed this repo has entirely different lens parmaters for photo, 4k video and 2k video .pto Thanks

evertvorster commented 6 years ago

It's a little more tricky than that.

You first need a .pto that has pictures in it with control points automatically selected, and the entire .pto fully optimised.

THEN you can modify the Anchor image rotations, and hit optimize positions again, which will move the other lenses in the .pto accordingly.

Of course, you can just try to modify the rotations in the original .pto and optimize positions, but your mileage might vary

-Evert-

On 26 December 2017 at 18:06, utack notifications@github.com wrote:

Can I just copy and paste my custom pitch/roll/yaw and d parameter from my photo .pto into the 4k video.pto, or is it more tricky to adopt that file? Thanks

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ultramango/gear360pano/issues/27#issuecomment-353984183, or mute the thread https://github.com/notifications/unsubscribe-auth/ALfL1Tdnkgc8wS60H3P8EUGyxh-cmj-Eks5tERl-gaJpZM4OGWH0 .

-- Evert Vorster Isometrix Acquistion Superchief