Traceback (most recent call last): File "detect_onnx.py", line 112, in <module> outs=post_process_opencv(outs,320,320,480,640,0.4,0.5) File "detect_onnx.py", line 60, in post_process_opencv ids = cv2.dnn.NMSBoxes(areas,conf,thred_cond,thred_nms) TypeError: Can't convert vector element for 'bboxes', index=0报错 # 转换为列表格式 areas = areas.tolist() # 应用非极大值抑制算法获取IDs ids = cv2.dnn.NMSBoxes(areas,conf,thred_cond,thred_nms) # 返回包含筛选后的区域、置信度和类别ID的数据列表 return [np.array(areas)[ids],np.array(conf)[ids],cls_id[ids]]
时间: 2024-01-28 17:04:43 浏览: 176
这个错误通常是由于 `areas` 向量中的元素不是整数或浮点数类型,导致不能被转换为 `cv::Rect` 类型。建议将 `areas` 向量中的元素转换为整数或浮点数类型,可以使用 `astype()` 方法来实现这一点。例如,可以像下面这样修改代码:
```
# 将 areas 转换为列表格式,并将元素转换为整数类型
areas = areas.astype(int).tolist()
# 应用非极大值抑制算法获取IDs
ids = cv2.dnn.NMSBoxes(areas, conf, thred_cond, thred_nms)
# 返回包含筛选后的区域、置信度和类别ID的数据列表
return [np.array(areas)[ids], np.array(conf)[ids], cls_id[ids]]
```
这样就可以避免这个错误了。如果还有问题,请检查代码中的其他部分是否存在错误。
相关问题
Traceback (most recent call last): File "paddle\fluid\ir.py", line 24, in <module> File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module File "paddle\fluid\proto\pass_desc_pb2.py", line 16, in <module> ModuleNotFoundError: No module named 'framework_pb2' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "main.py", line 1, in <module> File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module File "index.py", line 7, in <module> File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module File "leis\jietuwj.py", line 8, in <module> File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module File "paddleocr\__init__.py", line 14, in <module> File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module File "paddleocr\paddleocr.py", line 21, in <module> File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module File "paddle\__init__.py", line 62, in <module> File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module File "paddle\distributed\__init__.py", line 15, in <module> File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module File "paddle\distributed\spawn.py", line 24, in <module> File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module File "paddle\distributed\utils\launch_utils.py", line 27, in <module> File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module File "paddle\distributed\fleet\__init__.py", line 31, in <module> File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module File "paddle\distributed\fleet\fleet.py", line 33, in <module> File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module File "paddle\fluid\ir.py", line 28, in <module> File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module File "paddle\fluid\proto\pass_desc_pb2.py", line 16, in <module> ModuleNotFoundError: No module named 'framework_pb2' [15508] Failed to execute script 'main' due to unhandled exception!
这是一个 Python 的错误,看起来是在使用 PaddlePaddle 框架时出现了问题。可能是因为缺少某个依赖项或环境配置不正确导致的。你可以尝试更新 PaddlePaddle 和相关的依赖项,或者检查你的环境配置是否正确。如果问题仍然存在,请查看错误信息中的文件和行号,以便更好地定位和解决问题。
Traceback (most recent call last): File "D:\host_system\FlexflowCCD\paddle_main\paddleocr1.py", line 7, in <module> from paddleocr import PaddleOCR File "D:\host_system\FlexflowCCD\paddle_main\paddleocr.py", line 29, in <module> from PaddleOCRlib.tools.infer import predict_system File "D:\host_system\FlexflowCCD\paddle_main\PaddleOCRlib\__init__.py", line 15, in <module> from .paddleocr import * File "D:\host_system\FlexflowCCD\paddle_main\PaddleOCRlib\paddleocr.py", line 29, in <module> from tools.infer import predict_system File "D:\host_system\FlexflowCCD\paddle_main\PaddleOCRlib\tools\infer\predict_system.py", line 31, in <module> import tools.infer.predict_rec as predict_rec File "D:\host_system\FlexflowCCD\paddle_main\PaddleOCRlib\tools\infer\predict_rec.py", line 31, in <module> from ppocr.postprocess import build_post_process File "D:\host_system\FlexflowCCD\paddle_main\ppocr\postprocess\__init__.py", line 30, in <module> from .pg_postprocess import PGPostProcess File "D:\host_system\FlexflowCCD\paddle_main\ppocr\postprocess\pg_postprocess.py", line 25, in <module> from ppocr.utils.e2e_utils.pgnet_pp_utils import PGNet_PostProcess File "D:\host_system\FlexflowCCD\paddle_main\ppocr\utils\e2e_utils\pgnet_pp_utils.py", line 25, in <module> from extract_textpoint_slow import * File "D:\host_system\FlexflowCCD\paddle_main\ppocr\utils\e2e_utils\extract_textpoint_slow.py", line 24, in <module> from skimage.morphology._skeletonize import thin File "D:\Anaconda3\envs\py_opencv\lib\site-packages\skimage\__init__.py", line 122, in <module> from ._shared import geometry File "geometry.pyx", line 1, in init skimage._shared.geometry ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject Process finished with exit code 1
这个错误是由于numpy版本不兼容导致的。你可以尝试更新numpy版本来解决这个问题。可以使用以下命令来更新numpy:
```
pip install --upgrade numpy
```
如果你使用的是Anaconda环境,可以使用以下命令来更新numpy:
```
conda update numpy
```
更新完numpy之后,再次运行代码应该就不会出现这个错误了。希望这能帮到你!如果还有其他问题,请随时提问。
阅读全文