admin 发表于 2022-7-29 10:54:14

OpenCV将图像分离为rgb,hls,hsv通道并显示

#include<opencv2/opencv.hpp>
#include<opencv2/highgui.hpp>
#include<opencv2/imgproc.hpp>
#include<iostream>

using namespace std;
using namespace cv;
int main()
{
    Mat img;
       img = imread("11.png");

    if (img.empty())
    {
      cout << "could not load image!" << endl;
    }
    Mat img_bgr,img_hsv, img_hls;
    cvtColor(img, img_hsv, COLOR_BGR2HSV);
    cvtColor(img, img_hls, COLOR_BGR2HLS);
    img_bgr = img.clone();
    vector<Mat> hsvSplit;
    vector<Mat> hlsSplit;
    vector<Mat> bgrSplit;
    split(img_hsv, hsvSplit);
    split(img_hls, hlsSplit);
    split(img_bgr, bgrSplit);
    Mat hsv_h = hsvSplit;
    Mat hsv_s = hsvSplit;
    Mat hsv_v = hsvSplit;
    Mat hls_h = hlsSplit;
    Mat hls_l = hlsSplit;
    Mat hls_s = hlsSplit;
    Mat bgr_b = bgrSplit;
    Mat bgr_g = bgrSplit;
    Mat bgr_r = bgrSplit;
    imshow("hsv_h", hsv_h);
    imshow("hsv_s", hsv_s);
    imshow("hsv_v", hsv_v);
    imshow("hls_h", hls_h);
    imshow("hls_l", hls_l);
    imshow("hls_s", hls_s);
    imshow("bgr_b", bgr_b);
    imshow("bgr_g", bgr_g);
    imshow("bgr_r", bgr_r);
    waitKey(0);
      return 1;

}
页: [1]
查看完整版本: OpenCV将图像分离为rgb,hls,hsv通道并显示