HSV
RGB 转HSV
HSV转RGB
//===============================================================
//FileName:
// HSV变换.cpp
//Date:
// 2019/12/8
//Author:
// khoing(https://blog.csdn.net/qq_45391763)
//===============================================================
#include <opencv2/opencv.hpp>
#include <iostream>
#include <math.h>
//----------------------------------------------------------
// BGR -> HSV
cv::Mat BGR2HSV(cv::Mat img) {
// get height and width
int width = img.cols;
int height = img.rows;
float r, g, b;
float h, s, v;
float _max, _min;
//----------------------------------------------------------
// prepare output
cv::Mat hsv = cv::Mat::zeros(height, width, CV_32FC3);
//----------------------------------------------------------
// each y, x
for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) {
// BGR -> HSV
//----------------------------------------------------------
//归一化 到0~1
r = (float)img.at<cv::Vec3b>(row, col)[2] / 255;
g = (float)img.at<cv::Vec3b>(row