Use CV2 on Headless Ubuntu

Method 1: use imgcat instead of cv2.imshow

Method 2: use cv2 or PIL over SSH X11

Compilation

OpenCV Build on Linux

https://wiki.aleen42.com/qa/opencvonlinux.html

https://www.marearts.com/0-OpenCV-Build-Ubuntu-20-04-OpenCV-4-5-2-CUDA-11-2-4c876d664e84442e82ebec13c23586b3

OpenCV with GPU for Python on Windows

https://www.youtube.com/watch?v=HsuKxjQhFU0&t=515s

https://docs.opencv.org/master/db/d05/tutorial_config_reference.html

  1. install NVIDIA CUDA, OpenCV code, CMake as for C++

  2. install Anaconda and set PATH correctly

  3. download OpenCV code,(opencv, opencv_contrib)

  4. CMake Configure:

    1. select the OpenCV source code and target build path, click Configure select os platform, start to build

      1. if 网络不佳,自行查看下载失败的包,去github下载好,修改相应.cmake 文件里的地址为file:///...。或者把raw.githubusersourcecontent 改为镜像地址,参考:https://www.codenong.com/cs107007432/
    2. upgrade NumPy version to newest

    3. check all python paths including the NumPy path,configure again

      Untitled

    4. uncheck OPENCV_GENERATE_SETUPVARS

    5. check these:

      1. WHITH_CUDA
      2. OPENCV_DNN_CUDA
      3. ENABLE_FAST_MATH
      4. BUILD_opencv_world
    6. OPENCV_EXTRA_MODULES_PATH = path/to/opencv_contrib/modules

    7. configure again

    8. check CUDA_FAST_MATH

    9. choose arch version ( https://en.wikipedia.org/wiki/CUDA, torch.cuda.get_arch_list()), and release config, click ‘Configure’ again

    10. click ‘Generate'

    11. install in prompt

      cmake --build "D:\mnvai-alg\cv2_with_gpu\build_win_py" --target INSTALL --config Release
      
  5. Verify:

    import cv2
    from cv2 import cuda
    
    cuda.printCudaDeviceInfo(0)