Reputation:
Based on this question/answer, I have been trying to use OpenCV's Stitcher class in python. My code is basically the same as in the answer.
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])
The issue is I want to change the mode from Panoramic to Scans. In the c++ documentation, the create method has an input of mode. However, the createStitcher class in Python only takes one input- whether or not to try gpu. Is there a way to specify the mode in Python?
When I tried createStitcherScans, I get an error
stitcher = cv2.createStitcherScans(False)
"AttributeError: 'module' object has no attribute 'createStitcherScans'"
I did find this GitHub issue that seems relevant, regarding Python bindings missing something. But this is over my head and I am not sure how to edit the opencv code to do this properly. I tried adding this to the stitching.hpp:
typedef Stitcher::Mode Mode;
But nothing happened. createStitcher(1, False) still give me the attribute error. Any help would be greatly appreciated.
Upvotes: 3
Views: 5673
Reputation: 2495
Looking at the official test code for Python on GitHub samples/python/stitching.py
, you can use Stitcher_PANORAMA
or Stitcher_SCANS
. You can always check the test code of any module, like modules/stitching/misc/python/test
in this case.
stitcher = cv.Stitcher.create(cv.Stitcher_PANORAMA)
Upvotes: 1
Reputation: 4521
This has been resolved in Open CV 4 (at least in 4.1.0 which I'm running). You can now specify mode
as a keyword argument to cv2.Stitcher.create
:
stitcher = cv2.Stitcher.create(mode = 1)
It seems that the enumeration labels for the different modes have not yet been ported but it works with numbers. PANORAMA
is 0
, SCANS
is 1
as defined here.
Note, if you're working on Google Colab then you can change the version of Open CV like this:
!pip3 install opencv-python==4.1.0.25
Upvotes: 2
Reputation: 31
I am having the same issue. After looking at the documentation it looks like the python wrapper function is not mapping to create(), but rather createDefault() which does not have a mode input, only the try_use_gpu input. I don't have experience with wrappers, but one could try to figure it out by reading OpenCV's info on how the python bindings work.
based on my work with stitch so far in python, it seems like createDefault() creates a stitcher in PANORAMA mode since it is warping my images. I can't dedicate work time to looking through the wrappers, but if I end up spending personal time to fix it, I will update my answer here.
Upvotes: 1