opencv cuda使用笔记

x33g5p2x  于2021-12-17 转载在 其他  
字(1.6k)|赞(0)|评价(0)|浏览(383)

cv::cuda::split 使用_jacke121的专栏-CSDN博客

  1. cv::Mat image = cv::imread(imgpath + filelist[i]);
  2. //std::cout << "image:" << filelist[i] << std::endl;
  3. if (image.empty()) {
  4. std::cout << "读入图片为空,请检查路径!" << std::endl;
  5. system("pause");
  6. return -1;
  7. }
  8. /* cv::Mat image;
  9. cv::cvtColor(image_o, image, cv::COLOR_BGR2RGB);*/
  10. DWORD start2 = GetTickCount();
  11. cv::cuda::GpuMat imageGpu(image.cols, image.rows, CV_8UC3, cv::Scalar(0, 0, 0));
  12. //cv::cuda::GpuMat imageGpu;// (cv::Size(image.cols, image.rows), CV_8UC3);
  13. cv::cuda::GpuMat imageRGB(image.cols, image.rows, CV_32FC3, cv::Scalar(0, 0, 0));
  14. imageGpu.upload(image);
  15. imageGpu.convertTo(imageRGB, CV_32FC3, 1,0);

转cpu:

  1. cv::Mat dst;
  2. flt_image_out.download(dst);
  1. cv::Mat dst_gold;
  2. cv::cvtColor(src, dst_gold, cv::COLOR_BGR2RGB);

查看像素:

  1. void showMat(cv::Mat &img){
  2. std::cout << "图像元素查看 : " << img.rows<<"," << img.cols <<std::endl;
  3. for (int i = 0; i<img.rows; i++)
  4. {
  5. for (int j = 0; j < img.cols; j++)
  6. {
  7. std::cout<< "("<<
  8. (float)img.at<cv::Vec3f>(i, j)[0]<< ", " <<
  9. (float)img.at<cv::Vec3f>(i, j)[1]<< ", " <<
  10. (float)img.at<cv::Vec3f>(i, j)[2]<< ") " << std::endl;
  11. //(int)img.at<cv::Vec3b>(i, j)[0]<< ", " <<
  12. //(int)img.at<cv::Vec3b>(i, j)[1]<< ", " <<
  13. //(int)img.at<cv::Vec3b>(i, j)[2]<< ") " << std::endl;
  14. }
  15. }
  16. }
  17. }
  1. //打印一个Mat矩阵
  2. void PrintMat(Mat A)
  3. {
  4.   for(int i=0;i<A.rows;i++)
  5.   {
  6.     for(int j=0;j<A.cols;j++)
  7.       cout<<A.at<float>(i,j)<<' ';
  8.     cout<<endl;
  9.   }
  10.   cout<<endl;
  11. }

cuda方式操作:

OpenCV+CUDA 遍历cv::Mat笔记_YaoJiawei329的博客-CSDN博客

相关文章