MacOS下OpenCV + Python+PyQt5多进程Bug

MacOS下OpenCV + Python+PyQt5 多进程Bug

环境

  • macOS Catalina 10.15.7
  • pyqt5
  • opencv

问题

  • 多进程情况下cv2.resize或者cv2.cvtColor引发程序崩溃
  • 使用PyQt5与opencv的冲突

可能的解决方案

  1. 安装opencv-python-headless替换opencv-python
  2. 设置 cv2.setNumThreads(0)

OpenCV will try to set the number of threads for the next parallel region. If threads == 0, OpenCV will disable threading optimizations and run all its functions sequentially. Passing threads < 0 will reset threads number to system default. This function must be called outside of parallel region.

  1. 1
    2
    import multiprocessing as mp
    mp.set_start_method('spawn')

参考

OpenCV + Python multiprocessing breaks on OSX

pytorch dataloader stucked if using opencv resize method

OpenCV 4.4.0.44 macOS Catalina - Hang/Frozen