First time here? Check out the FAQ!

Ask Your Question
3

Need to know the HSV value.

asked Mar 25 '14

Nitesh gravatar image

updated Dec 26 '15

image description I want to know the minimum and maximum range of HSV values to be kept in cvInRangeS() to get the body of mouse. Any particular method to get almost exact range?? I am using OpenCV2.4.8 and C and Visual Studio 2010.

Any help would be appreciated. Thanks

Preview: (hide)

Comments

Cut out the mouse manually, calculate the average values for each channel over all pixels. Then do + and - 15%?

StevenPuttemans gravatar imageStevenPuttemans (Mar 25 '14)edit

2 answers

Sort by » oldest newest most voted
7

answered Mar 25 '14

Haris gravatar image

updated Mar 25 '14

Just use code below, which will display RGB and HSV value corresponding to mouse position. Also see the HSV-ColorWheel here might be helpful.

 char window_name[30] = "HSV Segemtation";
 Mat src;

 static void onMouse( int event, int x, int y, int f, void* ){
 Mat image=src.clone();
 Vec3b rgb=image.at<Vec3b>(y,x);
 int B=rgb.val[0];
 int G=rgb.val[1];
 int R=rgb.val[2];

  Mat HSV;
  Mat RGB=image(Rect(x,y,1,1));
  cvtColor(RGB, HSV,CV_BGR2HSV);

    Vec3b hsv=HSV.at<Vec3b>(0,0);
    int H=hsv.val[0];
    int S=hsv.val[1];
    int V=hsv.val[2];

    char name[30];
    sprintf(name,"B=%d",B);
    putText(image,name, Point(150,40) , FONT_HERSHEY_SIMPLEX, .7, Scalar(0,255,0), 2,8,false );

    sprintf(name,"G=%d",G);
    putText(image,name, Point(150,80) , FONT_HERSHEY_SIMPLEX, .7, Scalar(0,255,0), 2,8,false );

    sprintf(name,"R=%d",R);
    putText(image,name, Point(150,120) , FONT_HERSHEY_SIMPLEX, .7, Scalar(0,255,0), 2,8,false );

    sprintf(name,"H=%d",H);
    putText(image,name, Point(25,40) , FONT_HERSHEY_SIMPLEX, .7, Scalar(0,255,0), 2,8,false );

    sprintf(name,"S=%d",S);
    putText(image,name, Point(25,80) , FONT_HERSHEY_SIMPLEX, .7, Scalar(0,255,0), 2,8,false );

    sprintf(name,"V=%d",V);
    putText(image,name, Point(25,120) , FONT_HERSHEY_SIMPLEX, .7, Scalar(0,255,0), 2,8,false );

    sprintf(name,"X=%d",x);
    putText(image,name, Point(25,300) , FONT_HERSHEY_SIMPLEX, .7, Scalar(0,0,255), 2,8,false );

    sprintf(name,"Y=%d",y);
    putText(image,name, Point(25,340) , FONT_HERSHEY_SIMPLEX, .7, Scalar(0,0,255), 2,8,false );

 //imwrite("hsv.jpg",image);
 imshow( window_name, image );
}



int main(){
 src = imread("bgr.png",1);
 imshow(window_name,src);
 setMouseCallback( window_name, onMouse, 0 );
 waitKey();
 }

image description

Preview: (hide)

Comments

You should consider turning your answers into small tutorials. It could help people alot! +1 for the effort!

StevenPuttemans gravatar imageStevenPuttemans (Mar 26 '14)edit

Hi thanks for your suggestion, I will think about it.

Haris gravatar imageHaris (Mar 26 '14)edit
4

answered Mar 25 '14

unxnut gravatar image

One solution would be to create two trackbars corresponding to min and max of the range. Move the trackbars around and see what values give you satisfactory result. You will probably discover a few additional things about your picture as well to get ideas on other processing needed.

Preview: (hide)

Question Tools

1 follower

Stats

Asked: Mar 25 '14

Seen: 15,073 times

Last updated: Mar 25 '14