Quantcast
Channel: OpenCV Q&A Forum - Latest question feed
Viewing all articles
Browse latest Browse all 19555

slow when calculate moment

$
0
0
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(y, x); break; case 01: mm += y*roi.at(y, x); break; case 10: mm += x*roi.at(y, x); break; case 11: mm += x*y*roi.at(y, x); break; case 02: mm += y*y*roi.at(y, x); break; case 20: mm += x*x*roi.at(y, x); break; default: break; } } } return mm; } My problem is my own function is quite slower than the moments of OpenCV library. So can you help me to improve my code to make it faster?

Viewing all articles
Browse latest Browse all 19555

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>