Ask Your Question

Need to know the HSV value.

asked 2014-03-25 08:17:43 -0500

Nitesh gravatar image

updated 2015-12-26 04:12:59 -0500

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

edit retag flag offensive close merge delete


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

StevenPuttemans gravatar imageStevenPuttemans ( 2014-03-25 08:22:50 -0500 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2014-03-25 10:11:12 -0500

Haris gravatar image

updated 2014-03-25 10:16:32 -0500

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();
 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);

    int H=hsv.val[0];
    int S=hsv.val[1];
    int V=hsv.val[2];

    char name[30];
    putText(image,name, Point(150,40) , FONT_HERSHEY_SIMPLEX, .7, Scalar(0,255,0), 2,8,false );

    putText(image,name, Point(150,80) , FONT_HERSHEY_SIMPLEX, .7, Scalar(0,255,0), 2,8,false );

    putText(image,name, Point(150,120) , FONT_HERSHEY_SIMPLEX, .7, Scalar(0,255,0), 2,8,false );

    putText(image,name, Point(25,40) , FONT_HERSHEY_SIMPLEX, .7, Scalar(0,255,0), 2,8,false );

    putText(image,name, Point(25,80) , FONT_HERSHEY_SIMPLEX, .7, Scalar(0,255,0), 2,8,false );

    putText(image,name, Point(25,120) , FONT_HERSHEY_SIMPLEX, .7, Scalar(0,255,0), 2,8,false );

    putText(image,name, Point(25,300) , FONT_HERSHEY_SIMPLEX, .7, Scalar(0,0,255), 2,8,false );

    putText(image,name, Point(25,340) , FONT_HERSHEY_SIMPLEX, .7, Scalar(0,0,255), 2,8,false );

 imshow( window_name, image );

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

image description

edit flag offensive delete link more


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

StevenPuttemans gravatar imageStevenPuttemans ( 2014-03-26 02:41:10 -0500 )edit

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

Haris gravatar imageHaris ( 2014-03-26 02:48:23 -0500 )edit

answered 2014-03-25 08:35:05 -0500

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.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2014-03-25 08:17:43 -0500

Seen: 12,908 times

Last updated: Mar 25 '14