OpenCV静心修炼总结篇3——Mat 对象的使用

 按照src 大小尺寸 类型复制 size type

参考代码:

Mat dst;

  dst = Mat(src.size(),src.type());

  dst= Scalar(0,0,100);  // 为BGR 每个通道赋值

  namedWindow("output image",CV_WINDOW_AUTOSIZE);

      imshow("output image",dst);

 clone 克隆

参考代码:

Mat dst = src.clone();

      namedWindow("output image",CV_WINDOW_AUTOSIZE);

imshow("output image",dst);

copyTo 克隆

参考代码:

Mat dst;

   src.copyTo(dst);

       namedWindow("output image",CV_WINDOW_AUTOSIZE);

       imshow("output image",dst);

 图像通道数查看 channels

参考代码: 

Mat dst;

  cvtColor(src,dst,CV_BGR2GRAY);

      printf("input image channels: %d\n",src.channels());

      printf("output image channels: %d\n",dst.channels());

 打印灰度图的行数与列数 读取灰度图片某一行数据

参考代码:    

  int cols = dst.cols;

  int rows = dst.rows;

  printf("cols: %d, rows: %d\n",cols,rows);

  for(int i=0;i<dst.rows;i++)

  {

    static uchar *firstrow = dst.ptr<uchar>(i);

printf("%d row fiex %d\n",i,*firstrow);

}

 Mat对象创建

参考代码:    

  Mat M(3,3,CV_8UC3,Scalar(0,0,255));​​​​​​​

  cout<<"M:"<< endl <<M << endl;

  imshow("output image",M);

 

猜你喜欢

转载自blog.csdn.net/qq_27762895/article/details/84180903
今日推荐