OpenStitching / stitching

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

two same pic stitching err! #93

Closed zhangjunqiang closed 1 year ago

zhangjunqiang commented 1 year ago

my code like this.

  features = _detect_features(from_image, target_image, detector)
    matcher = FeatureMatcher()
    matches = matcher.match_features(features)
    relevant_matches = matcher.draw_matches_matrix([from_image, target_image], features, matches, conf_thresh=1,
                                                       inliers=True, matchColor=(0, 255, 0))

if the from_image and target_image is same. the len(list(relevant_matches)) is 0. when i debug this code. i found that the match.confidence is zero.

@staticmethod
    def draw_matches_matrix(
        imgs, features, matches, conf_thresh=1, inliers=False, **kwargs
    ):
        matches_matrix = FeatureMatcher.get_matches_matrix(matches)
        for idx1, idx2 in FeatureMatcher.get_all_img_combinations(len(imgs)):
            match = matches_matrix[idx1, idx2]
            if match.confidence < conf_thresh:
                continue
            if inliers:
                kwargs["matchesMask"] = match.getInliers()
            yield idx1, idx2, FeatureMatcher.draw_matches(
                imgs[idx1], features[idx1], imgs[idx2], features[idx2], match, **kwargs
            )
zhangjunqiang commented 1 year ago

_detect_features code

def _detect_features(from_image, target_image, detector="sift"):
    """
    提取到图片的特征
    :param images:
    :return:
    """
    finder = FeatureDetector(detector)
    features = [finder.detect_features(img) for img in [from_image, target_image]]
    return features
zhangjunqiang commented 1 year ago

image

zhangjunqiang commented 1 year ago

In the tutorial code. the confidence matrix of array. The diagonal of a matrix is 0.

lukasalexanderweber commented 1 year ago

_detect_features code

def _detect_features(from_image, target_image, detector="sift"):
    """
    提取到图片的特征
    :param images:
    :return:
    """
    finder = FeatureDetector(detector)
    features = [finder.detect_features(img) for img in [from_image, target_image]]
    return features

Why wont you use the build in FeatureDetector class?

zhangjunqiang commented 1 year ago

_detect_features code

def _detect_features(from_image, target_image, detector="sift"):
    """
    提取到图片的特征
    :param images:
    :return:
    """
    finder = FeatureDetector(detector)
    features = [finder.detect_features(img) for img in [from_image, target_image]]
    return features

Why wont you use the build in FeatureDetector class? It is the build in FeatureDetector. This is the import code:

import mpld3
from matplotlib import pyplot as plt
import cv2 as cv
from stitching.feature_detector import FeatureDetector
from stitching.image_handler import ImageHandler
from stitching.feature_matcher import FeatureMatcher
lukasalexanderweber commented 1 year ago

Your list comprehension is wrong

zhangjunqiang commented 1 year ago

Your list comprehension is wrong

Can you tell me why? Intuitively, two identical pictures should return a high degree of similarity.

lukasalexanderweber commented 1 year ago

You need to get the features Independent of the matching, something like

features1 = detector.detect_features(img1) features2 = detector.detect_features(img2)

And then

matches1to2 = matcher.match_features([features1, features2])