报错如下

Traceback (most recent call last):
  File "D:\Users\Admin\Anaconda3\envs\tf1\lib\site-packages\IPython\core\interactiveshell.py", line 3437, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-a72356cb5e0c>", line 1, in <module>
    runfile('D:/WorkFolders/ProjectFolder/20210705_dsp_advertisement/online/hmcs-violation-detection/models/detect_main.py', wdir='D:/WorkFolders/ProjectFolder/20210705_dsp_advertisement/online/hmcs-violation-detection/models')
  File "D:\Program Files\JetBrains\PyCharm 2019.2.1\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "D:\Program Files\JetBrains\PyCharm 2019.2.1\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  ......
  rgb_small_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
cv2.error: OpenCV(4.5.1) ..\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

解决办法

将cv2.imread() 的问题,将其替换为 cv2.imdecode()

import numpy as np
import cv2
filePath = 'data/周杰伦/周杰伦1.jpg'
frame=cv2.imdecode(np.fromfile(filePath,dtype=np.uint8), 1)  
posted on 2021-07-09 17:30  jaysonteng  阅读(2480)  评论(0编辑  收藏  举报