Python binding stitcher class

asked 2018-11-18 10:26:56 -0600

LBerger gravatar image

updated 2018-11-18 13:46:13 -0600

My problem is translate this C++ code in python ... I want to generate python binding for :

struct CV_EXPORTS ImageFeatures
    int img_idx;
    Size img_size;
    std::vector<KeyPoint> keypoints;
    UMat descriptors;

I have done :

struct CV_EXPORTS_W_SIMPLE ImageFeatures
    CV_PROP_RW int img_idx;
    CV_PROP_RW Size img_size;
    std::vector<KeyPoint> keypoints;
    CV_PROP_RW UMat descriptors;
    CV_WRAP std::vector<KeyPoint> getKeypoints() { return keypoints; };

and it works :

import numpy as np
import cv2 as cv
finder= cv.xfeatures2d_SURF.create()
img = cv.imread('f:/images/pano/pano1.jpg')
img = cv.imread('f:/images/pano/pano2.jpg')
img = cv.imread('f:/images/pano/pano3.jpg')
for img in imgListe:
    imgFea= cv.detail.computeImageFeatures2(finder,img)

My problem is when I add CV_PROP_RW before std::vector<keypoint> keypoints; I have got a compilation error :

10>G:\Lib\opencv\modules\python\src2\cv2.cpp(24): error C2039: 'to': is not a member of 'PyOpenCV_Converter<T,void>'
10>        with
10>        [
10>            T=vector_KeyPoint
10>        ]
10>G:\Lib\opencv\modules\python\src2\cv2.cpp(24): note: see declaration of 'PyOpenCV_Converter<T,void>'
10>        with
10>        [
10>            T=vector_KeyPoint
10>        ]
10>G:\Lib\build\opencv\modules\python_bindings_generator\pyopencv_generated_types.h(72119): note: see reference to function template instantiation 'bool pyopencv_to<vector_KeyPoint>(PyObject *,T &,const char *)' being compiled
10>        with
10>        [
10>            T=vector_KeyPoint
10>        ]
10>G:\Lib\opencv\modules\python\src2\cv2.cpp(24): error C3861: 'to': identifier not found
10>Done building project "opencv_python3.vcxproj" -- FAILED.

Then i add a method to get vector<keypoints> and removed CV_WRAP_RW. Is it only way to get value of c++ vector in python ?

private message : @berak any idea?

edit retag flag offensive close merge delete


lol, i already promise: you won't get happy with the idea. the solution for #13187 might be:

CV_WRAP_AS(apply) void operator()(some_args)

(but you obviously have found out on your own, i guess ;)

but i'm puzzled. shouldn't the current problem with to() be covered from here ?

can you add the resp. c++ wrapper from build/modules/python_bindings_generator/pyopencv_???.h

also, isn't everything in ImageFeatures "read-only" ?

berak gravatar imageberak ( 2018-11-18 10:45:40 -0600 )edit

hmm, (alternative idea) -- what would be the c++ use-case of the functionality, you're trying to wrap here ?

sometimes, it might be easier, to add a new c++ function (with an "easier to wrap" interface), that does it all under the hood (without having to expose "problematic types"). related:

berak gravatar imageberak ( 2018-11-18 10:47:53 -0600 )edit

CV_WRAP_AS(apply) thanks I didn't find it : I was looking how to generate python doc in VS 2017. (update cmake and add BeautifulSoup and -DPYTHON_EXECUTABLE="C:/Program Files (x86)/Microsoft Visual Studio/Shared/Python36_64/python.exe"

I pushed on Is it enough?

I want to write stitching_detailed in python : Brute force method

LBerger gravatar imageLBerger ( 2018-11-18 11:04:47 -0600 )edit

what do you think of the "alternative" idea? would not that be far easier (and more clean) ?

berak gravatar imageberak ( 2018-11-18 11:36:19 -0600 )edit
LBerger gravatar imageLBerger ( 2018-11-18 11:42:17 -0600 )edit

"what do you think of the "alternative" idea?" use c++ class and simply wrap as here

LBerger gravatar imageLBerger ( 2018-11-18 11:55:56 -0600 )edit

Change this:

import numpy as cv


import numpy as np
supra56 gravatar imagesupra56 ( 2018-11-18 12:15:38 -0600 )edit

@LBerger, can you add the c++ code for your pipeline to the question ?

(again, imho, wrapping that (with already known types would be far more useful,than having to extend the python / java ??? wrappers, based on your original idea.)

berak gravatar imageberak ( 2018-11-18 12:28:53 -0600 )edit

Problem : CV_WRAP_AS(apply) operator() does not generate any python documentation

LBerger gravatar imageLBerger ( 2018-11-18 13:45:11 -0600 )edit

work in progress

b, c =h.apply(features,p,None)
for cam in c:
b,c = ba.apply(features,p,c) #
LBerger gravatar imageLBerger ( 2018-11-19 08:42:04 -0600 )edit