1、BGR转为灰度图的CUDA demo
__global__ void Image2Gray(uchar* din, uchar* dout, int h, int w) {
int i = threadIdx.x + blockDim.x*blockIdx.x;
int j = threadIdx.y + blockDim.y*blockIdx.y;
int idx = j*w + i;
int idx3 = idx * 3;
dout[idx] = 0.229* din[idx3 + 0] + 0.587*din[idx3 + 1] + 0.114*din[idx3 + 2];
}
int Img2GrayTestGPU() {
bool display = true;
cv::Mat img = cv::imread("C:/Users/Desktop/demo/res.jpg");
cv::resize(img, img, cv::Size(480, 640));
//cv::imshow("img", img);
//cv::waitKey(0);
int w = img.cols;
int h = img.rows;
int wh = w*h;
int len_size = wh * 3;
cv::Mat img_gray(h, w, CV_8UC1);
uchar *gdata;
cudaMalloc((void**)&gdata, sizeof(uchar)*wh);
uchar *dataa;
cudaMalloc((void**)&dataa, sizeof(uchar)*len_size);
double gtct_time = (double)cv::getTickCount();
cudaMemcpy(dataa, img.data, sizeof(uchar)*len_size, cudaMemcpyHostToDevice);
dim3 threadPerBlock(32, 32);//block:t