<DeepSORT적용 test동영상 - 다운X>

test.zip

Untitled

Untitled

Untitled

Untitled

Untitled

Untitled

Untitled

Untitled

Untitled

Untitled

Project.h

//  Project.h: interface of CProject (main project class you will write)
//    Dept. Software Convergence, Kyung Hee University
//    Prof. Daeho Lee, [email protected]
//

#pragma once
#include "cv_dnn_ultraface.h"

class CKcPoint {
public:
    int x, y;
    CKcPoint() : x(0), y(0) {}
    CKcPoint(int x, int y) : x(x), y(y) {}
    CKcPoint operator+(const CKcPoint& p) const {
        return { x + p.x, y + p.y };
    }
    CKcPoint operator-(const CKcPoint& p) const {
        return { x - p.x, y - p.y };
    }
};

class CKcRect {
public:
    int left, top, right, bottom;
    CKcRect() {}
    CKcRect(int l, int t, int r, int b) : left(l), top(t), right(r), bottom(b) {}
    double Iou(const CKcRect& rt) {
        CKcRect inter;
        inter = Intersect(rt);
        if (!inter.IsRect()) return 0;

        return (double)(inter.Width()*inter.Height()) / (Width()*Height() + rt.Width()*rt.Height() - inter.Width() * inter.Height());
    }
    CKcRect Intersect(const CKcRect& rt) const {
        CKcRect inter;
        inter.left = std::max(left, rt.left);
        inter.top = std::max(top, rt.top);
        inter.right = std::min(right, rt.right);
        inter.bottom = std::min(bottom, rt.bottom);

        return inter;
    }
    bool IsRect() const {
        if (left >= right) return false;
        if (top >= bottom) return false;
        return true;
    }
    int Width() const {
        return right - left;
    }
    int Height() const {
        return bottom - top;
    }

    CKcPoint Center() const {
        return CKcPoint((right + left)/2, (bottom + top)/2);
    }

    void RefineImage(int nW, int nH) {
        if (left < 0) left = 0;
        if (top < 0) top = 0;
        if (right < 0) right = 0;
        if (bottom < 0) bottom = 0;

        if (left >= nW) left = nW - 1;
        if (top >= nH) top = nH - 1;
        if (right >= nW) right = nW - 1;
        if (bottom >= nH) bottom = nH - 1;
    }
};

class CFaceTracker {
public:
    static int cnt;
    int id;
    CKcRect rt;
    std::vector<cv::Mat> featureList; // Feature map 저장 (여러 프레임에 대하여)
    int untrackedCnt;
    bool remove;
    CKcPoint offset;

    static double GetCosineSimilarity(std::vector<cv::Mat> featureList, cv::Mat feature) {
			/*코드 작성 -> featureList의 5프레임에 대하여 각각 feature와 cosine similarity계산 후, 가장 큰 cosine similarity 값을 return */
    }

    CFaceTracker() {
        id = cnt++;
        untrackedCnt = 0;
        remove = false;
    }
    CFaceTracker(int l, int t, int r, int b, cv::Mat f) : rt(l, t, r, b) {
        id = cnt++;
        untrackedCnt = 0;
        remove = false;
        featureList.push_back(f);
    }
    CFaceTracker(CKcRect rt, cv::Mat f) : rt(rt) {
        id = cnt++;
        untrackedCnt = 0;
        remove = false;
        featureList.push_back(f);
    }
};

class CProject
{
    cv::Mat m_PreviousImage;
public:
    char m_ExePath[256];
    wchar_t m_ExePathUnicode[256];

    CProject();
    ~CProject();
    void GetExecutionPath();
    void Run(cv::Mat Input, cv::Mat& Output, bool bFirstRun, bool bVerbose);

    UltraFace *m_pUltraface;

    cv::dnn::Net m_MobileNet; // DeepSORT에 사용할 CNN네트워크
    std::vector<CFaceTracker> m_FaceTracker;
};