opencv3.1 提取图像中某一像素点的HSV值并判断颜色

相关学习资料:

https://blog.csdn.net/taily_duan/article/details/51506776【OpenCV】HSV颜色识别-HSV基本颜色分量范围

https://blog.csdn.net/qq_15947787/article/details/72784253【opencv】目标识别——HSV颜色识别

https://blog.csdn.net/guyuealian/article/details/77981619OpenCV获取图像某点的颜色值,并设置某点的颜色

https://blog.csdn.net/weijifen000/article/details/84203136利用OpenCV获取图片上某一点的颜色HSV值

https://blog.csdn.net/clp786080772/article/details/51913158Opencv颜色识别

https://www.jianshu.com/p/bb3b316d6936简单颜色识别并跟踪

https://blog.csdn.net/qq78442761/article/details/83056346OpenCV识别指定颜色(黑、灰、白、红、橙、黄、绿、青、蓝、紫)

https://blog.csdn.net/bjbz_cxy/article/details/79712074使用Opencv获取每个像素点的RGB颜色分量/HSV颜色分量

 

判断颜色时H、S、V的上下区间值(if语句中的取值范围)需要根据实际需要调整,matHsv是HSV格式的图像

            vector colorVec;
            colorVec.push_back(matHsv.at(rows,cols)[0]);
            colorVec.push_back(matHsv.at(rows,cols)[1]);
            colorVec.push_back(matHsv.at(rows,cols)[2]);
           if((colorVec[0]>=174&&colorVec[0]<=180)&&(colorVec[1]>=236&&colorVec[1]<=242)&&(colorVec[2]>=238&&colorVec[2]<=244)){
               //cout<=57&&colorVec[0]<=63)&&(colorVec[1]>=239&&colorVec[1]<=245)&&(colorVec[2]>=232&&colorVec[2]<=238)){
               //return 'G';
                cout<<"green"<

下面是在一段视频中截取某一帧,将其特定像素的HSV作为颜色判断参考值的代码

    VideoCapture capture;
    capture.open( "/home/wfl/Desktop/test/record.mp4"  );
    Mat image;
    Mat matHsv;    
    long frameToStart =7970;
    capture.set( CV_CAP_PROP_POS_FRAMES, frameToStart );
    capture>>image;
    cvtColor(image,matHsv,COLOR_BGR2HSV);//RGB转HSV
    cout<<"G:"<(matHsv.at(30,1325)[0])<<","<(matHsv.at(30,1325)[1])<<","<(matHsv.at(30,1325)[2])<(matHsv.at(27,1444)[0])<<","<(matHsv.at(27,1444)[1])<<","<(matHsv.at(27,1444)[2])<

H:  0 — 180

S:  0 — 255

V:  0 — 255

在HSV空间各种颜色的范围

opencv3.1 提取图像中某一像素点的HSV值并判断颜色_第1张图片

图片来自https://blog.csdn.net/taily_duan/article/details/51506776

你可能感兴趣的:(opencv)