Reputation: 106
I have a Point3f and I want to normalize it, e.g. divide with the last (z) element.
Point3f C_tmp;
I can print it out like this,
cout << "C_tmp= " << C_tmp << endl;
But, I cannot just do
C_tmp=C_tmp/C_tmp[3];
I use C++ interface. I couldn't find something helpful in the documentation. Any idea?
EDIT: Vector case:
int i;
for (i=begin; i<end; i++) {
threeD=...[i]..;
threeDVector.push_back(threeD);
twoD.x= threeD.x / threeD.z;
twoD.y= threeD.y / threeD.z;
twoDVector.push_back(twoD);
}
Upvotes: 1
Views: 5168
Reputation: 5853
Point3f
has the fields x
, y
, and z
:
Point3f threeD(2, 3, 4);
Point2f twoD(threeD.x / threeD.z, threeD.y / threeD.z);
You can also (implicitly) convert a Point3f
to a Vec3f
and do the trick your way (be away, c++ uses 0-based array):
...
Vec3f threeDVector = threeD;
threeDVector /= threeDVector[2];
Last, I think the best way to explore the functionality of such structures is simply just to read the opencv header files (in this case opencv2/core/types.hpp
)
Upvotes: 4