How do I access Opencv-3.0.0's expectation maximization algorithm through Python

asked 2015-08-12 09:06:36 -0500

desri gravatar image

Hi,

I am using Opencv-3.0.0 through Python 2.7.x on Ubuntu 14.04 LTS. I wanted to use the expectation maximization algorithm of Opencv. In Opencv-2.4.x the expectation maximization algorithm used to be accessed as cv2.EM. However, that doesn't exist anymore. I looked into cv2.ml, but did not find the EM class there.

Could anyone please help me out in that? The transition from Opencv-2.4.x to Opencv-3.0.0 is pretty arcane to me.

edit retag flag offensive close merge delete

Comments

1

really ?

import cv2
import numpy as np

data = np.ones((10,10), np.float32)

em = cv2.ml.EM_create()
em.setClustersNumber(5)
em.trainEM(data)
covs = em.getCovs() # this was fixed only 2 weeks ago, so you might need an update
print(covs)

also try a :

>>> help(cv2.ml.EM_create())
berak gravatar imageberak ( 2015-08-12 09:18:24 -0500 )edit

cv2.ml.EM_create() doesn't exist in my Python API. Does that mean I need to download an updated source and reinstall all over again? Please confirm.

desri gravatar imagedesri ( 2015-08-12 09:21:58 -0500 )edit
1

ohhh, most probably, - yes, and please, from github src.

(there was an early time, when none of the ml classes were actually wrapped into python. (in that case, a help(cv2.ml) will only give you a list of constants) when did you download it ?)

berak gravatar imageberak ( 2015-08-12 09:26:00 -0500 )edit

Yes, that's what I have. I only get a list of constants. Should clone Opencv-3.0.0 beta or alpha version for this? Thanks for your help in advance.

desri gravatar imagedesri ( 2015-08-12 09:35:28 -0500 )edit
1

just git clone (or better git pull, if you already have a local git repo) from here . also, future updates will be pretty easy using git pull upstream master

berak gravatar imageberak ( 2015-08-12 09:52:00 -0500 )edit