Exposing the LBP descriptors from OpenCV in Python

前端 未结 2 1527
梦如初夏
梦如初夏 2021-01-06 04:33

I want to be able to calculate the LBP discriptor in python using OpenCV. According to this I need to compile openCV again.

I changed the elbp() functio

2条回答
  •  攒了一身酷
    2021-01-06 05:27

    So, it worked.

    To make the function accessible: .

    1. I made the following change to facerec.cpp, from:

      static void elbp(InputArray src, OutputArray dst, int radius, int neighbors)
      {
      ...
      }    
      
      static Mat elbp(InputArray src, int radius, int neighbors) {
          Mat dst;
          elbp(src, dst, radius, neighbors);
          return dst;
      }
      
      static Mat spatial_histogram(InputArray _src, int numPatterns,
                               int grid_x, int grid_y, bool /*normed*/)
      {
      ...
      }
      

      to:

      void elbp(InputArray src, OutputArray dst, int radius, int neighbors)
      {
      ...
      }    
      
      Mat elbp(InputArray src, int radius, int neighbors) {
          Mat dst;
          elbp(src, dst, radius, neighbors);
          return dst;
      }
      
      Mat spatial_histogram(InputArray _src, int numPatterns,
                               int grid_x, int grid_y, bool /*normed*/)
      {
      ...
      }
      
    2. I added the following into /modules/contrib/include/opencv2/include/contrib.hpp under the cv namespace:

      CV_EXPORTS_W void elbp(InputArray src, OutputArray dst, int radius, int neighbors);
      
    3. I then creted a release folder in the opencv root.
    4. From within that folder, I ran:

      cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON -D WITH_TBB=ON -D BUILD_EXAMPLES=ON ..
      
    5. Next, I ran make
    6. take the cv2.so shared object created under /lib and put it where python looks for the packages. For me, it was /usr/local/lib/python2.7/dist-packages/
    7. run python

      from cv2 import spatial_histogram
      

    Voila!

提交回复
热议问题