forked from Smorodov/Multitarget-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5bb22fb
Showing
142 changed files
with
4,311 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# ---------------------------------------------------------------------------- | ||
# ìèíèìàëüíàÿ âåðñèÿ CMake, ñïîñîáíàÿ ïåðåâàðèòü ýòîò ôàéë | ||
# ---------------------------------------------------------------------------- | ||
cmake_minimum_required(VERSION 2.8) | ||
# ---------------------------------------------------------------------------- | ||
# Ïðåäïîëàãàåì, ÷òî FindOpenCV.cmake ðàñïîëîæåí ïî àäðåñó CMAKE_MODULE_PATH. | ||
# ---------------------------------------------------------------------------- | ||
FIND_PACKAGE(OpenCV) | ||
# ---------------------------------------------------------------------------- | ||
# èùåì âñå .cpp è .h ôàéëû è äîáàâëÿåì èõ â íàø ïðîåêò | ||
# ---------------------------------------------------------------------------- | ||
FILE(GLOB folder_source *.cpp) | ||
FILE(GLOB folder_header *.h) | ||
SOURCE_GROUP("Source Files" FILES ${folder_source}) | ||
SOURCE_GROUP("Header Files" FILES ${folder_header}) | ||
# ---------------------------------------------------------------------------- | ||
# ñîçäàåì ïðîåêò | ||
# ---------------------------------------------------------------------------- | ||
ADD_EXECUTABLE(ObjectTracker ${folder_source} ${folder_header}) | ||
# ---------------------------------------------------------------------------- | ||
# äîáàâëÿåì include äèðåêòîðèè | ||
# ---------------------------------------------------------------------------- | ||
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}) | ||
INCLUDE_DIRECTORIES(${OpenCV_INCLUDE_DIRS}) | ||
# ---------------------------------------------------------------------------- | ||
# è Lib-û opencv | ||
# ---------------------------------------------------------------------------- | ||
TARGET_LINK_LIBRARIES(ObjectTracker ${OpenCV_LIBS}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include "Detector.h" | ||
using namespace cv; | ||
using namespace std; | ||
|
||
CDetector::CDetector(Mat& gray) | ||
{ | ||
fg=gray.clone(); | ||
bs=new BackgroundSubtract; | ||
bs->init(gray); | ||
vector<Rect> rects; | ||
vector<Point2d> centers; | ||
|
||
} | ||
|
||
//---------------------------------------------------------------------- | ||
// Äåòåêòîð êîíòóðîâ, âûâîä ðåçóëüòàòîâ | ||
//---------------------------------------------------------------------- | ||
void CDetector::DetectContour(Mat& img, vector<Rect>& Rects,vector<Point2d>& centers) | ||
{ | ||
double area=0; | ||
Rects.clear(); | ||
centers.clear(); | ||
vector<vector<Point> > contours; | ||
vector<Vec4i> hierarchy; | ||
Mat edges=img.clone(); | ||
Canny(img, edges, 50, 190, 3); | ||
findContours(edges,contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, Point()); | ||
if(contours.size()>0) | ||
{ | ||
for( int i = 0; i < contours.size(); i++ ) | ||
{ | ||
Rect r=cv::boundingRect(contours[i]); | ||
Rects.push_back(r); | ||
centers.push_back((r.br()+r.tl())*0.5); | ||
} | ||
} | ||
} | ||
|
||
vector<Point2d> CDetector::Detect(Mat& gray) | ||
{ | ||
bs->subtract(gray,fg); | ||
// rects - ãàáàðèòíûå ïðÿìîóãîëüíèêè | ||
// centers - öåíòðû ãàáàðèòíûõ ïðÿìîóãîëüíèêîâ | ||
/* | ||
Mat fg2; | ||
fg.convertTo(fg2,CV_32FC1); | ||
cv::GaussianBlur(fg2,fg2,Size(5,5),1.0); | ||
cv::Laplacian(fg2,fg2,CV_32FC1); | ||
normalize(fg2,fg2,0,255,cv::NORM_MINMAX); | ||
fg2.convertTo(fg2,CV_8UC1); | ||
cv::applyColorMap(fg2,fg2,COLORMAP_JET); | ||
imshow("Foreground",fg2); | ||
*/ | ||
DetectContour(fg,rects,centers); | ||
return centers; | ||
} | ||
|
||
CDetector::~CDetector(void) | ||
{ | ||
delete bs; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
#include "opencv2/opencv.hpp" | ||
#include "BackgroundSubtract.h" | ||
#include <iostream> | ||
#include <vector> | ||
using namespace cv; | ||
using namespace std; | ||
class CDetector | ||
{ | ||
private: | ||
void DetectContour(Mat& img, vector<Rect>& Rects,vector<Point2d>& centers); | ||
BackgroundSubtract* bs; | ||
vector<Rect> rects; | ||
vector<Point2d> centers; | ||
Mat fg; | ||
public: | ||
CDetector(Mat& gray); | ||
vector<Point2d> Detect(Mat& gray); | ||
~CDetector(void); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <vector> | ||
#include <iostream> | ||
#include <limits> | ||
#include <time.h> | ||
// http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=hungarianAlgorithm | ||
using namespace std; | ||
class AssignmentProblemSolver | ||
{ | ||
private: | ||
// -------------------------------------------------------------------------- | ||
// Computes the optimal assignment (minimum overall costs) using Munkres algorithm. | ||
// -------------------------------------------------------------------------- | ||
void assignmentoptimal(int *assignment, double *cost, double *distMatrix, int nOfRows, int nOfColumns); | ||
void buildassignmentvector(int *assignment, bool *starMatrix, int nOfRows, int nOfColumns); | ||
void computeassignmentcost(int *assignment, double *cost, double *distMatrix, int nOfRows); | ||
void step2a(int *assignment, double *distMatrix, bool *starMatrix, bool *newStarMatrix, bool *primeMatrix, bool *coveredColumns, bool *coveredRows, int nOfRows, int nOfColumns, int minDim); | ||
void step2b(int *assignment, double *distMatrix, bool *starMatrix, bool *newStarMatrix, bool *primeMatrix, bool *coveredColumns, bool *coveredRows, int nOfRows, int nOfColumns, int minDim); | ||
void step3 (int *assignment, double *distMatrix, bool *starMatrix, bool *newStarMatrix, bool *primeMatrix, bool *coveredColumns, bool *coveredRows, int nOfRows, int nOfColumns, int minDim); | ||
void step4 (int *assignment, double *distMatrix, bool *starMatrix, bool *newStarMatrix, bool *primeMatrix, bool *coveredColumns, bool *coveredRows, int nOfRows, int nOfColumns, int minDim, int row, int col); | ||
void step5 (int *assignment, double *distMatrix, bool *starMatrix, bool *newStarMatrix, bool *primeMatrix, bool *coveredColumns, bool *coveredRows, int nOfRows, int nOfColumns, int minDim); | ||
// -------------------------------------------------------------------------- | ||
// Computes a suboptimal solution. Good for cases with many forbidden assignments. | ||
// -------------------------------------------------------------------------- | ||
void assignmentsuboptimal1(int *assignment, double *cost, double *distMatrixIn, int nOfRows, int nOfColumns); | ||
// -------------------------------------------------------------------------- | ||
// Computes a suboptimal solution. Good for cases with many forbidden assignments. | ||
// -------------------------------------------------------------------------- | ||
void assignmentsuboptimal2(int *assignment, double *cost, double *distMatrixIn, int nOfRows, int nOfColumns); | ||
public: | ||
enum TMethod { optimal, many_forbidden_assignments, without_forbidden_assignments }; | ||
AssignmentProblemSolver(); | ||
~AssignmentProblemSolver(); | ||
double Solve(vector<vector<double>>& DistMatrix,vector<int>& Assignment,TMethod Method=optimal); | ||
}; |
Oops, something went wrong.