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

yes it is!

La Rosa gravatar imageLa Rosa ( 2014-03-17 10:36:50 -0600 )edit

i am using cv2 but just (import cv2 as cv)

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

and how about the R1,R2,P1,P2,Q?

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

"and how about the R1,R2,P1,P2,Q?" - pardon ? they'll get returned from the function. are you asking, wether you have to supply them as arguments ? - no. (well you could ofc, but that's optional)

berak gravatar imageberak ( 2014-03-17 10:49:16 -0600 )edit

ok,but still getting this error: ValueError: too many values to unpack in this line RL, Rr, PL, PR, Q = cv.stereoRectify(camera_matrixL,dist_coefsL, cameraR_matrix, dist_coefsR,(384,288), R, T) (and i'm so sorry if i am bothering you)

La Rosa gravatar imageLa Rosa ( 2014-03-17 11:05:50 -0600 )edit

"and i'm so sorry if i am bothering you" - no prob, nice to see you making progress.

you forgot the roi's now, try :

RL, Rr, PL, PR, Q, validRoiL, validRoiR = cv.stereoRectify(....

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

okay i really appreciate,now it works,thank you now moving to the next step thank you again

La Rosa gravatar imageLa Rosa ( 2014-03-17 11:16:39 -0600 )edit

i'm getting this error: colors = cv.cvtColor(imgL, cv.COLOR_BGR2RGB) error: ......\src\opencv\modules\imgproc\src\color.cpp:3346: error: (-215) scn == 3 || scn == 4 :/ ?!!

La Rosa gravatar imageLa Rosa ( 2014-03-17 12:30:09 -0600 )edit