cv::Vec3b

cv::Vec3b 小记

1.vector(向量): C++中的一种数据结构,一个类,相当于一个动态的数组。(类模板)

vector <int> a  //vector用法

<Vec3f>  浮点
<Vec3d>  double
<Vec3b>  8U 类型的 RGB 彩色图像  (0-255)

2.设置像素点值

单通道:

 img.at<uchar>(5,6) = 25;

多通道:

img.at< cv:: Vec3b >(5,6) [0]= 25;//B  
img.at< cv:: Vec3b >(5,6) [1]= 25;//G  
img.at< cv:: Vec3b >(5,6) [2]= 25;//R  

3.读取像素点值

   #include<opencv2/opencv.hpp>           //偷懒可直接全局引用
   #include <iostream>   
   int main(int argc, char *argv[]){
   
   cv::Mat image_rgb=cv::imread("/home/wan/dog.png");       //读图
   int x=16,y=32;     // 要读取的坐标点
   
   cv::Vec3b pix_rgb=image_rgb.at< cv::Vec3b >(y,x);//  多通道,(x,y)根据自己的图像格式安排
   // Scalar pix_gray = img.at<uchar>(x, y);            //单通道
   
   uchar blue=pix_rgb[0];
   uchar green=pix_rgb[1];
   uchar red=pix_rgb[2];
   
   int r_int= int(red);
   int b_int= int(blue);
   int g_int= int(green);

   std::cout<<"blue: "<<b_int<<std::endl;
   std::cout<<"green: "<<g_int<<std::endl;
   std::cout<<"red: "<<r_int<<std::endl;
   
   cv::imshow("RGB",image_rgb);
   cv::waitKey(0);
   cv::destroyAllWindows();
   
   return 0;
   }
   
//注:转换为 int 再输出   

     int red_int=int(red);
     std::cout<<red_int<<endl;
  • 11
    点赞
  • 49
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值