As the title suggest, what is the best / most efficient way to convert form an OpenCV Mat CV_8UC3 to an NDArray in C++? This is my current implementation, but I feel it can be improved. Thanks for the help
NDArray TruefaceFRVT11::mtxToNDArr(const cv::Mat& frame) {
NDArray retArr(Shape(1, frame.channels(), frame.rows, frame.cols), m_globalCtx, false);
std::vector<float> data;
for (int c = 0; c < frame.channels(); ++c) {
for (int i = 0; i < frame.rows; ++i) {
for (int j = 0; j < frame.cols; ++j) {
data.emplace_back(static_cast<float>(frame.data[(i * frame.rows + j) * 3 + c]));
}
}
}
retArr.SyncCopyFromCPU(data.data(), 1 * frame.channels() * frame.rows * frame.cols);
// NDArray::WaitAll();
return retArr;
}