Hi everyone, I try to write my own function to calc the moments as below:
double getMoment(Mat roi, uint8_t mode) { double mm = 0; for (int x = 0; x < roi.size().width; ++x) { for (int y = 0; y < roi.size().height; ++y) { switch (mode) { case 00: mm += roi.at<uchar>(y, x); break; case 01: mm += yroi.at<uchar>(y, x); break; case 10: mm += xroi.at<uchar>(y, x); break; case 11: mm += xyroi.at<uchar>(y, x); break; case 02: mm += yyroi.at<uchar>(y, x); break; case 20: mm += xxroi.at<uchar>(y, x); break; default: break; } } } return mm; }
My problem is my own function is quite slow than the moments of OpenCV library. So can you help me to improve my code to make it faster?