OpenStitching / stitching

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

Bug in FeatureMatcher() #52

Closed algopert closed 1 year ago

algopert commented 1 year ago

It seems that each element interfere to each other. After removing 7th image, I can get correct the result. image

Only after physically removing the 7th image, I had got the correct result. If I understand the theory correctly, the matching result should only depend on 2 feature packs. Why is 3rd party intervention having an impact? This result doesn't depend on whether I use match-mask or not as well.

algopert commented 1 year ago

Ok. It was derived from that I settled range_width to 10. image

But still not sure why the match cofidence is slightly different. image

lukasalexanderweber commented 1 year ago

The confidence varies from Run to Run

algopert commented 1 year ago

Thanks. I guess because the algo is using RANSAC.

Could you please answer my another question? image

First case is to stitch 4 images serially. I have no issue on it.

But in 2nd case, all images have enough confidence to each other.

At this point, do all confidence participate in the camera estimator calculation? Or are some of the confidences removed to construct a loop-free graph?

Thanks.

lukasalexanderweber commented 1 year ago

can you please create a matches graph

--matches_graph_dot_file matches.txt

and share the result for your use case?

algopert commented 1 year ago

graph.txt

algopert commented 1 year ago

----- Confidence Matrix--------- [[0. 2.35 0.3 0.57] [2.35 0. 0.52 0.37] [0.3 0.52 0. 1.2 ] [0.57 0.37 1.2 0. ]] Matches Image 0 to Image 1: CF 2.35 195 Matches Image 0 to Image 3: CF 0.57 29 Matches Image 1 to Image 2: CF 0.52 27 Matches Image 2 to Image 3: CF 1.2 165 image

algopert commented 1 year ago

The case using "BRISK"

-----  Confidence Matrix---------
[[0.   2.08 0.84 0.77]
 [2.08 0.   1.22 1.05]
 [0.84 1.22 0.   2.16]
 [0.77 1.05 2.16 0.  ]]
Matches Image 0 to Image 1: CF 2.08 137
Matches Image 0 to Image 2: CF 0.84 18
Matches Image 0 to Image 3: CF 0.77 16
Matches Image 1 to Image 2: CF 1.22 24
Matches Image 1 to Image 3: CF 1.05 20
Matches Image 2 to Image 3: CF 2.16 303
graph matches_graph{
"46_-28_1_-133_41_65.png" -- "47_-14_2_-134_41_65.png"[label="Nm=193, Ni=137, C=2.07891"];
"46_-28_1_-133_41_65.png" -- "70_-30_1_-47_41_65.png"[label="Nm=45, Ni=18, C=0.837209"];  
"46_-28_1_-133_41_65.png" -- "71_-14_0_-46_41_65.png"[label="Nm=43, Ni=16, C=0.76555"];
}
lukasalexanderweber commented 1 year ago

In the brisk case all Images are alinged directly to 46_-281-133_41_65.png

algopert commented 1 year ago

Is there any way to introduce FLANN matcher?

Your library is great, but sometimes I feel the limitations of current matchers a little.

lukasalexanderweber commented 1 year ago

From the Docs you should be able to include it

algopert commented 1 year ago

Thanks. Tried, but KNN matcher was worse!

Anyway, thanks a lot!

lukasalexanderweber commented 1 year ago

but sometimes I feel the limitations of current matchers a little.

to you mean performance limitations or matches quality limitations?

algopert commented 1 year ago

Yes, for example

image image

algopert commented 1 year ago

image

lukasalexanderweber commented 1 year ago

I think those features are filtered out because of Lowe's Ratio test (they are too similar). You can play around with the match_conf parameter to maybe be able to include them.

algopert commented 1 year ago

Yes, I tried it as well. image But it was algo pointless.

lukasalexanderweber commented 1 year ago

ok. we would need to dig deeper on if matches are computed and where they are omitted (Ratio Test? RANSAC?).

algopert commented 1 year ago

Agreed! :)

lukasalexanderweber commented 1 year ago

I'll close this issue, but you can keep me updated here if you make any progress :)

algopert commented 1 year ago

Ok, Thanks.

algopert commented 1 year ago

Hi Lukas.

Hope you are well.

I faced one issue...

I attempted to stitch only 2 images using a homography. matches[1].H was used as the homography matrix. But contrary to my expectations, I can't stitch the 2 images properly.

All is from your code. My snippet are as follow.

fileNames = ["5_150_0_-88_41_65.png","6_180_0_-92_41_65.png"]
img_handler = ImageHandler()
img_handler.set_img_names(fileNames)

medium_imgs = list(img_handler.resize_to_final_resolution())
low_imgs = list(img_handler.resize_to_low_resolution(medium_imgs))
final_imgs = list(img_handler.resize_to_final_resolution())
...
i = matches[1].src_img_idx
j = matches[1].dst_img_idx
homoMatrix = matches[1].H

srcImg = medium_imgs[i]
dstImg = medium_imgs[j]

dst = cv.warpPerspective(srcImg,homoMatrix,(dstImg.shape[1] + srcImg.shape[1], srcImg.shape[0]))
dst[0:dstImg.shape[0],0:dstImg.shape[1]] = dstImg
plot_image(dst)

Could you please let me know what is my mistakes?

algopert commented 1 year ago

FYI,

I tried with matches[2].H as well.

image

image

lukasalexanderweber commented 1 year ago

Have you make any progress? I'm sadly not that deep into homography matrix to see the issue on the first glance :/

algopert commented 1 year ago

I mean I couldn't overlap the 2nd image on the 1st image by using match[i].H. So I just thought match[i].H is not homography matrix... If so, what is match[i].H?