opencv cuda使用笔记

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

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

cv::Mat image = cv::imread(imgpath + filelist[i]);
            //std::cout << "image:" << filelist[i] << std::endl;
            if (image.empty()) {
                std::cout << "读入图片为空,请检查路径!" << std::endl;
                system("pause");
                return -1;
            }

           /* cv::Mat image;
            cv::cvtColor(image_o, image, cv::COLOR_BGR2RGB);*/

            DWORD start2 = GetTickCount();

            cv::cuda::GpuMat imageGpu(image.cols, image.rows, CV_8UC3, cv::Scalar(0, 0, 0));

            //cv::cuda::GpuMat imageGpu;// (cv::Size(image.cols, image.rows), CV_8UC3);

            cv::cuda::GpuMat imageRGB(image.cols, image.rows, CV_32FC3, cv::Scalar(0, 0, 0));
            imageGpu.upload(image);
            imageGpu.convertTo(imageRGB, CV_32FC3, 1,0);

转cpu:

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

查看像素:

void showMat(cv::Mat &img){
    std::cout << "图像元素查看 : " << img.rows<<"," << img.cols <<std::endl;
    for (int i = 0; i<img.rows; i++)
    {
        for (int j = 0; j < img.cols; j++)
        {
            std::cout<< "("<<
                    (float)img.at<cv::Vec3f>(i, j)[0]<< ", " <<
                    (float)img.at<cv::Vec3f>(i, j)[1]<< ", " <<
                    (float)img.at<cv::Vec3f>(i, j)[2]<< ") " << std::endl;
                    //(int)img.at<cv::Vec3b>(i, j)[0]<< ", " <<
                    //(int)img.at<cv::Vec3b>(i, j)[1]<< ", " <<
                    //(int)img.at<cv::Vec3b>(i, j)[2]<< ") " << std::endl;
            }
        }
    }
}
//打印一个Mat矩阵
void PrintMat(Mat A)
{
  for(int i=0;i<A.rows;i++)
  {
    for(int j=0;j<A.cols;j++)
      cout<<A.at<float>(i,j)<<' ';
    cout<<endl;
  }
  cout<<endl;
}

cuda方式操作:

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

相关文章