0

I'm trying to upgrade python code that was programed for OpenCV 2.4 to be used with OpenCV 3.3. I found a problem with the flags of the function cv2.calcCovarMatrix, as I show next.

The code is this one:

# Compute 3x3 covariance matrix
covar, mean = cv2.calcCovarMatrix(total_matrix, cv2.cv.CV_COVAR_NORMAL | cv2.cv.CV_COVAR_SCALE | cv2.cv.CV_COVAR_ROWS)

The error that raises is this one:

covar, mean = cv2.calcCovarMatrix(total_matrix, cv2.cv.CV_COVAR_NORMAL | cv2.cv.CV_COVAR_SCALE | cv2.cv.CV_COVAR_ROWS) 
AttributeError: 'module' object has no attribute 'cv'

The python version is 2.7

Does anyone know a way of upgrade this particular piece of code? I think the problem is that the flags now have a different name, but I have not been able to find it.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
Pharaun
  • 61
  • 6

1 Answers1

0

From OpenCV 2.X OpenCV 3.0 a few things changed.

Specifically:

cv2.cv doesn't exists in OpenCV 3.0. Use simply cv2.

So you need to change to:

covar, mean = cv2.calcCovarMatrix(total_matrix, cv2.CV_COVAR_NORMAL | cv2.CV_COVAR_SCALE | cv2.CV_COVAR_ROWS)
GPPK
  • 6,546
  • 4
  • 32
  • 57
  • Thanks for your answer. I tryed that before asking here, maybe I shoud have added the information in the post. If I execute the function like that the error that raises is: AttributeError: 'module' object has no attribute 'CV_COVAR_NORMAL' Since I need the eigenvalues and the eigenvectors I tryed also with PCACompute, but it discards de eigenvalues. – Pharaun Feb 15 '18 at 11:01