Ask Your Question
2

Trackers window add to Canvas window

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

cherault gravatar image

Dear all,

Problem:

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.

Regards,

edit retag flag offensive close merge delete

Comments

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.

Regards,

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
3

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++)
    {
        algorithms.push_back(createTrackerByName(trackingAlg));
        objects.push_back(ROIs[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);
        frame.copyTo(canvas(r));

        trackers.update(frame);

        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);
        waitKey(1);
    }
    destroyAllWindows();
    return 0;
}
edit flag offensive delete link more

Comments

2

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
1

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

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

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
2

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

Stats

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

Seen: 380 times

Last updated: Dec 13 '18