21种颜色的rgb值及显示

21种颜色的rgb值及显示_第1张图片

#include 

int colors[21][3] = 
    {
        {255, 0, 0}, 
        {255, 69, 0}, 
        {255, 99, 71}, 
        {255, 140, 0}, 
        {255, 165, 0}, 
        {238, 173, 14},
        {255, 193, 37}, 
        {255, 255, 0}, 
        {255, 236, 139},
        {202, 255, 112}, 
        {0, 255, 0}, 
        {84, 255, 159},
        {127, 255, 212}, 
        {0, 229, 238}, 
        {152, 245, 255},
        {178, 223, 238}, 
        {126, 192, 238}, 
        {28, 134, 238},
        {0, 0, 255}, 
        {72, 118, 255}, 
        {122, 103, 238} 
    };

int main() {
    int height = 630, width = 360;
    cv::Mat src = cv::Mat::zeros(height, width, CV_8UC3);
    for(int i = 0; i < height; ++i) {
        for(int j = 0; j < width; ++j) {
            src.at<cv::Vec3b>(i, j)[0] = colors[i/30][2];
            src.at<cv::Vec3b>(i, j)[1] = colors[i/30][1];
            src.at<cv::Vec3b>(i, j)[2] = colors[i/30][0];
        }
        cv::putText(src, std::to_string(colors[i/30][0]), cv::Point(0,i/30*30+15), cv::FONT_HERSHEY_PLAIN,1,cv::Scalar(255, 255, 255), 2);
        cv::putText(src, std::to_string(colors[i/30][1]), cv::Point(60,i/30*30+15), cv::FONT_HERSHEY_PLAIN,1,cv::Scalar(255, 255, 255), 2);
        cv::putText(src, std::to_string(colors[i/30][2]), cv::Point(120,i/30*30+15), cv::FONT_HERSHEY_PLAIN,1,cv::Scalar(255, 255, 255), 2);
    }
    cv::imshow("img", src);
    cv::waitKey(0);

    return 0;
}

你可能感兴趣的:(小功能)