I created OpenCV matrix:
CvMat * src = cvCreateMat(1, 2, CV_32FC2);
Then I want to set up element row=0, col=1, channel=1
According to the example in description of documentation for CvMat
I tried to set element with the following code:
CV_MAT_ELEM(*src, float, 0, 1 * 2 + 1) = 123;
But assert is fired.
And the reason is obvious:
We have following defintions in OpenCV sources:
#define CV_MAT_ELEM_PTR_FAST( mat, row, col, pix_size ) \
(assert( (unsigned)(row) < (unsigned)(mat).rows && \
(unsigned)(col) < (unsigned)(mat).cols ), \
(mat).data.ptr + (size_t)(mat).step*(row) + (pix_size)*(col))
#define CV_MAT_ELEM( mat, elemtype, row, col ) \
(*(elemtype*)CV_MAT_ELEM_PTR_FAST( mat, row, col, sizeof(elemtype)))
In my case mat.cols == 2 and col == 1 * 2 + 1 == 3.
What is wrong: documentation or assert in sources of OpenCV?
How to manage this?
How can I set up element of multichannel matrix?
Thanks.
P.S. To OpenCV developers if anyone here.
When I press “you can create one now” to create new account to report a bug from the page http://opencv.willowgarage.com/wiki/Welcome?action=login, I obtain the error “Unknown action newaccount.”
UPDATE:
I use OpenCV 2.1.
I have worked around usage of
CV_MAT_ELEM: