cv2.CreateMat in python

asked 2014-03-16 14:15:32 -0600

La Rosa gravatar image

updated 2014-03-16 14:19:39 -0600

berak gravatar image

Hi guys

i'm trying to use the cv.CreateMat in a python code but when i run it i got this error:

AttributeError: 'module' object has no attribute 'createMat'!!!!!

Please can anybody help me! thank you

edit retag flag offensive close merge delete

Comments

in cv2, everything's a numpy array. ( it does not need any Create* functions anymore. if you ask me - for the better! )

berak gravatar imageberak ( 2014-03-16 14:37:07 -0600 )edit

Sorry but i didn't understand you (i'm new in opencv and python) how can i create matrix?!

La Rosa gravatar imageLa Rosa ( 2014-03-16 15:15:46 -0600 )edit

>>> import numpy as np

>>> a = numpy.array((3,4,3), np.uint8) # (that is: height, width,numchannels)

(i'm going to try a more detailled answer tomorrow ... )

berak gravatar imageberak ( 2014-03-16 15:28:29 -0600 )edit

okay thank you so much (please if you can help me in cv.stereoCalibration, how to calculate R,T,F,E?i'll be thankful) waiting for your explanation tomorrow.

La Rosa gravatar imageLa Rosa ( 2014-03-16 15:32:03 -0600 )edit

use cv2.stereoCalibrate - it will just return all of them.

in general, stick to the cv2 api. the old cv one won't be included in the next release

berak gravatar imageberak ( 2014-03-17 09:11:24 -0600 )edit

ok,i did it and it works now thank you one more question please what will the next step be in order to be able to calculate the distance between the tow webcams and the object in front of them?

La Rosa gravatar imageLa Rosa ( 2014-03-17 09:41:42 -0600 )edit

have a look at StereoBM or StereoSGBM to create a disparity map, which is (inverse)proportional to the distance. maybe this sample is helpful

berak gravatar imageberak ( 2014-03-17 09:46:24 -0600 )edit

okay working on it thank you

La Rosa gravatar imageLa Rosa ( 2014-03-17 09:53:20 -0600 )edit

hi again, i tried to run the cv2.stereoRectify but i got this error:

Traceback (most recent call last): File "C:\opencv246\samples\python2\stereocalib.py", line 132, in <module> cv.stereoRectify(camera_matrixL, cameraR_matrix, dist_coefsL, dist_coefsR,(384,288), R, T, RL, Rr, PL, PR) error: ......\src\opencv\modules\imgproc\src\undistort.cpp:292: error: (-215) CV_IS_MAT(_distCoeffs) && (_distCoeffs->rows == 1 || _distCoeffs->cols == 1) && (_distCoeffs->rows_distCoeffs->cols == 4 || _distCoeffs->rows_distCoeffs->cols == 5 || _distCoeffs->rows*_distCoeffs->cols == 8) why?!

La Rosa gravatar imageLa Rosa ( 2014-03-17 10:21:41 -0600 )edit

please use: cv2.stereoRectify(cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2, image, ...

imho, you used the cv one, and mixed up the arguments

python has a nice help function, btw:

>>> import cv2

>>> help(cv2.stereoRectify)

Help on built-in function stereoRectify in module cv2:

stereoRectify(...) stereoRectify(cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2, imageS ize, R, T[, R1[, R2[, P1[, P2[, Q[, flags[, alpha[, newImageSize]]]]]]]]) -> R1, R2, P1, P2, Q, validPixROI1, validPixROI2

berak gravatar imageberak ( 2014-03-17 10:36:21 -0600 )edit