-
Notifications
You must be signed in to change notification settings - Fork 0
/
algFeatSearch.cpp
73 lines (58 loc) · 1.75 KB
/
algFeatSearch.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "algFeatSearch.h"
AlgFeatSearch::GetFeatFunc* AlgFeatSearch::GetFeat::gfFuncList = 0;
bool AlgFeatSearch::GetFeat::isInitialized = false;
AlgFeatSearch::CompareFeatFunc* AlgFeatSearch::CompareFeat::cfFuncList = 0;
bool AlgFeatSearch::CompareFeat::isInitialized = false;
AlgFeatSearch::GetFeat::GetFeat(baseImage& image, baseImage** nImage, int imageNum, _FEAT_TYPE featType) : image(image)
{
if (!isInitialized){
gfFuncList = new GetFeatFunc[_FEAT_TYPE_END];
gfFuncList[_COLOR_HIST] = GetColorHist;
}
this->nImage = nImage;
this->imageNum = imageNum;
this->featType = featType;
}
void AlgFeatSearch::GetFeat::apply()
{
gfFuncList[featType](image);
for (int i = 0; i < imageNum; ++i)
{
gfFuncList[featType](*nImage[i]);
}
}
void AlgFeatSearch::GetColorHist(baseImage& image)
{
if (image.GetImageFeat()->state.getColorHist)
{
return;
}
// change the mat format
cv::Mat* mat = image.GetMat();
cv::Mat newMat;
cv::Mat* histMat = &image.GetImageFeat()->histMat;
unsigned int channels = mat->channels();
double maxVal,minVal;
switch (channels) {
case 1:
{
int histSize[] = {256};
float hRanges[] = {0.0, 255.0};
const float* ranges[] = {hRanges};
const int channels[] = {0};
mat->copyTo(newMat);
cv::calcHist(&newMat, 1, channels, cv::Mat(), *histMat, 1, histSize, ranges);
cv::minMaxLoc(*histMat, &minVal, &maxVal);
}
break;
case 3:
if (image.GetChannelChangeState()){
cv::cvtColor(*mat, newMat, CV_RGB2HSV);
}else{
cv::cvtColor(*mat, newMat, CV_BGR2HSV);
}
break;
case 4:
break;
}
}