Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can check the color values using the OpenCV GUI: imshow("HSV image",imhsv);. The colors will be off, but you can verify the values using the mouse cursor.

Otherwise it's strange, normally your segmentation should take the V values over 50 and S values over 70.

Anyway, I wrote a small interactive OpenCV utility to help getting the correct limits for segmentation with inRange. Hope it helps:

Mat imHSV,colorimg;

void on_trackbar(int, void *data)
{
    Mat sgm,res;
    int *ch=(int*)data;
    Scalar smin,smax;
    smin[0]=ch[0];smin[1]=ch[2];smin[2]=ch[4];
    smax[0]=ch[1];smax[1]=ch[3];smax[2]=ch[5];
    inRange(imHSV,smin,smax,sgm);
    colorimg.copyTo(res,sgm);
    imshow("Image",res);
}

void main()
{
    colorimg=imread("my_image.jpg");
    cvtColor(colorimg, imHSV, COLOR_BGR2HSV);
    int ch[6];
    ch[0]=ch[2]=ch[4]=0;
    ch[1]=ch[3]=ch[5]=255;
    createTrackbar("H_Min","Image",&ch[0],255,on_trackbar,ch);
    createTrackbar("H_Max","Image",&ch[1],255,on_trackbar,ch);
    createTrackbar("S_Min","Image",&ch[2],255,on_trackbar,ch);
    createTrackbar("S_Max","Image",&ch[3],255,on_trackbar,ch);
    createTrackbar("V_Min","Image",&ch[4],255,on_trackbar,ch);
    createTrackbar("V_Max","Image",&ch[5],255,on_trackbar,ch);
    waitKey();
}