for循环的一种加速方法
来源:互联网 发布:ios编程软件 编辑:程序博客网 时间:2024/05/23 16:57
一、源码如下:
#include "stdafx.h"#include "cv.h"#include "highgui.h"#include <istream>using namespace cv;using namespace std; int _tmain(int argc, _TCHAR* argv[]){Mat srcImg = imread("D:\\Documents\\Desktop\\图像拼接测试图片\\11-over750.bmp", CV_LOAD_IMAGE_GRAYSCALE);Mat dstImg1, dstImg2;srcImg.copyTo(dstImg1);srcImg.copyTo(dstImg2);uchar *srcData = srcImg.data;uchar *dstData1 = dstImg1.data;uchar *dstData2 = dstImg2.data;int size = srcImg.cols * srcImg.rows;int threshold = 122;int i;double ts1 = ( double )getTickCount();for(i = 0; i < size; ++i){if(srcData[i] < threshold)dstData1[i] = 0;elsedstData1[i] = 255;}//idouble te1 = ( double )getTickCount();double tim1 = (te1 - ts1) * 1000.0 / getTickFrequency();double ts2 = ( double )getTickCount();i = 0;int size2 = size - 4;for(; i < size2; i += 4){if(srcData[i] < threshold)dstData2[i] = 0;elsedstData2[i] = 255;if(srcData[i + 1] < threshold)dstData2[i + 1] = 0;elsedstData2[i + 1] = 255;if(srcData[i + 2] < threshold)dstData2[i + 2] = 0;elsedstData2[i + 2] = 255;if(srcData[i + 3] < threshold)dstData2[i + 3] = 0;elsedstData2[i + 3] = 255;}//ifor(; i < size; ++i){if(srcData[i] < threshold)dstData2[i] = 0;elsedstData2[i] = 255;}//idouble te2 = ( double )getTickCount();double tim2 = (te2 - ts2) * 1000.0 / getTickFrequency();cout << " one loop:" << tim1 << endl;cout << "one four loop:" << tim2 << endl;namedWindow("img1");namedWindow("img2");imshow("img1", dstImg1);imshow("img2", dstImg2);waitKey(0);return 0;}时间对比:
1、Debug下时间:
2、Release下时间:
结论:几乎加速一倍。
0 0
- for循环的一种加速方法
- for循环的一种加速方法
- for循环的一种简化
- 游戏中防止加速的一种方法
- 一种基于ARM平台的Android启动加速方法
- 一种不能进行gpu加速的折中方法
- 数组循环左移的一种方法
- for双层循环的一种使用方法:Java新用法
- 一种利用线程池进行for循环处理的思想
- Java1.5中新加入的一种for循环——增强型for循环
- 在上JAVA课时看到了一种的调试方法,帮我把这个循环弄明白了,而且对FOR循环的理解也更深了
- 退出双层的for循环的方法
- 在点阵液晶显示中,一种菜单循环的方法
- 一种不断循环监测某一事件的方法
- for循环遍历字符串的另一种方法
- for循环保存i值的方法
- Django模版中for循环的方法
- for循环和jquery的each()跳出循环的方法
- Oracle E-Business Suite Maintenance Guide Release 12.2(Patching Utilities)
- linux学习之(五)-linux文解压、压缩、安装
- Queue
- HDU 2544 最短路【经典题】
- Oracle E-Business Suite Maintenance Guide Release 12.2(Patching Procedures)
- for循环的一种加速方法
- 寒假训练DP
- iOS的Asyncsocket进行socket编程
- 大家不要看
- xmanager连接redhat(centos)
- Idea部署Openfire源码时遇到的一些问题
- 嘿嘿笑话网-低俗笑话与黄色笑话的集中地
- Android 遮罩层效果
- c语言中很有意思的union讲解