2x1=10

because numbers are people, too
Persönliches
Fotografie
Programmierung
    • Building OpenCV for Anaconda Python 3

      Don’t judge me, I know how this title sounds. The harsh real­i­ty is — as per writ­ing of this post — that I always have a hard time get­ting CMake to rec­og­nize the right Python path when I’m using an Ana­con­da envi­ron­ment. In the­o­ry it’s just

      git clone https://github.com/opencv/opencv.git opencv
      mkdir opencv/build && cd opencv/build
      cmake -DCMAKE_INSTALL_PREFIX=/usr/local  ..
      make -j8
      (sudo) make install
      

      and there you go. It will hap­pi­ly pick up your environment’s Python instal­la­tion and build that for you. Of course, it looks more along the lines of

      cmake \
          -DCMAKE_INSTALL_PREFIX="/usr/local" \
          -DOPENCV_EXTRA_MODULES_PATH="../opencv_contrib/modules" \
          -DBUILD_DOCS=OFF \
          -DBUILD_TESTS=OFF \
          -DBUILD_EXAMPLES=OFF \
          -DBUILD_PERF_TESTS=OFF \
          -DBUILD_opencv_dnn=OFF \
          -DENABLE_FAST_MATH=ON \
          -DWITH_OPENMP=ON \
          -DWITH_TBB=ON \
          -DMKL_WITH_TBB=ON \
          -DMKL_WITH_OPENMP=ON \
          -DCMAKE_CXX_COMPILER="/usr/bin/g++-5" \
          -DCMAKE_C_COMPILER="/usr/bin/gcc-5" \
          -DCUDA_HOST_COMPILER="/usr/bin/gcc-5" \
          -DCUDA_FAST_MATH=ON \
          -DCUDA_ARCH_BIN="5.2" \
          -DWITH_CUBLAS=ON \
          ..
      

      When­ev­er you then add

      conda activate my-environment
      

      to the mix though, all hell breaks loose and you end up with par­tial­ly con­fig­ured Python 2 and no Python 3 sup­port at all. The trick seems to be not to rely on OpenCV’s stan­dard Python con­fig­u­ra­tion val­ues

      PYTHON3_LIBRARY
      PYTHON3_EXECUTABLE
      PYTHON3_INCLUDE_DIR
      PYTHON3_INCLUDE_DIR2
      PYTHON3_NUMPY_INCLUDE_DIRS
      

      but rather to use the seem­ing­ly undoc­u­ment­ed val­ues

      PYTHON3_LIBRARIES
      PYTHON3_INCLUDE_PATH
      

      as well, giv­ing it the nice appear­ance of

      cmake \
          -DCMAKE_BUILD_TYPE=RELEASE \
          -DCMAKE_INSTALL_PREFIX="/your/anaconda3" \
          -DOPENCV_EXTRA_MODULES_PATH="../opencv_contrib/modules" \
          -DBUILD_DOCS=OFF \
          -DBUILD_TESTS=OFF \
          -DBUILD_EXAMPLES=OFF \
          -DBUILD_PERF_TESTS=OFF \
          -DBUILD_opencv_dnn=ON \
          -DTINYDNN_USE_NNPACK=OFF \
          -DTINYDNN_USE_TBB=ON \
          -DTINYDNN_USE_OMP=ON \
          -DENABLE_FAST_MATH=ON \
          -DWITH_OPENMP=ON \
          -DWITH_TBB=ON \
          -DMKL_WITH_TBB=ON \
          -DMKL_WITH_OPENMP=ON \
          -DCMAKE_CXX_COMPILER="/usr/bin/g++-5" \
          -DCMAKE_C_COMPILER="/usr/bin/gcc-5" \
          -DCUDA_HOST_COMPILER="/usr/bin/gcc-5" \
          -DCUDA_FAST_MATH=ON \
          -DCUDA_ARCH_BIN="5.2" \
          -DWITH_CUBLAS=ON \
          -DBUILD_opencv_python2=OFF \
          -DPYTHON_EXECUTABLE="/your/anaconda3/bin/python3" \
          -DPYTHON_LIBRARY="/your/anaconda3/lib/libpython3.6m.so" \
          -DPYTHON3_LIBRARY="/your/anaconda3/lib/libpython3.6m.so" \
          -DPYTHON3_EXECUTABLE="/your/anaconda3/bin/python3" \
          -DPYTHON3_INCLUDE_DIR="/your/anaconda3/include/python3.6m" \
          -DPYTHON3_INCLUDE_DIR2="/your/anaconda3/include" \
          -DPYTHON3_NUMPY_INCLUDE_DIRS="/your/anaconda3/lib/python3.6/site-packages/numpy/core/include" \
          -DPYTHON3_INCLUDE_PATH="/your/anaconda3/include/python3.6m" \
          -DPYTHON3_LIBRARIES="/your/anaconda3/lib/libpython3.6m.so" \
          -DHDF5_C_LIBRARY_z="/your/anaconda3/lib/libz.so" \
          ..
      

      And then it’ll do what you want it to do. Because I’m tired of retry­ing every­time, on github.com/sunsided/opencv-cmake is my repo with sup­port for the OpenCV Extras Mod­ule and some doc­u­men­ta­tion for this.

      So, what paths go in there? Well, this blog post has a very flashy way of find­ing out.

      For CMAKE_INSTALL_PREFIX you use

      python3 -c "import sys; print(sys.prefix)"
      

      so it will install OpenCV direct­ly into your Ana­con­da instal­la­tion.
      For PYTHON3_EXECUTABLE you call

      which python3
      

      and PYTHON3_INCLUDE_DIR is giv­en by

      python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())"
      

      Final­ly, a PYTHON3_PACKAGES_PATH can be found using

      python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
      

      which you a can use to deter­mine the PYTHON3_NUMPY_INCLUDE_DIRS, although CMake strange­ly did that part right for me.

      August 23rd, 2017 GMT +2 von
      Markus
      2017-08-23T21:06:08+02:00 2017-08-23T21:35:12+02:00 · 0 Kommentare
      OpenCV Anaconda CMake
      Image Processing

      Hinterlasse einen Kommentar

      Hier klicken, um das Antworten abzubrechen.

    1. « newer
    2. 1
    3. 2
    4. 3
    5. 4
    6. 5
    7. 6
    8. 7
    9. 8
    10. “Compiler crashed with code 1” on Mono">9
    11. …
    12. 43
    13. older »
    • Kategorien

      • .NET
        • ASP.NET
        • Core
        • DNX
      • Allgemein
      • Android
      • Data Science
      • Embedded
      • FPGA
      • Humor
      • Image Processing
      • Kalman Filter
      • Machine Learning
        • Caffe
        • Hidden Markov Models
        • ML Summarized
        • Neural Networks
        • TensorFlow
      • Mapping
      • MATLAB
      • Robotik
      • Rust
      • Signal Processing
      • Tutorial
      • Version Control
    • Neueste Beiträge

      • Summarized: The E-Dimension — Why Machine Learning Doesn’t Work Well for Some Problems?
      • Use your conda environment in Jupyter Notebooks
      • Building OpenCV for Anaconda Python 3
      • Using TensorFlow’s Supervisor with TensorBoard summary groups
      • Getting an image into and out of TensorFlow
    • Kategorien

      .NET Allgemein Android ASP.NET Caffe Core Data Science DNX Embedded FPGA Hidden Markov Models Humor Image Processing Kalman Filter Machine Learning Mapping MATLAB ML Summarized Neural Networks Robotik Rust Signal Processing TensorFlow Tutorial Version Control
    • Tags

      .NET Accelerometer Anaconda Bitmap Bug Canvas CLR docker FPGA FRDM-KL25Z FRDM-KL26Z Freescale git Gyroscope Integration Drift Intent J-Link Linear Programming Linux Magnetometer Matlab Mono Naismith OpenCV Open Intents OpenSDA Optimization Pipistrello Player/Stage PWM Python Sensor Fusion Simulink Spartan 6 svn tensorflow Tilt Compensation TRIAD ubuntu Windows Xilinx Xilinx SDK ZedBoard ZYBO Zynq
    • Letzte Kommetare

      • Lecke Mio bei Frequency-variable PWM generator in Simulink
      • Vaibhav bei Use your conda environment in Jupyter Notebooks
      • newbee bei Frequency-variable PWM generator in Simulink
      • Markus bei Using TensorFlow’s Supervisor with TensorBoard summary groups
      • Toke bei Using TensorFlow’s Supervisor with TensorBoard summary groups
    • Blog durchsuchen

    • August 2017
      M D M D F S S
      « Jan   Mrz »
       123456
      78910111213
      14151617181920
      21222324252627
      28293031  
    • Self

      • Find me on GitHub
      • Google+
      • Me on Stack­Ex­change
      • Ye olde blog
    • Meta

      • Anmelden
      • Beitrags-Feed (RSS)
      • Kommentare als RSS
      • WordPress.org
    (Generiert in 0,691 Sekunden)

    Zurück nach oben.