步骤:
1先读取视频(or图片)文件
2将图像转换为hsv
3通过判断hsv值范围识别颜色
hsv范围颜色对应:
示例:识别视频中的黄色区域,并变成白色显示
#include <iostream>
#include <opencv2\opencv.hpp>
using namespace cv;
using namespace std;
int H, S, V;
void GetHSV(Mat &image, int div = 64)
{
int nl = image.rows; //行数
int nc = image.cols; //列数
for (int j = 0; j < nl; j++)
{
for (int i = 0; i < nc; i++)
{
H = image.at<Vec3b>(j, i)[0];
S = image.at<Vec3b>(j, i)[1];
V = image.at<Vec3b>(j, i)[2];
//cout << "H=" << H << "S=" << S << "V=" << V << endl;
if ((H >= 0) && (H <= 180) && (S >= 0) && (S &l