How to use OpenCV Stitcher class with Python?

后端 未结 1 1349
面向向阳花
面向向阳花 2020-12-09 19:02

I\'m trying to use OpenCV Stitcher class with Python, with no luck. My code is:

import cv2
stitcher = cv2.createStitcher(False)
foo = cv2.imread(\"foo.png\")         


        
相关标签:
1条回答
  • 2020-12-09 19:17

    You're using it right, be the process failed for some reason.

    The first value of the result tuple is an error code, with 0 indicating success. Here you got 1, which means, according to stitching.hpp, that the process needs more images.

    enum Status
    {
        OK = 0,
        ERR_NEED_MORE_IMGS = 1,
        ERR_HOMOGRAPHY_EST_FAIL = 2,
        ERR_CAMERA_PARAMS_ADJUST_FAIL = 3
    };
    

    ERR_NEED_MORE_IMGS usually indicates that you don't have enough keypoints in your images.

    If you need more details about why the error occurs, you could switch to C++ and debug the process in details.


    Edit : providing working example

    Same code as OP, just added result save and absolute paths.

    import cv2
    
    stitcher = cv2.createStitcher(False)
    foo = cv2.imread("D:/foo.png")
    bar = cv2.imread("D:/bar.png")
    result = stitcher.stitch((foo,bar))
    
    cv2.imwrite("D:/result.jpg", result[1])
    

    with these images: (I hope you love pandas)

    foo.png

    bar.png

    result.jpg

    0 讨论(0)
提交回复
热议问题