opencv GPU 简单遍历图像


opencv GPU  简单遍历图像  


#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <cuda.h>
#include <cuda_device_runtime_api.h>
#include <opencv2\gpu\gpu.hpp>
#include <opencv2\gpu\gpumat.hpp>
#include <opencv2\opencv.hpp>
#include <opencv.hpp>
#include <stdio.h>
#include <iostream>
#include "opencv2/gpu/device/common.hpp"
#include "opencv2/gpu/device/reduce.hpp"
#include "opencv2/gpu/device/functional.hpp"
#include "opencv2/gpu/device/warp_shuffle.hpp"
using namespace std;
using namespace cv;
using namespace gpu;
template <int nthreads>
        __global__ void compute_kernel(int height, int width, const PtrStepb img ,PtrStepb dst)
        {
            const int x = blockIdx.x * blockDim.x + threadIdx.x;
			const int y = blockIdx.y * blockDim.y + threadIdx.y;

			const uchar* src_y = (const uchar*)(img+y*img.step);//对于彩色图像
			uchar* dst_y = (uchar*)(dst+y*dst.step);
			if (x < width && y < height)
            {
				
				dst_y[3*x] = src_y[3*x] ;
                dst_y[3*x+1]  = src_y[3*x+1] ;
                dst_y[3*x+2]  = src_y[3*x+2] ;		 
			 }

灰度图像//
			//if (x < width)
   //         {
			// if (blockIdx.y > 0 && blockIdx.y < height )
   //          {
			//	 ((float*)dst.ptr(blockIdx.y))[x] = ((float*)img.ptr(blockIdx.y))[x];
			//	 //((uchar2*)dst.ptr(blockIdx.y))[x] = make_uchar2(blockIdx.y,blockIdx.x);
			// }
			//}
        }	
	int main()
{
Mat a= imread("d:/1.jpg");
	GpuMat d_a(a);
	GpuMat d_dst(d_a.size(),CV_8UC3);
	int width = a.size().width;
	int height = a.size().height;
	const int nthreads =256;
	dim3 bdim(nthreads, 1);
    dim3 gdim(divUp(width, bdim.x), divUp(height, bdim.y));
	compute_kernel<nthreads><<<gdim, bdim>>>(height,width,d_a,d_dst);
	Mat dst(d_dst);
	imshow("a",a);
	imshow("dst",dst);
	waitKey();
    return 0;
}


显示结果



评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值