//swap.cu  

#include "cuda_runtime.h"
#include "device_launch_parameters.h" #include <opencv2/core/cuda_devptrs.hpp>
using namespace cv;
using namespace cv::gpu; //自定义内核函数
__global__ void swap_rb_kernel(const PtrStepSz<uchar3> src,PtrStep<uchar3> dst)
{
int x = threadIdx.x + blockIdx.x * blockDim.x;
int y = threadIdx.y + blockIdx.y * blockDim.y; if(x < src.cols && y < src.rows)
{
uchar3 v = src(y,x);
dst(y,x) = make_uchar3(v.z,v.y,v.x);
}
} extern "C" void swap_rb_caller(const PtrStepSz<uchar3>& src,PtrStep<uchar3> dst,cudaStream_t stream)
{
dim3 block(32,8);
dim3 grid((src.cols + block.x - 1)/block.x,(src.rows + block.y - 1)/block.y); swap_rb_kernel<<<grid,block,0,stream>>>(src,dst);
if(stream == 0)
cudaDeviceSynchronize();
}

  

//swap.cpp  

#include <opencv2/gpu/gpu.hpp>
#include <opencv2/gpu/stream_accessor.hpp> using namespace cv;
using namespace cv::gpu; extern "C" void swap_rb_caller(const PtrStepSz<uchar3>& src,PtrStep<uchar3> dst,cudaStream_t stream); extern "C" void swap_rb(const GpuMat& src,GpuMat& dst,Stream& stream = Stream::Null())
{
CV_Assert(src.type() == CV_8UC3);
dst.create(src.size(),src.type());
cudaStream_t s = StreamAccessor::getStream(stream);
swap_rb_caller(src,dst,s);
}

  

//main.cpp  

#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/gpu/gpu.hpp> #pragma comment(lib,"opencv_gpu2410d.lib")
#pragma comment(lib,"opencv_core2410d.lib")
#pragma comment(lib,"opencv_highgui2410d.lib") using namespace cv;
using namespace cv::gpu; extern "C" void swap_rb(const GpuMat& src,GpuMat& dst,Stream& stream = Stream::Null()); int main()
{
Mat image = imread("lena.jpg");
imshow("src",image);
GpuMat gpuMat,output; gpuMat.upload(image);
swap_rb(gpuMat,output);
output.download(image); imshow("gpu",image);
getchar();
waitKey(0);
return 0;
}

  

最新文章

  1. Electron中Jquery的引入方式
  2. [模板] SAP
  3. C++设计模式-Flyweight享元模式
  4. Js C# 实现跨域访问数据
  5. Linux内核启动
  6. STL学习三:deque容器
  7. SMB2 Protocol – 简介(应用层协议主要用于在计算机间共享文件、打印机、串口等)
  8. Fitnesse-20140630与RestFixture-3.1编译与运行步骤
  9. kernel解读之 pick_next_rt_entity
  10. Microsoft Visual C++ Runtime Library Runtime Error解决的方式
  11. 2.1 Word 插入 smartart、图表
  12. 老李推荐: 第3章2节《MonkeyRunner源码剖析》脚本编写示例: MonkeyDevice API使用示例 4
  13. CSRF跨站
  14. js网页判断移动终端浏览器版本信息是安卓还是苹果ios,判断在微信浏览器跳转不同页面,生成二维码
  15. centos 开放端口
  16. HBase事务
  17. 步步深入:MySQL架构总览-&gt;查询执行流程-&gt;SQL解析顺序(转)
  18. LuoGu P1541 乌龟棋
  19. vue.js自定义指令详解
  20. Java进阶之路

热门文章

  1. Flutter移动电商实战 --(13)ADBanner组件的编写
  2. Nginx命令与配置详解
  3. HttpClient提交数据
  4. 11. Ingress及Ingress Controller(主nginx ingress controller)
  5. 让 Nginx 支持 WAF 防护功能实战
  6. Flask Response响应(flask中设置响应信息的方法,返回json数据的方法)
  7. java.lang.reflect.Method.getAnnotation()方法示例
  8. 线程池小结(JDK8)
  9. linux 系统函数 basename和dirname
  10. 李宏毅 Gradient Descent Demo 代码讲解