module 'cv2.cv2' has no attribute 'legacy'
时间: 2023-08-05 15:06:54 浏览: 475
回答: 如果你在使用OpenCV时遇到了"module 'cv2.cv2' has no attribute 'legacy'"的错误,这可能是因为你的OpenCV版本过高。建议你回退到低于4.5的版本,例如使用4.4版本。在回退版本后,你可以尝试删除代码中的"legacy"部分,然后重新执行代码。这样应该可以解决这个问题。\[1\]
#### 引用[.reference_title]
- *1* [在目标跟踪时出现AttributeError: module ‘cv2‘ has no attribute ‘legacy‘的问题解决方法](https://blog.csdn.net/KD_NO_1/article/details/124596809)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
相关问题
AttributeError: module 'cv2.cv2' has no attribute 'legacy'
AttributeError: module 'cv2.cv2' has no attribute 'legacy'是由于OpenCV库的版本问题导致的错误。在较新的OpenCV版本中,'cv2.cv2'模块不再包含'legacy'属性。
解决这个问题的方法是更新OpenCV库或者修改代码中的引用。以下是两种解决方法:
1. 更新OpenCV库:可以通过升级OpenCV库到最新版本来解决此问题。可以使用pip命令来更新OpenCV库,例如:
```
pip install --upgrade opencv-python
```
2. 修改代码引用:如果你无法或不想升级OpenCV库,可以修改代码中对'cv2.cv2.legacy'的引用。将其改为'cv2'即可,例如:
```
import cv2
# 使用cv2模块而不是cv2.cv2.legacy
```
希望以上解决方法能够帮助到你!
AttributeError: module 'cv2.legacy' has no attribute 'MultiTracker_create'
`AttributeError: module 'cv2.legacy' has no attribute 'MultiTracker_create'` 这是一个Python中常见的错误,通常在使用OpenCV(cv2库)时出现。这个错误意味着你在尝试访问`cv2.legacy`模块中的`MultiTracker_create`属性或方法,但在当前版本的OpenCV中,这个`MultiTracker_create`已经被移除或者不在`cv2.legacy`模块中了。
OpenCV 4.x以后,`MultiTracker`已被合并到`cv2.TrackerMultiTracker`中,可能需要更新你的代码来适应新版本。如果你还在使用旧版本的OpenCV或者`legacy`模块,那么应该将代码中的`cv2.legacy.MultiTracker_create`替换为`cv2.MultiTracker()`或者直接使用`cv2.TrackerMultiTracker()`创建对象。
相关问题:
1. OpenCV 4.x后`MultiTracker_create`被移到哪里了?
2. 如何在新版本的OpenCV中正确初始化`MultiTracker`?
3. 我如何检查我的OpenCV版本以及是否包含了`cv2.legacy`?
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![so](https://img-home.csdnimg.cn/images/20210720083646.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)