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_TCHARargv[])
{
    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_TCHARargv[])
{
    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_TCHARargv[])
{    
    //时间记录
    const int64 start = getTickCount();
    vector<MatvectorMats;
    //文件目录
    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的是这么长时间
不看算法本身的效率,在解决这个问题的时候,这种方法还是相当好用的。
 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值