Post date: Mar 27, 2016 3:9:56 PM
Man .......
Okay the matrices used in OpenCV are cv::Mat. cv::Mat elements are accessed by using the .at method. So say a cv::Mat src is a matrix for double values. To access an element, the method is to use src.at<double>(i, j) where i,j are integer or size_t indices of the matrix. It is widely known that a faster means of access is via pointers. The following illustrates how this can be done using by transferring from cv::Mat src to cv::Mat ret.
uchar* srcptr = src.data;
uchar* retptr = ret.data;
for (int j = 0; j < src.rows; j++)
{
for (int i = 0; i < src.cols; i++)
{
*((double *)(retptr + i*ds + j*src.step)) = *((double *)(srcptr + i*ds + j*src.step));
}
}
Note that OpenCV matrices are rowmajor which means that the rows are stored contiguously in memory.