I am trying to figure out how to use OpenCV's new c ++ interface.
For elements of multi-channel matrix, for example:
matte (size (3, 3), cv_32 fc 2); For (int i = 0; i
What is the easiest way to do this? Some cvSet2D like the old interface - What is the most effective way? Similar to using direct pointers in the old interface.
Thanks
typed fip elem_ {float F1; Float F2; } Elem; Elem data [9] = {0.0f}; Cvmat mat = cvmt (3, 3, cv_32 fc2, data); Float F1 = CV_AMEEDMEM (Matt, AMM, Row, Call). F1; Float F2 = CV_AMEEDMEM (Matt, AMM, Row, Call). F2; CV_MAT_ELEM (mat, AMM, line, cola). F1 = 1212.0f; CV_MAT_ELEM (mat, AMM, line, cola). F2 = 326.0f;
Update: OpenCV 2.0 for
Select a type to represent 1 element
Mat (or CvMat) has 3 dimensions: row, call, channel.
We can reach an element (or pixels) in the matrix
CV_32FC2
means element 2 with 32 channels Bit floating point value.
Elem is an acceptable representation in the code given above CV_32FC2
.
You can use other representations of your choice. For example:
typedef struct elem_ {float val [2]; } Elem; Typedef struct elem_ {float x; Float y; } Elem;
OpenCV2.0 adds some new types of elements to the element in the matrix, such as:
template & lt; Typename _Tp, int cn & gt; Class CV_EXPORTS Vec // cxcore.hpp (208)
so we can call Vec & lt; Float, 2 & gt; You can use
to represent CV_32FC2
, or use:
typedef Vec & lt; Float, 2 & gt; Vec2f; // cxcore.hpp (254)
To find more types, see the source code that can represent your element.
Here we use the Vec2f
element 2
The easiest and most effective way to use the element in mat is Mat :: at .
There are 4 overloads in:
templates & lt; Typename _Tp & gt; _Tp & amp; At (int y, int x); // cxcore.hpp (868) template & lt; Typename _Tp & gt; Const _Tp & amp; At (int y, int x) const; // cxcore.hpp (870) template & lt; Typename _Tp & gt; _Tp & amp; At (point pt); // cxcore.hpp (869) template & lt; Typename _Tp & gt; Const _Tp & amp; At (point pt) const; // cxcore.hpp (871) // cxmat.hpp (454-468) / we can use the element like this: mat m (size (3,3), cv_32 fc 2); Vec2f & amp; Elem = m.at & lt; Vec2f & gt; (Line, color); // or M.AT & lt; Vec2f & gt; (Point (call, line)); AMM [0] = 1212.0F; AMM [1] = 326.0F; Float c1 = m.at & lt; Vec2f & gt; (Line, color) [0]; // or M.AT & lt; Vec2f & gt; (Point (call, line)); Float c2 = m.at & lt; Vec2f & gt; (Line, color) [1]; M.T. & Lt; Vec2f & gt; (Line, color) [0] = 1986.0 f; M.A.T. & Lt; Vec2f & gt; (Line, color) [1] = 326.0F;
Conversation with old interface
Mat gives two conversion actions:
// headers Converts to CVMAT; No data has been copied // cxcore.hpp (829) operator cvmat () const; Converts the header to IplImage defined in // cxmat.hpp //; No data copied operator IplImage () const; // We can negotiate a mott object with the old interface: Mat new_matrix (...); CvMat old_matrix = new_matrix; // Be careful about your lifetime CV_MAT_ELEM (old_mat, elem, row, col) .f1 = 1212.0f;
No comments:
Post a Comment