文章目录
- 问题一:**TypeError: CvBridge.imgmsg_to_cv2() missing 1 required positional argument:**
- 问题二:**DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead**![请添加图片描述](https://i-blog.csdnimg.cn/blog_migrate/1d7105dd3d7f317c983a5b550dcbe9c9.png)
- 问题三: **Failed to load image Python extension: warn(f"Failed to load image Python extension: {e}")以及 Couldn't load custom C++ op
- 总结
问题一:TypeError: CvBridge.imgmsg_to_cv2() missing 1 required positional argument:
—
问题描述:
运行video_detect.py文件时, 将ros图像文件格式转换为opencv图像格式时出现以上问题,图像并没有传入imgmsg_to_cv2()函数,通过测试, 节点已经接收到图像话题并且进入回调函数。
该问题没有解决,使用了其它方式在处理图像。
存在两个问题
问题二:DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
原因:使用了np.fromstring解二进制图像:
np_arr = np.fromstring(data.data, np.uint8)
image_np = cv2.imdecode(np_arr, cv2.IMREAD_COLOR)
改为:
np_arr = np.frombuffer(data.data, np.uint8)
image_np = cv2.imdecode(np_arr, cv2.IMREAD_COLOR)
问题三: **Failed to load image Python extension: warn(f"Failed to load image Python extension: {e}")以及 Couldn’t load custom C++ op
问题分析:
通常出现以上报错可能有两个原因供参考:
1、安装的pytorch和torchvision版本不匹配
2、使用的cuda版本不合适
解决办法:
使用以下命令查看cuda版本,我安装的cuda版本为10.0, torch为1.12.0, torchvision 为 0.13, python3.10. 查看版本对应表cuda10.0对应的pytorch版本是1.2.0, torchvision是0.4.0, 而yolov5要求torch>=1.7.0 torchvision>=0.8.1. 因此需要升级cuda版本,升级方法在以下链接,我将cuda升级到了11.3, 同时重新安装了torch1.12.1和torchvison 0.13.1 , 最终问题解决。
nvcc --version
Failed to load image Python extension: warn(f“Failed to load image Python extension: {e}")
总结
提示:这里对文章进行总结:
以上为在ros中使用yolov5订阅ros图像遇到的一些问题,简单记录一下。