OpenCV:获取图片像素值(RGB/HSV)

//RGB→HSV
Mat rgb,hsv;
cvtColor(rgb, hsv, COLOR_BGR2HSV);

//RGB
//image为BGR类型
B = image.at<Vec3b>(y, x)[0];
G = image.at<Vec3b>(y, x)[1];
R = image.at<Vec3b>(y, x)[2];

//HSV
//image为HSV类型
H = image.at<Vec3b>(y, x)[0];
S = image.at<Vec3b>(y, x)[1];
V = image.at<Vec3b>(y, x)[2];
//RGB→灰度图
cvtColor(image, gray, CV_BGR2GRAY);

//灰度值
gray.at<uchar>(y, x);

你可能感兴趣的:(OpenCV)