0

Hopefully someone can point me in the right direction here.

I'm using the latest release of Anaconda (Python 2.7). I would like to use it with OpenCV with the tracking features. I've tried various versions of the cv2.pyd file including 3.0, 3.1, 3.2, 3.3 and 3.4. However, the examples I've found use one of the following commands which are not found in the module.

tracker = cv2.Tracker_create(tracker_type)

or

tracker = cv2.TrackerKCF_create()

The usage of either of these depends which OpenCV version is being used. However, neither of them work, both with the following error.

'module' object has no attribute 'Tracker_create / or TrackerKCF_create'

All of the other features in OpenCV seem to work fine.

Is the cv2.pyd file I'm extracting from the Windows OpenCV install limited to certain features?

If I use the following in the Anaconda Prompt

conda install -c menpo opencv3

it installs the tracking features I need. However, it installs v3.1 of OpenCV which is known to have bugs with the tracking features. Ideally I wan't v3.4 of OpenCV.

Any help would be appreciated.

maffoo
  • 107
  • 1
  • 8
  • I'm guessing you have a reason as to why you're using `menpo opencv3`? If there's no significant reason, I'd suggest using `conda install -c conda-forge opencv` or `pip install python-opencv` instead? – nitred May 12 '18 at 11:26
  • There's sort of a reason - I don't know what I'm doing :) I've done "conda install -c conda-forge opencv" which does give me the tracking features. However, it's OpenCV 3.2. – maffoo May 12 '18 at 13:14
  • 1
    If you look at the [conda-forge/opencv](https://anaconda.org/conda-forge/opencv/files) page, you'll see that it's supposed to be 3.4. This most likely means that your anaconda environment is a mess where some other package will break if you install opencv 3.4. I will post an answer in a bit, in the meantime please read on how to [manage anaconda environments](https://conda.io/docs/user-guide/tasks/manage-environments.html) very carefully. – nitred May 12 '18 at 13:22
  • Oops, my bad it seems like `conda-forge opencv` v3.4 is not supported for `python 2.7` and only v3.2 is supported for `python 2.7`. Is there any specific reason you chose `python 2.7`? If there isn't then I'd suggest moving to `python 3.6`. – nitred May 12 '18 at 13:38
  • Hello, I chose Python 2.7 as when I previously looked in to OpenCV it didn't support Python 3 and I wrongly assumed that was still the case. – maffoo May 12 '18 at 21:14

1 Answers1

1

If you're using Anaconda then it would be wise to use it's environment management tools. Create an environment.yml file with the following contents:

environment.yml using conda-forge/opencv & python 3.6

name: opencv-env      # any name for the environment
channels:
- conda-forge
dependencies:         # everything under this, installed by conda
- python=3.6
- opencv=3.4
- pip:                # everything under this, installed by pip
  - future

environment.yml using pip/opencv-python & python 3.6

name: opencv-env      # any name for the environment
channels:
- defaults
dependencies:         # everything under this, installed by conda
- python=3.6
- pip:                # everything under this, installed by pip
  - future
  - opencv-python>=3.4

How to install the environment?

conda create --force -f environment.yml

How to activate the environment?

source activate opencv-env

Once you've activated the environment, you can check the version of opencv.

nitred
  • 5,309
  • 3
  • 25
  • 29