OpenCV Python调用createBinaryDescriptor报AttributeError问题求助
解决
AttributeError: module 'cv2' has no attribute 'createBinaryDescriptor'问题 createBinaryDescriptor属于OpenCV的line_descriptor子模块,且该模块仅包含在opencv-contrib扩展包中,默认的opencv-python包不包含此功能。按以下步骤解决:
安装/更新opencv-contrib-python
打开终端执行:pip install --upgrade opencv-contrib-python注意:如果已安装opencv-python,需保证它和opencv-contrib-python版本完全一致,避免版本冲突导致的异常。
正确调用函数
代码中需通过line_descriptor子模块访问该函数,示例:import cv2 # 直接通过子模块调用 bd = cv2.line_descriptor.createBinaryDescriptor() # 或先导入子模块再调用 from cv2 import line_descriptor bd = line_descriptor.createBinaryDescriptor()验证版本兼容性
确认你的OpenCV版本为4.x及以上(与你参考的教程版本匹配),可通过以下代码查看:import cv2 print(cv2.__version__)
内容的提问来源于stack exchange,提问作者Yuri Soeda
相关产品推荐
相关产品推荐

