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);

Dr. Mian
  • 3,334
  • 10
  • 45
  • 69
  • 2
    just create a numpy array the shape and dtype you need – Miki Feb 15 '19 at 11:00
  • how about cv.CreateImage – Spinkoo Feb 15 '19 at 11:01
  • http://answers.opencv.org/question/30037/cv2createmat-in-python/ This should help you. – keineahnung2345 Feb 15 '19 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`. – Dr. Mian Feb 15 '19 at 11:11
  • @Spinkoo I want the equivalent because the later functions utilize this data. I believe the cvCreateMat is replaced by numpy. – Dr. Mian Feb 15 '19 at 11:13

1 Answers1

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

Spinkoo
  • 2,080
  • 1
  • 7
  • 23
  • Yes I think something similar but I found this [link](https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.zeros.html) which gives a bit different format for it. – Dr. Mian Feb 15 '19 at 11:34
  • Will it not be `img = np.zeros((3*numberOfMatrices, 6), dtype=np.float64) – Dr. Mian Feb 15 '19 at 11:38
  • 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. – Dr. Mian Feb 15 '19 at 11:58
  • Yes it its the equivalent to do it in python you can call it with np.ones too if yo want – Spinkoo Feb 15 '19 at 12:45
  • Hi Spinkoo please remove the last 3 from `size = 3*numberOfMatrices, 6, 3`. It should be `size = 3*numberOfMatrices, 6` – Dr. Mian Feb 23 '19 at 18:44