aisingapore / PeekingDuck

A modular framework built to simplify Computer Vision inference workloads.
Apache License 2.0
163 stars 39 forks source link

AttributeError: module 'cv2' has no attribute 'legacy_TrackerMOSSE' #729

Closed ZhaoPeiduo closed 1 year ago

ZhaoPeiduo commented 1 year ago

image

Hi I encountered this error when trying to import tracking from dabble.

Seems that for opencv with verison >= 4.5.2 (as stated in the requirements), TrackerMOOSE is moved under legacy namespace, and this call no longer works.

Is it possible to update the requirements / fix the namespace?

Thanks.

liyier90 commented 1 year ago

Hi @ZhaoPeiduo, I have briefly tested this on my machine with both opencv-contrib-python==4.5.2.54 (min version) and opencv-contrib-python==4.6.0.66 (latest version) but was unable to reproduce the error you have observed.

May I know the following information about your system to try and reproduce the error?

OS: 
Python version:
PeekingDuck version:
opencv-contrib-python version:
ZhaoPeiduo commented 1 year ago

Hi @liyier90 , thank you for your quick reply.

The details required are as follows: OS: Windows 10 Python Version: 3.8.16 PeekingDuck version: 1.3.0.post1 opencv-contrib-python version: 4.6.0.66

I was running my code on Google Colab by the way.

Screenshot (attempted to uninstall opencv-python as well) image'

Thank you for your kind support!

liyier90 commented 1 year ago

May I know what is the output of the following command

!pip freeze | grep opencv

Apparently the Colab instance install 3 variants of OpenCV, opencv-python, opencv-contrib-python, and opencv-python-headless. There have been cases where having multiple variants of OpenCV install can cause issues https://github.com/opencv/opencv/issues/15723

If you have multiple variants of OpenCV installed in your Colab notebook, could you try to uninstall all opencv packages and then reinstall only opencv-contrib-python? Also, try to restart the runtime with "Runtime > Restart runtime" after reinstalling.

Here is a sample Colab notebook with the uninstall and reinstall steps https://colab.research.google.com/drive/1lai3PsqeA5PUt0xfFZyF4sKJisPTlZnv?usp=sharing

ZhaoPeiduo commented 1 year ago

Thank you for your response! Yes as you have pointed out, there are three variants of opencv and I did not uninstall opencv-python-headless. I followed your sample notebook and the issue has been resolved :)