原文:http://blog.csdn.net/sanwandoujiang/article/details/22087973
//#include "stdafx.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char* argv[])
{
Mat image = imread("14.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++)
{
uchar* ptr = image.ptr<uchar>(i);
uchar* g_ptr = gray1.ptr<uchar>(i);
for (int j = 0; j < image.cols; j++)
{
g_ptr[j] = ptr[j];
}
}
t = ((double)getTickCount() - t)/getTickFrequency();
double t1 = (double)getTickCount();
for (int i=0;i<image.rows;i++)
{
for (int j=0;j<image.cols;j++)
{
gray1.at<uchar>(i,j) = image.at<uchar>(i,j);
}
}
t1 = ((double)getTickCount() - t1)/getTickFrequency();
double t2 = (double)getTickCount();
for (int i = 0; i < image.rows; i++)
{
uchar* ptr = image.ptr<uchar>(i);
for (int j = 0; j < image.cols; j++)
{
num = ptr[j];
}
}
t2 = ((double)getTickCount() - t2)/getTickFrequency();
double t3 = (double)getTickCount();
for (int i=0;i<image.rows;i++)
{
for (int j=0;j<image.cols;j++)
{
num = image.at<uchar>(i,j);
}
}
t3 = ((double)getTickCount() - t3)/getTickFrequency();
cout << t*1000 <<endl;
cout << t1*1000 << endl;
cout << t2*1000 *1000<< endl;
cout << t3*1000 *1000<< endl;
getchar();
return 0;
}
结果时间:
0.31934 0.949494 0.031 0.022
转载请注明原文地址: https://ju.6miu.com/read-10445.html