opencv GPU 简单遍历图像
2014-04-08 11:05
1731 查看
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; }
显示结果
相关文章推荐
- 一种简单高效的OpenCV图像遍历方式
- OpenCV ——遍历图像方法
- Python下opencv使用笔记(一)(图像简单读取、显示与储存)
- 将文件夹中的图像路径自动生成txt文件(便于opencv遍历处理图像)
- OpenCV优化:图像的遍历4种方式
- 我的OpenCV学习笔记(三):利用操作像素完成简单的图像处理:加入椒盐噪声、图像翻转、改变对比度、图像锐化
- opencv遍历图像像素
- OpenCV对图像或矩阵元素遍历的四种方法
- OPenCV2_如何使用迭代器遍历图像
- OpenCV笔记8:一个简单的变换:图像的平滑
- opencv中遍历图像(Mat格式)
- opencv入门笔记之三 简单图像识别,识别线,点,圆,轮廓
- OpenCV学习篇之六 遍历图像和邻域操作
- OpenCV学习笔记(基于OpenCV 2.4)二:图像的加载显示及简单变换
- 使用VS+OpenCV的图像处理简单例子
- OpenCV学习C++接口:图像遍历+像素压缩
- opencv 图像简单逻辑操作汇总与一些常用的函数
- OpenCV - 简单图像融合
- OpenCV2编程手册笔记之 2.4迭代器遍历图像
- [OpenCV2]遍历图像的临近像素