Ask Your Question
0

How can I draw a mark over the video?

asked 2018-06-01 09:15:48 -0600

biza gravatar image

I have made the following code , and when the user click the left side of mouse he should put a marker in the position, and when the second click as made , the first one should be erased , the same thing should happen with coordinates, someone can help me. I don't understand the draw marker function...

void onMouse(int event, int x, int y, int flags, void *param){
if(event == CV_EVENT_LBUTTONDOWN){
    /**/
    if(cntr == 0){
      //  cv::drawMarker(param, cv::Point(x, y),  cv::Scalar(0, 0, 255), MARKER_CROSS, 10, 1);

        waitKey(5);
        cout << "POSITION:\n"<<y<<" "<<endl;
       //destroy=true;
    }else{
       // cv::drawMarker(param, cv::Point(x, y),  cv::Scalar(0, 0, 255), MARKER_CROSS, 10, 1);
        cout <<y<<endl;
    }
    cntr = cntr + 1;
}

}

edit retag flag offensive close merge delete

Comments

berak gravatar imageberak ( 2018-06-01 09:27:13 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-06-01 10:12:27 -0600

berak gravatar image

updated 2018-06-01 10:22:13 -0600

yea, broken logic / code.

to draw a marker, you would need an image, and you probably don't have that in your onMouse callback.

also, you can't erase anything, but you can choose, NOT to draw it again in the next frame.

let's try to fix it. assuming, you wanted a single marker drawn at the current click position ,

void onMouse(int event, int x, int y, int flags, void *param){
    Point *p = (Point*)param;

    // set
    if (event == CV_EVENT_LBUTTONDOWN){
         p->x = x;
         p->y = y;
    }

    // clear
    if (event == CV_EVENT_RBUTTONDOWN){
         p->x = -1;
         p->y = -1;
    }
}


// in main()

Point p(-1,-1);  // initially invisible
namedWindow("main");
setMouseCallback("main", onMouse,  (void) &p); // use our point in the callback function

while(true) {
     Mat frame; 
     capture.read(frame);

    if (p.x != -1) 
         cv::drawMarker(frame, p,  cv::Scalar(0, 0, 255), MARKER_CROSS, 10, 1);

    ....
}
edit flag offensive delete link more

Comments

Solved, tank you for your help

biza gravatar imagebiza ( 2018-06-02 14:41:01 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-06-01 09:15:48 -0600

Seen: 385 times

Last updated: Jun 01 '18