cvtColor vs. manual conversion time
Why is cvtColort ~10 times faster than:
float coeffs[3];
coeffs[0] = 0;
coeffs[1] = 1;
coeffs[2] = 0;
gray = Mat(color.rows, color.cols, CV_8UC1);
for (int i = 0; i < color.rows; i++) {
for (int j = 0; j < color.cols; j++) {
gray.at<uchar>(i, j) = 0;
for (int k = 0; k < 3; k++) {
gray.at<uchar>(i, j) += coeffs[k] * color.at<Vec3b>(i, j)[k];
}
}
}
I tried changing row/col for order but it does not change the time.
Because you have a double for loop, which is basically a quite intensive memory operation. OpenCV uses internal optimalisations like the use of parallelized for loops and NEON optimizations. So it is quite normal you will never reach the same performance with a double for loop, which is always a kind of bad programming if you want to go for processing speed!