forked from gnebehay/OpenTLD
-
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
IIUJ-MaksymPlencler
committed
Aug 6, 2013
1 parent
9e3f5b8
commit 620e3d5
Showing
14 changed files
with
452 additions
and
16 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 |
---|---|---|
|
@@ -8,4 +8,4 @@ OpenTLDConfig.cmake | |
TODO | ||
cmake_install.cmake | ||
*.a | ||
|
||
build/ |
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
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
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
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
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
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,127 @@ | ||
/* | ||
* ShapeClassifier.h | ||
* | ||
* Created on: May 20, 2013 | ||
* Author: Maksym Plencler | ||
*/ | ||
#include "ShapeClassifier.h" | ||
#include "DetectorCascade.h" | ||
#include "TLDUtil.h" | ||
#include <iostream> | ||
|
||
using namespace cv; | ||
|
||
namespace tld | ||
{ | ||
|
||
ShapeClassifier::ShapeClassifier(void) | ||
{ | ||
this->img = NULL; | ||
enabled = false; | ||
similarityThreshold = 0.6f; | ||
} | ||
|
||
ShapeClassifier::~ShapeClassifier(void) | ||
{ | ||
release(); | ||
} | ||
|
||
void ShapeClassifier::release() | ||
{ | ||
positivePatches->clear(); | ||
} | ||
|
||
void ShapeClassifier::nextIteration(const Mat &img) | ||
{ | ||
if(!enabled) return; | ||
|
||
this->img = img; | ||
} | ||
|
||
bool ShapeClassifier::filter(int i) | ||
{ | ||
if(!enabled) return true; | ||
|
||
if(calcSimilarity(i) < similarityThreshold) { | ||
//cout << "rejected" << endl; | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
float ShapeClassifier::calcSimilarity(int windowIdx) | ||
{ | ||
NormalizedPatch patch; | ||
|
||
int *bbox = &windows[TLD_WINDOW_SIZE * windowIdx]; | ||
tldExtractNormalizedPatchBB(img, bbox, patch.values); | ||
|
||
return similarityWithModel(&patch); | ||
} | ||
|
||
float similarityOf(Mat patch1, Mat patch2) | ||
{ | ||
Mat result; | ||
absdiff(patch1, patch2, result); | ||
|
||
float sum = 0; | ||
unsigned char *imgData = (unsigned char *)result.data; | ||
|
||
for(int i = 0; i < 15; i++) | ||
{ | ||
for(int j = 0; j < 15; j++) | ||
{ | ||
sum += imgData[j * result.step + i]; | ||
} | ||
} | ||
float res = 1 - (sum/(15*15))/255; | ||
return res; | ||
} | ||
|
||
float ShapeClassifier::similarityWithModel(NormalizedPatch *patch) | ||
{ | ||
if(positivePatches->empty()) | ||
{ | ||
return 0; | ||
} | ||
|
||
float similarity = 0; | ||
|
||
Mat patchMat = Mat(15, 15, CV_8U, patch); | ||
Canny(patchMat, patchMat, 10, 30, 3); | ||
//int element_shape = CV_SHAPE_RECT; | ||
//IplConvKernel* element = cvCreateStructuringElementEx(2+1, 2+1, 1, 1, element_shape); | ||
dilate(patchMat, patchMat, Mat(), Point(-1,-1)); | ||
//imshow( "propozycja", patchMat ); | ||
|
||
Mat modelElemMat; | ||
//cout << "PP: " << positivePatches->size() << endl; | ||
|
||
for(size_t i = 0; i < positivePatches->size(); i++) | ||
{ | ||
modelElemMat = Mat(15, 15, CV_8U, positivePatches->at(i).values); | ||
Canny(patchMat, patchMat, 10, 30, 3); | ||
dilate(patchMat, patchMat, Mat(), Point(-1,-1)); | ||
|
||
similarity = similarityOf(modelElemMat, patchMat); | ||
|
||
if(similarity > similarityThreshold) | ||
{ | ||
patchMat.release(); | ||
modelElemMat.release(); | ||
return similarity; | ||
} | ||
} | ||
|
||
patchMat.release(); | ||
modelElemMat.release(); | ||
return similarity; | ||
} | ||
|
||
|
||
void ShapeClassifier::setPositivePatches(std::vector<NormalizedPatch>* pp) | ||
{ | ||
positivePatches = pp; | ||
} | ||
|
||
} /* namespace tld */ |
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,46 @@ | ||
/* | ||
* ShapeClassifier.h | ||
* | ||
* Created on: May 20, 2013 | ||
* Author: Maksym Plencler | ||
*/ | ||
|
||
#ifndef SHAPECLASSIFIER_H_ | ||
#define SHAPECLASSIFIER_H_ | ||
|
||
#include <opencv/cv.h> | ||
|
||
#include "DetectionResult.h" | ||
#include "NormalizedPatch.h" | ||
|
||
namespace tld | ||
{ | ||
|
||
class ShapeClassifier | ||
{ | ||
std::vector<NormalizedPatch>* positivePatches; | ||
cv::Mat img; | ||
|
||
|
||
public: | ||
bool enabled; | ||
int *windows; | ||
int *windowOffsets; | ||
|
||
DetectionResult *detectionResult; | ||
|
||
float similarityThreshold; | ||
|
||
ShapeClassifier(); | ||
virtual ~ShapeClassifier(); | ||
|
||
void release(); | ||
void nextIteration(const cv::Mat &img); | ||
bool filter(int idx); | ||
float calcSimilarity(int windowIdx); | ||
void setPositivePatches(std::vector<NormalizedPatch>* positivePatches); | ||
float similarityWithModel(NormalizedPatch *patch); | ||
}; | ||
|
||
} /* namespace tld */ | ||
#endif /* SHAPECLASSIFIER_H_ */ |
Oops, something went wrong.