selectROI is not working.

asked 2016-04-20 01:38:32 -0600

onecue gravatar image

I want to run a multi object tracking code nuder opencv 3.1 with contrib. In the code, there is a line with selectROI().

Console said to me "Select an object to track and then press SPACE or ENTER button! Finish the selection process by pressing ESC button!".

I could select roi with mouse click.

But the window can't capture my keyboard input. I can't proceed next step. What is a problem?

MultiTracker trackers(trackingAlg);

// container of the tracked objects
vector<Rect2d> objects;

// set input video
std::string video = argv[1];
VideoCapture cap(video);

Mat frame;

// get bounding box
cap >> frame;

selectROI("tracker", frame, objects);

//quit when the tracked object(s) is not provided
if (objects.size()<1)
    return 0;

// initialize the tracker
trackers.add(frame, objects);


// do the tracking
printf("Start the tracking process, press ESC to quit.\n");
for (;;){
    // get frame from the video
    cap >> frame;

    // stop the program if no more images
    if (frame.rows == 0 || frame.cols == 0)
        break;

    //update the tracking result
    trackers.update(frame);

    // draw the tracked object
    for (unsigned i = 0; i<trackers.objects.size(); i++)
        rectangle(frame, trackers.objects[i], Scalar(255, 0, 0), 2, 1);

    // show image with the tracked object

    imshow("tracker", frame);

    //quit on ESC button
    if (waitKey(1) == 27)break;
}
edit retag flag offensive close merge delete

Comments

1
  • which os is it ?
  • "But the window can't capture my keyboard input." -- what ? does it work in another context ?
berak gravatar imageberak ( 2016-04-20 01:42:14 -0600 )edit

windows 10 Yes, waitKey() works fine.

onecue gravatar imageonecue ( 2016-04-20 02:31:13 -0600 )edit
1

you actually have to perss 2 times, once(space or enter) to accept the selection, then esc, to leave the roiselector

berak gravatar imageberak ( 2016-04-20 02:40:00 -0600 )edit

I did that and press all of keys. but not working.

onecue gravatar imageonecue ( 2016-04-20 02:47:48 -0600 )edit

same problem here . the error is 'selectROI was not defined in this scope"

ManuVISION gravatar imageManuVISION ( 2016-11-10 01:08:41 -0600 )edit