1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| #include <iostream> #include <opencv2/opencv.hpp>
int main() { cv::Mat image = cv::imread("cv_blue.jpg"); cv::cvtColor(image,image,CV_BGR2RGB);
cv::Mat temp = image.clone(); cv::cvtColor(temp,temp,CV_RGB2HSV); int h = temp.at<cv::Vec3b>(0,0)[0]; int s = temp.at<cv::Vec3b>(0,0)[1]; int v = temp.at<cv::Vec3b>(0,0)[2]; std::cout << "h:" << h / 180.0 << ", s:" << s / 255.0<<", v:" << v / 255.0 << std::endl;
int red = static_cast<int>(image.at<cv::Vec3b>(0,0)[0]); int green = static_cast<int>(image.at<cv::Vec3b>(0,0)[1]); int blue = static_cast<int>(image.at<cv::Vec3b>(0,0)[2]); std::cout << "red:" << red << ", green:" << green <<", blue:" << blue << std::endl; }
h:0.666667, s:1, v:0.996078 red:0, green:0, blue:254
|