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;