When I try to assign the elements in cv::Mat to a single unsigned char array one by one, the channel index does not know how to define the type and the following code does not compile with the variable k. How can I change it to assign it correctly?
/**
* @brief OpenCV图像转一位数组
* @details This is the detail description.
* @param[in] srcImg 1289*720*3大小的BGR图像,uchar类型.
* @param[out] dst 1289*720*3大小的一维数组.
* @return 返回值
*/
void convertCVToMatrix(cv::Mat &srcImg, unsigned char dst[2332800]) {
CV_Assert(srcImg.total()==2332800 && srcImg.type() == CV_8UC3);
size_t num = 0;
for (int k = 0; k< srcImg.channels(); k++) {
for (int j = 0; j < srcImg.cols; j++) {
for (int i= 0; i < srcImg.rows; i++) {
dst[num++] = srcImg.at<uchar>(i, j)[k];
}
}
}
}
thanks very much,the above one-dimensional array is a column-major storage array, but a direct copy memcpy as you have provided would require some modification