Reputation: 174
I want to create a 1-D array of exactly 100 values and at each index store the index of another array. If I am to use std::vector<int16_t> someVector
, how do I ensure that someVector
has only 100 values and maybe add the first value at location 48 like someVector[48] = 29322
, and so on.
As an alternative I tried creating a 1-D mat of Mat someArray(1,100,CV_16UC1,Scalar(9999))
. Now when I try to retrieve the value at index 48, by using int retrievedValue = someArray.row(0).col(48)
, it says cannot convert from Mat
to int
.
I realize I'm doing something crazy for something very simple, but please help.
Upvotes: 0
Views: 620
Reputation: 4448
When you initialize vector you can set its size:
std::vector<int16_t> someVector(100);
This way it will be created with as array of 100 elements. But don't forget that size of vector may be changed later.
As for Mat, operators like row() or col() give you sub-matrix of initial matrix. So the code you created will return you a 1x1 matrix, not a short. If you want to access an element in matrix it should be:
int retrievedValue = someArray.at<ushort>(0,48);
Upvotes: 1