在图像处理领域,我们经常需要遍历一幅图像,opencv提供多种方法完成对图像的遍历,但是他们的效率是不同的。程序中我们常使用指针或者迭代器的方法遍历图像,下面的程序将对两种方法的效率做对比。
条件:单线程,主频3.4GHz计算机运行,图像image.jpg尺寸为768×576。
// readImage.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include
#include
#include
using namespace cv;
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
Mat image = imread("image.jpg",0);
Mat gray1 = Mat::zeros(image.rows,image.cols,image.type());
Mat gray2 = Mat::zeros(image.rows,image.cols,image.type());
long int count = 0;
uchar num = 0;
double t = (double)getTickCount();
for (int i = 0; i < image.rows; i++)</