580
社区成员
发帖
与我相关
我的任务
分享
Mat left_image = imread("AVT60.bmp", IMREAD_GRAYSCALE);
Mat right_image = imread("AVT61.bmp", IMREAD_GRAYSCALE);
//判断图像文件是否加载成功
if (left_image.empty() || right_image.empty())
{
cout << "图像加载失败,程序即将退出...";
exit(EXIT_FAILURE);
}
else
cout << "图像加载成功!" << endl << endl;
//图像基本信息
const int width = left_image.cols;
const int height = left_image.rows;
//cout << left_image.size();
//声明device存储图像数据
uchar* left_data_device = NULL;
uchar* right_data_device = NULL;
size_t pitch;
checkCudaErrors(cudaMallocPitch(&left_data_device, &pitch, width*sizeof(int), height));
checkCudaErrors(cudaMallocPitch(&right_data_device, &pitch, width*sizeof(int), height));
checkCudaErrors(cudaMemcpy2D(left_data_device, pitch, left_image.data, width*sizeof(int), width*sizeof(int), height, cudaMemcpyHostToDevice));
checkCudaErrors(cudaMemcpy2D(right_data_device, pitch, right_image.data, width*sizeof(int), width*sizeof(int), height, cudaMemcpyHostToDevice));
checkCudaErrors(cudaFree(left_data_device));
checkCudaErrors(cudaFree(right_data_device));