【opencv+OpenMP】OpenMP并行编程应用 |
您所在的位置:网站首页 › openmp是什么 › 【opencv+OpenMP】OpenMP并行编程应用 |
OpenMP是一种应用于多处理器程序设计的并行编程处理方案,它提供了对于并行编程的高层抽象,只需要在程序中添加简单的指令,就可以编写高效的并行程序,而不用关心具体的并行实现细节,降低了并行编程的难度和复杂度。也正因为OpenMP的简单易用性,它并不适合于需要复杂的线程间同步和互斥的场合。
OpenCV中使用Sift或者Surf特征进行图像拼接的算法,需要分别对两幅或多幅图像进行特征提取和特征描述,之后再进行图像特征点的配对,图像变换等操作。不同图像的特征提取和描述的工作是整个过程中最耗费时间的,也是独立 运行的,可以使用OpenMP进行加速。
以下是不使用OpenMP加速的Sift图像拼接原程序: [cpp] view plain copy print ? #include "highgui/highgui.hpp" #include "opencv2/nonfree/nonfree.hpp" #include "opencv2/legacy/legacy.hpp" #include "omp.h" using namespace cv; //计算原始图像点位在经过矩阵变换后在目标图像上对应位置 Point2f getTransformPoint(const Point2f originalPoint, const Mat &transformMaxtri); int main(int argc, char *argv[]) { float startTime = omp_get_wtime(); Mat image01 = imread("Test01.jpg"); Mat image02 = imread("Test02.jpg"); imshow("拼接图像1", image01); imshow("拼接图像2", image02); //灰度图转换 Mat image1, image2; cvtColor(image01, image1, CV_RGB2GRAY); cvtColor(image02, image2, CV_RGB2GRAY); //提取特征点 SiftFeatureDetector siftDetector(800); // 海塞矩阵阈值 vector keyPoint1, keyPoint2; siftDetector.detect(image1, keyPoint1); siftDetector.detect(image2, keyPoint2); //特征点描述,为下边的特征点匹配做准备 SiftDescriptorExtractor siftDescriptor; Mat imageDesc1, imageDesc2; siftDescriptor.compute(image1, keyPoint1, imageDesc1); siftDescriptor.compute(image2, keyPoint2, imageDesc2); float endTime = omp_get_wtime(); std::cout |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |