Reputation: 711
How do you write a vector in OpenCV? that contains 3 values like this v = [p1,p2,p3]
? This is what I tried:
int dim [1] = {3};
Mat v(1,dim,CV_32F, Scalar(p1,p2,p3));
But when I do debug in Qt, I see in the local and expression window that the vector v
indeed has 1 column and 3 rows but has also 2 dim. I was wondering if this is due to the Mat
type in the declaration.
With which type could I replace it to get just a simple vector of 3 values?
Upvotes: 4
Views: 24866
Reputation: 41775
Which type could I use to get just a simple vector of 3 values? I want to do some operation on this vector like use the norm and change it's elements.
You can use cv::Vec type.
Assuming you're working on double
values (the same applies for other types) you can:
// Create a vector
Vec3d v;
// Assign values / Change elements
v[0] = 1.1;
v[1] = 2.2;
v[2] = 3.3;
// Or initialize in the constructor directly
Vec3d u(1.1, 2.2, 3.3);
// Read values
double d0 = v[0];
// Compute the norm, using cv::norm
double norm_L2 = norm(v, NORM_L2); // or norm(v);
double norm_L1 = norm(v, NORM_L1);
For:
double
type use Vec3d
float
type use Vec3f
int
type use Vec3i
short
type use Vec3s
ushort
type use Vec3w
uchar
type use Vec3b
Upvotes: 7