Ask Your Question
2

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

Comments

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
6

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

edit flag offensive delete link more

Comments

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
4

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
Login/Signup to Answer

Question Tools

1 follower

Stats

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

Seen: 9,391 times

Last updated: Mar 25 '14