Ask Your Question

Trackers window add to Canvas window

asked 2018-12-13 05:22:04 -0600

cherault gravatar image

Dear all,


Using a main window with the multitracker algorithm, I select various ROIs with a mouse. This main window is within another one named "Canvas". In the Canvas window, I would like to add all the ROIs which I selected, whitin a window named "Tracks".

Here is a screen-shot of what I want:

image description

How could I add the "Tracks" window within the "Canvas" window ?

Thanks for your help and support.


edit retag flag offensive close merge delete


wasn't this already answered here ?

berak gravatar imageberak ( 2018-12-13 07:07:33 -0600 )edit

Hello Berak, yes you are right. But is it possible to associate the "tracks" window within the "canvas" window resizing the tracks automatically to fit the width of the canvas window ?

Thanks in advance for your support.


cherault gravatar imagecherault ( 2018-12-13 07:13:42 -0600 )edit

if you post your actual code (preferably on github) i can try to help.

sturkmen gravatar imagesturkmen ( 2018-12-13 07:16:34 -0600 )edit

Hello Sturkmen, Thanks for your proposal. You can find the code here : link text Thanks for your help. Regards

cherault gravatar imagecherault ( 2018-12-13 07:27:36 -0600 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2018-12-13 09:39:30 -0600

please try the code below ( i hope it is not too cryptographic )

#include <iostream>
#include <opencv2/highgui.hpp>
#include <opencv2/tracking.hpp>
#include "samples_utility.hpp"

using namespace std;
using namespace cv;

void addPatch(Mat& canvas, Mat& frame, Rect rect, Size sz, int index)
    Rect r_patch(10+(10*index)+(sz.width*index), frame.rows + 20, sz.width, sz.height);
    Mat m_patch = canvas(r_patch);
    resize(frame(rect), m_patch, sz);

int main()
    Mat frame;

    MultiTracker trackers;
    String trackingAlg = "CSRT";
    vector<Rect> ROIs;
    vector<Rect2d> objects;
    vector<Ptr<Tracker> > algorithms;

    string video = "vtest.avi";
    VideoCapture cap(video);

    cap >> frame;

    selectROIs("tracker", frame, ROIs, 0, 0);

    for (size_t i = 0; i < ROIs.size(); i++)

    trackers.add(algorithms, frame, objects);

    while (true)
        cap >> frame;
        Mat canvas(frame.rows + 150, frame.cols + 50, CV_8UC3, Scalar(127, 127, 127));

        Rect r(10, 10, frame.cols, frame.rows);


        for (unsigned i = 0; i < trackers.getObjects().size(); i++)
            rectangle(canvas, trackers.getObjects()[i], Scalar::all(255), 2);

        Size sz(100, 100);
        Mat rois;
        vector<Rect2d> rects = trackers.getObjects();

        for (unsigned i = 0; i < rects.size(); i++)
            addPatch(canvas,frame,rects[i], sz, i);

        imshow("Frame", frame);
        imshow("Canvas", canvas);
    return 0;
edit flag offensive delete link more



Thank you very much, it's exactly what I need !!! You save my day ! Thanks ! Regards,

cherault gravatar imagecherault ( 2018-12-13 09:48:31 -0600 )edit

Also, it's not cryptographic ;-) It 's clear for me.

cherault gravatar imagecherault ( 2018-12-13 09:49:26 -0600 )edit

glad it helped. maybe you guess if the selections more than x (7 in my test case ) it will give an error. you need to add some checks

sturkmen gravatar imagesturkmen ( 2018-12-13 09:55:40 -0600 )edit

Thanks to you ! Ok, but I will use only 3 or may be 4 max. I am really bad when I need a specifi GUI... This code will help me to go further and add some AI on the trackers. If I can achieve that, I will be very glad to share my work with the OpenCV community. Best regards, Christophe

cherault gravatar imagecherault ( 2018-12-13 09:59:21 -0600 )edit

Question Tools

1 follower


Asked: 2018-12-13 05:22:04 -0600

Seen: 354 times

Last updated: Dec 13 '18