File size: 1,702 Bytes
c583b63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""This a test for sequential stitcher method"""

from pathlib import Path
import cv2
from panaroma_stitcher.sequential_stitcher import SequentialStitcher


def test_detect_and_describe() -> None:
    """Test for detecting and describing keypoints in KeypointStitcher"""
    stitcher = SequentialStitcher(Path("./test_data/mountain"), feature_detector="sift")
    detector = stitcher.detect_and_describe()
    assert isinstance(detector, cv2.SIFT)
    stitcher = SequentialStitcher(Path("./test_data/mountain"), feature_detector="orb")
    detector = stitcher.detect_and_describe()
    assert isinstance(detector, cv2.ORB)
    stitcher = SequentialStitcher(
        Path("./test_data/mountain"), feature_detector="brisk"
    )
    detector = stitcher.detect_and_describe()
    assert isinstance(detector, cv2.BRISK)


def test_matcher() -> None:
    """Test for matching keypoints in KeypointStitcher"""
    stitcher = SequentialStitcher(
        Path("./test_data/mountain"), feature_detector="sift", matcher_type="bf"
    )
    matcher = stitcher.matcher()
    assert isinstance(matcher, cv2.BFMatcher)
    stitcher = SequentialStitcher(
        Path("./test_data/mountain"), feature_detector="sift", matcher_type="flann"
    )
    matcher = stitcher.matcher()
    assert isinstance(matcher, cv2.FlannBasedMatcher)


def test_stitcher(tmp_path: Path) -> None:
    """Test for stitcher method in KeypointStitcher"""
    stitcher = SequentialStitcher(
        Path("./test_data/mountain"),
        feature_detector="sift",
        matcher_type="bf",
        number_feature=500,
    )
    stitcher.stitcher(str(tmp_path / "test_result.png"), True)
    assert Path(tmp_path / "test_result.png").exists()