deephealthproject / pyecvl

Python wrapper for the ECVL.
MIT License
4 stars 2 forks source link

Support for OpenCV 4 #35

Closed simleo closed 3 years ago

simleo commented 4 years ago

If compiled with OpenCV >= 4, ECVL requires the calib3d OpenCV component in addition to core, imgproc, imgcodecs, photo. However, setup.py is not listing opencv_calib3d among the libraries to be linked.

Simply adding it unconditionally could be a solution, but then we need to document that we always expect the opencv_calib3d library to be present, even with OpenCV < 3.

Trying to determine the installed OpenCV version, on the other hand, is nontrivial and probably not worth it.

simleo commented 3 years ago

Getting the installed opencv version is straightforward in C++:

#include "opencv2/opencv.hpp"
#include <iostream>

using namespace cv;
using namespace std;

int main() {
  cout << "version string: " << CV_VERSION << endl;
  cout << "Major version: " << CV_MAJOR_VERSION << endl;
  cout << "Minor version: " << CV_MINOR_VERSION << endl;
  cout << "Patch version: " << CV_SUBMINOR_VERSION << endl;
}

We can generate the above program on-the-fly and compile it within a build_ext subclass:

class PyecvlExt(build_ext):

    def build_extension(self, ext):
        self.compiler.compile([program_src], output_dir=some_tempdir)
        [...]

Then execute it with subprocess and capture the output.

simleo commented 3 years ago

I ran a quick test with opencv 4.5.2 and it worked as it is, picking up the extra library links from ECVL:

# ldd /usr/local/lib/python3.6/dist-packages/pyecvl-0.10.0-py3.6-linux-x86_64.egg/pyecvl/_core.cpython-36m-x86_64-linux-gnu.so |  grep opencv
    libopencv_imgcodecs.so.4.5 => /usr/local/lib/libopencv_imgcodecs.so.4.5 (0x00007f54a78eb000)
    libopencv_photo.so.4.5 => /usr/local/lib/libopencv_photo.so.4.5 (0x00007f54a7649000)
    libopencv_calib3d.so.4.5 => /usr/local/lib/libopencv_calib3d.so.4.5 (0x00007f54a726b000)
    libopencv_imgproc.so.4.5 => /usr/local/lib/libopencv_imgproc.so.4.5 (0x00007f54a65e5000)
    libopencv_core.so.4.5 => /usr/local/lib/libopencv_core.so.4.5 (0x00007f54a6047000)
    libopencv_features2d.so.4.5 => /usr/local/lib/libopencv_features2d.so.4.5 (0x00007f54a42fb000)
    libopencv_flann.so.4.5 => /usr/local/lib/libopencv_flann.so.4.5 (0x00007f54a4093000)

Actually, it seems that we don't need to explicitly link the extra libraries anymore. Maybe it's a leftover from the early stage when we still used to build on top of the ecvl static libraries. Anyway, I'm closing this for now. It can be reopened if anyone has problems.