Ask Your Question
0

How to create trackbar

asked 2014-09-13 03:52:32 -0600

nhat.truong gravatar image

Hi everybody ! I want to create a trackbar to change the value of argument in inRange() function. I realize that everytime I change Scalar in this function and debug, it takes many times. I want to create a trackbar to change Scalar when I'm debugging . Can everyone help me about this problem ? Thanks very much

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-09-13 04:03:21 -0600

berak gravatar image
int red = 17; // initial value
int grn = 1;  // initial value
int blu = 27; // initial value
namedWindow("thewindow");
createTrackbar("red", "thewindow", &red, 255);
createTrackbar("grn", "thewindow", &grn, 255);
createTrackbar("blu", "thewindow", &blu, 255);
// ...
// later,
// ...
Mat img, bin;
Scalar lower(red,grn,blu);
Scalar upper(200,100,50);
inRange(img,lower,upper,bin);
edit flag offensive delete link more

Comments

1

@berak thank you

nhat.truong gravatar imagenhat.truong ( 2014-09-13 04:54:56 -0600 )edit

@berak I used trackbar to find out the suitable argument for Houghcircle function and then draw right circle cover my object, but everytime I change value of trackbar then I can't change the circle was drew in the previous time. Here is my code : createTrackbar("min_dist_px","Window",&min_dist_px,255); createTrackbar("canny_threshold","Window",&canny_threshold,255); createTrackbar("acc_threshold","Window",&acc_threshold,255); createTrackbar("min_radius","Window",&min_radius,255); createTrackbar("max_dist_px","Window",&max_radius,255);

        vector<Vec3f> circles;

        HoughCircles(dst,circles,CV_HOUGH_GRADIENT,
            1, // dp
            min_dist_px, // min_dist_px
            canny_threshold, // higher canny
            acc_threshold, // acc threshold
            min_radius, // min radius
            max_radius);
nhat.truong gravatar imagenhat.truong ( 2014-09-13 11:05:30 -0600 )edit

I think I must use the trackbar change event to solve this problem but I don't know how to use this trackbar event. Can you help me about this problem ? Have a great day

nhat.truong gravatar imagenhat.truong ( 2014-09-13 11:07:55 -0600 )edit

only if you tell me, what "Anh sau khi tim thay duong tron" means ? i'm having a lot of fun with google translate ;)

berak gravatar imageberak ( 2014-09-13 11:17:26 -0600 )edit

sorry this is my mother language :) It means the image after finding out right circle

nhat.truong gravatar imagenhat.truong ( 2014-09-13 11:42:36 -0600 )edit

hehe, thanks. and sorry for being late, but life got in the way. i'll do another answer for the event handler

berak gravatar imageberak ( 2014-09-14 04:07:08 -0600 )edit

Question Tools

Stats

Asked: 2014-09-13 03:52:32 -0600

Seen: 462 times

Last updated: Sep 13 '14