#include <iostream> #include <opencv2/opencv.hpp> #include <osakana/stopwatch.hpp> int main() { const int w = 1920; const int h = 1080; const int testcnt = 255; osakana::stopwatch sw; cv::Mat img1 = cv::Mat::zeros(w, h, CV_8UC1); sw.reset(); for(int cnt = 0; cnt < testcnt; ++cnt) { for(int y = 0; y < h; ++y) for(int x = 0; x < w; ++x) img1.at<unsigned char>(y, x) += 1; } std::cout << "cv::Mat::at<T>() -> " << (1.0 * sw.elapsed_ms() / testcnt) << "ms/回" << std::endl; cv::Mat_<unsigned char> img2 = cv::Mat_<unsigned char>::zeros(w, h); sw.reset(); for(int cnt = 0; cnt < testcnt; ++cnt) { for(int y = 0; y < h; ++y) for(int x = 0; x < w; ++x) img2(y, x) += 1; } std::cout << "cv::Mat_<unsigned char>::operator() -> " << (1.0 * sw.elapsed_ms() / testcnt) << "ms/回" << std::endl; }