openmp在图像处理上面的运用
2016-06-05 22:34
337 查看
// openmptest的测试程序
//
#include "stdafx.h"
void Test(int n){
for (int i=0;i<10000;i++)
{
int j=0;
j = j+1;
}
printf("%d",n);
}
int _tmain(int argc, _TCHAR* argv[])
{
for (int i=0;i<10;i++)
{
Test(i);
}
getchar();
return 0;
}
而开启openmp
代码
// openmptest的测试程序
//
#include "stdafx.h"
void Test(int n){
for (int i=0;i<10000;i++)
{
int j=0;
j = j+1;
}
printf("%d",n);
}
int _tmain(int argc, _TCHAR* argv[])
{
for (int i=0;i<10;i++)
{
Test(i);
}
getchar();
return 0;
}
速度更快。
在最简单的层次上,openmp提供了粗颗粒的并行算法。一直以来,我都在寻找图像处理的加速算法,但是由于图像处理的特性(大多为线性项目),所以很难有好的提速方法。但是对于批量的图像处理,采用我们这种方法将是非常好用的。
编写较为复杂的opencv 程序
// openmptest的测试程序
//
#include "stdafx.h"
#include <iostream>
#include <opencv2/opencv.hpp>
#include "GoCvHelper.h"
using namespace std;
using namespace cv;
using namespace GO;
Mat Test(Mat src){
Mat draw;
Mat gray;
cvtColor(src,gray,COLOR_BGR2GRAY);
threshold(gray,gray,100,255,THRESH_OTSU);
connection2(gray,draw);
return draw;
}
int _tmain(int argc, _TCHAR* argv[])
{
//时间记录
const int64 start = getTickCount();
vector<Mat> vectorMats;
//文件目录
char cbuf[100] = "F:/图片资源/纹理库brodatz/brodatzjpg";
//获取所有文件
getFiles(cbuf,vectorMats);
//循环处理
// #pragma omp parallel for
for (int i=0;i<vectorMats.size();i++)
{
Mat dst = Test(vectorMats[i]);
}
//时间
double duration = (cv::getTickCount() - start)/getTickFrequency();
printf("共消耗时间%f",duration);
waitKey();
return 0;
}
不用mp的是这么长时间
不看算法本身的效率,在解决这个问题的时候,这种方法还是相当好用的。
//
#include "stdafx.h"
void Test(int n){
for (int i=0;i<10000;i++)
{
int j=0;
j = j+1;
}
printf("%d",n);
}
int _tmain(int argc, _TCHAR* argv[])
{
for (int i=0;i<10;i++)
{
Test(i);
}
getchar();
return 0;
}
而开启openmp
代码
// openmptest的测试程序
//
#include "stdafx.h"
void Test(int n){
for (int i=0;i<10000;i++)
{
int j=0;
j = j+1;
}
printf("%d",n);
}
int _tmain(int argc, _TCHAR* argv[])
{
for (int i=0;i<10;i++)
{
Test(i);
}
getchar();
return 0;
}
速度更快。
在最简单的层次上,openmp提供了粗颗粒的并行算法。一直以来,我都在寻找图像处理的加速算法,但是由于图像处理的特性(大多为线性项目),所以很难有好的提速方法。但是对于批量的图像处理,采用我们这种方法将是非常好用的。
编写较为复杂的opencv 程序
// openmptest的测试程序
//
#include "stdafx.h"
#include <iostream>
#include <opencv2/opencv.hpp>
#include "GoCvHelper.h"
using namespace std;
using namespace cv;
using namespace GO;
Mat Test(Mat src){
Mat draw;
Mat gray;
cvtColor(src,gray,COLOR_BGR2GRAY);
threshold(gray,gray,100,255,THRESH_OTSU);
connection2(gray,draw);
return draw;
}
int _tmain(int argc, _TCHAR* argv[])
{
//时间记录
const int64 start = getTickCount();
vector<Mat> vectorMats;
//文件目录
char cbuf[100] = "F:/图片资源/纹理库brodatz/brodatzjpg";
//获取所有文件
getFiles(cbuf,vectorMats);
//循环处理
// #pragma omp parallel for
for (int i=0;i<vectorMats.size();i++)
{
Mat dst = Test(vectorMats[i]);
}
//时间
double duration = (cv::getTickCount() - start)/getTickFrequency();
printf("共消耗时间%f",duration);
waitKey();
return 0;
}
不用mp的是这么长时间
不看算法本身的效率,在解决这个问题的时候,这种方法还是相当好用的。
相关文章推荐
- 基于SSH开发架构的重新分层/SSH思想之我见
- Linux下的进程管理——task_struct
- 查看Linux系统当前是多少位
- ScopeGuard : 安全清理资源
- 一天一个shell命令 linux好管家--磁盘--df命令详解
- 谈task_struct
- Nginx一个实现负载均衡的强大web server
- 第2章 linux文件系统
- linux 内核定时器
- shell,awk,sed
- Linux应用编程总结
- CentOS 7更换yum源
- Zernike矩及Opencv实现
- 关于Runloop
- hadoop 日志
- 《zabbix监控配置邮件报警》
- Linux下的I/O复用与epoll详解
- OpenCV 将视频截成等长的小片段
- Hadoop YARN配置参数剖析(5)—Capacity Scheduler相关参数
- 【OpenCV入门教程之一】 OpenCV 2.4.8 +VS2010的开发环境配置