Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

you need to clone() the image (so you can draw things independantly), and call imshow() with different window names, like:

  for(unsigned i=0; i<trackers.getObjects().size(); i++)
  {
      Mat img = frame.clone();
      rectangle(img, trackers.getObjects()[i], Scalar::all(255), 2);
      imshow(format("tracker_%d", i), img);
  }

  waitKey(30);

you need to clone() the image (so you can draw things independantly), and call imshow() with different window names, like:

  for(unsigned i=0; i<trackers.getObjects().size(); i++)
  {
      Mat img = frame.clone();
      rectangle(img, trackers.getObjects()[i], Scalar::all(255), 2);
      imshow(format("tracker_%d", i), img);
  }

  waitKey(30);

edit:

if you're mainly interested in the content of the roi's you also could try like this:

  Size sz(100,100);
  Mat rois;
  vector<Rect2d> rects = trackers.getObjects();
  for(unsigned i=0; i<rects.size(); i++)
  {
     Mat patch;
     resize(frame(rects[i]), patch, sz);
     if (rois.empty())
         rois = patch;
     else
         hconcat(rois, patch, rois);
  }

  imshow("ROIS", rois);
  waitKey(30);

you need to clone() the image (so you can draw things independantly), and call imshow() with different window names, like:

  for(unsigned i=0; i<trackers.getObjects().size(); i++)
  {
      Mat img = frame.clone();
      rectangle(img, trackers.getObjects()[i], Scalar::all(255), 2);
      imshow(format("tracker_%d", i), img);
  }

  waitKey(30);

edit:

if you're mainly interested in the content of the roi's you also could try like this:

  Size sz(100,100);
  Mat rois;
  vector<Rect2d> rects = trackers.getObjects();
  for(unsigned i=0; i<rects.size(); i++)
  {
     Mat patch;
     resize(frame(rects[i]), patch, sz);
     if (rois.empty())
         rois = patch;
patch.clone();
     else
         hconcat(rois, patch, rois);
  }

  imshow("ROIS", rois);
  waitKey(30);