opencv python binder does not bind anything

asked 2018-03-10 17:27:37 -0500

js42673 gravatar image

updated 2018-03-11 14:47:04 -0500

berak gravatar image


I write a custom opencv module for working with custom image file and video formats. I already had a working library that I reorganize looking at the modules ximgproc, highgui and core. My module have only four functions. The aim of my module is mostly to use those functions in Python thanks to OpenCV's interface.

I follow the intruction explained here and there

namespace cv{ namespace fs {
CV_EXPORTS_W Mat imread_extended(const String& filename,const int& fmt = IMREAD_COLOR);

CV_EXPORTS_W int imwrite_extended(const String &filename, InputArray img, const std::vector<int> &params = std::vector<int>());

CV_EXPORTS_W void read_sequence(const String& filename, OutputArray img,const int& fmt = IRT_RAW);

CV_EXPORTS_W void sequence2avi(InputArray seq, OutputArray avi,const int& color_map = COLORMAP_HOT);
} // fs
} // cv

I inspired my self of the "original" imread, imwrite, and many others functions.

The compilation passed like a charm but at the end I didn't had any python module. Does anyone already encounter such issue ? What can I do that may help the translation ?


Here are the make outputs:

    **[  0%] Building CXX object modules/irt/CMakeFiles/opencv_irt.dir/src/fsequence.cpp.o
    cc1plus: warning: /home/smile/lib_dir/opencv/opencv_340/bin/modules/irt/precomp.hpp.gch/opencv_irt_Release.gch: not used because `__cpp_aggregate_nsdmi' not defined [-Winvalid-pch]
    /home/smile/lib_dir/opencv/opencv_340/opencv_contrib/modules/irt/src/fsequence.cpp: In member function ‘virtual void cv::seq::{anonymous}::seq_raw2temp_::operator()(const cv::Range&) const’:
    /home/smile/lib_dir/opencv/opencv_340/opencv_contrib/modules/irt/src/fsequence.cpp:297:36: warning: unused variable ‘buf’ [-Wunused-variable]
              float CV_DECL_ALIGNED(32) buf[8];
    [  0%] Building CXX object modules/irt/CMakeFiles/opencv_irt.dir/src/ibin.cpp.o
    cc1plus: warning: /home/smile/lib_dir/opencv/opencv_340/bin/modules/irt/precomp.hpp.gch/opencv_irt_Release.gch: not used because `__cpp_aggregate_nsdmi' not defined [-Winvalid-pch]
    /home/smile/lib_dir/opencv/opencv_340/opencv_contrib/modules/irt/src/ibin.cpp:1138:6: warning: ‘void cv::ibin::{anonymous}::check_header(cv::ibin::{anonymous}::output_t*, const cv::ibin::{anonymous}::simple_t&)’ defined but not used [-Wunused-function]
     void check_header(output_t* header_main_info,const simple_t& all_in_one)
    /home/smile/lib_dir/opencv/opencv_340/opencv_contrib/modules/irt/src/ibin.cpp:631:6: warning: ‘void cv::ibin::{anonymous}::init_simple(cv::ibin::{anonymous}::simple_t&, const size_t&, const size_t&, const cv::ibin::{anonymous}::output_t*)’ defined but not used [-Wunused-function]
     void init_simple(simple_t& simple,const size_t& rows,const size_t& cols,const output_t* header)
    [  0%] Building CXX object modules/irt/CMakeFiles/opencv_irt.dir/src/irt.cpp.o
    cc1plus: warning: /home/smile/lib_dir/opencv/opencv_340/bin/modules/irt/precomp.hpp.gch/opencv_irt_Release.gch: not used because `__cpp_aggregate_nsdmi' not defined [-Winvalid-pch]
    [  0%] Building CXX object modules/irt/CMakeFiles/opencv_irt.dir/src/seq_utils.cpp.o
    cc1plus: warning: /home/smile/lib_dir/opencv/opencv_340/bin/modules/irt/precomp.hpp.gch/opencv_irt_Release.gch: not used because `__cpp_aggregate_nsdmi' not defined [-Winvalid-pch]
    /home/smile/lib_dir/opencv/opencv_340/opencv_contrib/modules/irt/src/seq_utils.cpp: In member function ‘virtual void cv::seq_utils::{anonymous}::norm_::operator()(const cv::Range&) const’:
    /home/smile/lib_dir/opencv/opencv_340/opencv_contrib/modules/irt/src/seq_utils.cpp:168:21: warning: declaration of ‘end’ shadows a previous local [-Wshadow]
                 __m128i end = _mm_packus_epi16(end1,end2);
    /home ...
edit retag flag offensive close merge delete


  • where did you put the new code ?
  • cmake output, please
berak gravatar imageberak ( 2018-03-10 17:34:24 -0500 )edit

Inspired by this post I created a folder inside the folder module of my local opencv_contrib folder. Then like for every module I created two other src and include and another folder opencv2 inside include, I put the sources files into src folder and the callable head in include/opencv2. I created inside the src folder a precomp.hpp file. I created the CMakeLists.txt inspired by the one of the module ximgproc.

js42673 gravatar imagejs42673 ( 2018-03-11 11:54:03 -0500 )edit

above is actually the make output, not the cmake one.

if your bindings do not show up in your newly built cv2.pyd (did you run a make install ?) we'll have to look at the cmake output again, so please try to add it !

i see some warnings, but no real error. what is the problem, now ?

opencv_340 -- you have to use exactly the same opencv_contrib and main opencv version !

also have a look into opencv_340/build/modules/python_bindings_generator , that's where the generated c++ heraders should be !

berak gravatar imageberak ( 2018-03-11 12:04:58 -0500 )edit

I did run a make install and I test it in C++ both it worked fine. I am recompiling everything for confirmation. What should the "proper" output from cmake if it arrive to bind my code ? And what could prevent the binding generator to work ?

js42673 gravatar imagejs42673 ( 2018-03-11 12:21:44 -0500 )edit

let's just see it.

and again, python_bindings_generator

your make output does not show any sign of building python wrappers / running the generator scripts

berak gravatar imageberak ( 2018-03-11 12:28:57 -0500 )edit

I partialy answer to you the second message, Yes I use exactly the same version for opencv, opencv_contrib, and opencv_extra in order to prevent compatibility of issues.

js42673 gravatar imagejs42673 ( 2018-03-11 12:30:53 -0500 )edit

Here are the cmake messages:

[  0%] Built target opencv_irt_pch_dephelp

[  0%] Built target pch_Generate_opencv_irt

[  0%] Built target opencv_irt

[  0%] Building CXX object modules/irt/CMakeFiles/opencv_irt_pch_dephelp.dir/opencv_irt_pch_dephelp.cxx.o

[  0%] Linking CXX static library ../../lib/libopencv_irt_pch_dephelp.a

[  0%] Built target opencv_irt_pch_dephelp

[  0%] Generating precomp.hpp.gch/opencv_irt_Release.gch

[  0%] Built target pch_Generate_opencv_irt

[  0%] Building CXX object modules/irt/CMakeFiles/opencv_irt.dir/src/image_format.cpp.o

[  0%] Building CXX object modules/irt/CMakeFiles/opencv_irt.dir/src/sequence.cpp.o
js42673 gravatar imagejs42673 ( 2018-03-11 14:29:52 -0500 )edit

how long do we have to wait for the cmake output ?

(again, above is from make, not cmake)

(maybe it it did not find python headers/libs, maybe your numpy is outdated)

no way to tell, without the required information. stop running make even, unless the cmake output meets your requirements

(right now -- i'm thinking, -- you're hitting make all over and over, while the problem is way before that (again -- cmake))

berak gravatar imageberak ( 2018-03-11 14:31:04 -0500 )edit

Sorry I use cmake only for compiling librairies and effectivelly I didnot distinguish the difference between cmake messages and make messages. I'll do now, sincerelly sorry for that :(.

js42673 gravatar imagejs42673 ( 2018-03-11 14:47:16 -0500 )edit

looks like it will install python bindings for python 3.6.3 (is that your problem ?)

berak gravatar imageberak ( 2018-03-11 14:52:41 -0500 )edit