0

I am converting an old piece of code written in c/cpp into python. It uses cvCreateMat function. From this link I believe that cvCreateMat function is not supported in OpenCV2. I dont know how to do it using OpenCV2/numpy. OR all I need is the equivalent of the following line in python.

cv::Mat a = cvCreateMat(3*numberOfMatrices, 6,CV_64FC1);

5
  • 2
    just create a numpy array the shape and dtype you need Commented Feb 15, 2019 at 11:00
  • how about cv.CreateImage Commented Feb 15, 2019 at 11:01
  • answers.opencv.org/question/30037/cv2createmat-in-python This should help you. Commented Feb 15, 2019 at 11:01
  • @Miki I dont know what will I put in type. If numberOfMatrices is 6 then I guess the cvCreateMat will create a matrix of 18 rows 6 columns, initialized with 0. I am also not sure do I need np.array or np.matrix. Commented Feb 15, 2019 at 11:11
  • @Spinkoo I want the equivalent because the later functions utilize this data. I believe the cvCreateMat is replaced by numpy. Commented Feb 15, 2019 at 11:13

1 Answer 1

1

I think this should do

// the third 3 is so it has 3 dimensions which i suppose what you need
size = 3*numberOfMatrices, 6
img = np.zeros(size, dtype=np.float64)

this is the correct format to create

Sign up to request clarification or add additional context in comments.

5 Comments

Yes I think something similar but I found this link which gives a bit different format for it.
Will it not be `img = np.zeros((3*numberOfMatrices, 6), dtype=np.float64)
It works to create matrix of 0's but I am not sure if it is eqivalent of cvCreateMat? Do you know? If yes i will accept it as answer.
Yes it its the equivalent to do it in python you can call it with np.ones too if yo want
Hi Spinkoo please remove the last 3 from size = 3*numberOfMatrices, 6, 3. It should be size = 3*numberOfMatrices, 6

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.