forked from NannanZhang/VideoRetrieve
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
executable file
·212 lines (179 loc) · 5.5 KB
/
Main.cpp
File metadata and controls
executable file
·212 lines (179 loc) · 5.5 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
// ImgRetrieveTest1.cpp : Defines the entry point for the console application.
#include "CEDD/CEDDFeature.h"
#include "LSHRetrieve.h"
#include "KeyframeExtraction.h"
using namespace std;
void test();
void testOnePic()
{
IplImage* image = cvLoadImage("0.jpg");
if( image == NULL)
return;
LSHRetrieve myLshRetrieve;
myLshRetrieve.getLSHfromText();
vector<string> similarImgPaths;
string imgDataFilePath = "extractImg/";
int imgNumberToShow = 50;
CEDDFeature myCeddFeature;
myCeddFeature.extract(image);
similarImgPaths = myLshRetrieve.query(myCeddFeature.qCEDD,imgNumberToShow);
string videoMD5filePath = "md5.txt";
ofstream videoMD5file(videoMD5filePath.c_str());
for(int i=0;i<imgNumberToShow;i++){
int dotPostion = similarImgPaths.at(i).find(".");
string md5 = similarImgPaths.at(i).substr(0,dotPostion);
cout << md5 << endl;
videoMD5file << md5 << endl;
}
videoMD5file.close();
}
int main(int argc, char *argv[])
{
//测试
// testOnePic();
// return 0;
///////////////////////////////////////////////////////
char *VIDEOPATH = "fangtan.avi";
if(argc>1){
VIDEOPATH = argv[1];
}
KeyframeExtraction keyframeExtract;
keyframeExtract.init(VIDEOPATH);
if(keyframeExtract.simpleExtraction()<0)
return -1;
keyframeExtract.hsvHistExtraction();
vector<IplImage*> keyframeList = keyframeExtract.getKeyframeList();
//clock_t start, finish;
//double duration;
//start = clock();
LSHRetrieve myLshRetrieve;
myLshRetrieve.getLSHfromText();
//for test
//finish = clock();
//duration = (double)(finish - start) / CLOCKS_PER_SEC;
//cout<< "read txt costs : "<< duration <<" seconds" <<endl;
IplImage* image = NULL;
CEDDFeature myCeddFeature;
cvNamedWindow("keyframe");
char* windowName = "showSimImg%d";
int windowHeight = 200;
int windowWidth = 200;
for(int i=0;i<5;i++){
char imgWindowName[1000];
sprintf(imgWindowName,windowName,i);
cvNamedWindow(imgWindowName,0);
cvResizeWindow(imgWindowName,windowWidth,windowHeight);
cvMoveWindow(imgWindowName,i*250,100);
}
IplImage* simImgs[5] = {NULL};
int imgNumberToShow = 5;
char* testImgFilePath = "%d.jpg";
char* imgRetrievalResultFilePath = "./retriResult/tvShow/%d.jpg";
vector<string> similarImgPaths;
string imgDataFilePath = "../extractImg/";
//while(1){
similarImgPaths.clear();
cout<< "input the img No to retrieve:"<<endl;
int imgNo = 0;
cin >> imgNo;
if(imgNo == -1){
//break;
return -1;
}
char testImgPath[1000];
sprintf(testImgPath,testImgFilePath,imgNo);
if(!(image = cvLoadImage(testImgPath))){
cout<< testImgPath << " doesn't exit or can't be opened !"<<endl;
// continue;
}
if(imgNo > keyframeList.size()){
cout << "key frame No " << imgNo << "doesn't exist" << endl;
return -1;
}
image = keyframeList.at(imgNo);
//IplImage* image = cvLoadImage("0.jpg");
//cvShowImage("keyframe",image);
//start = clock();
myCeddFeature.extract(image);
similarImgPaths = myLshRetrieve.query(myCeddFeature.qCEDD,imgNumberToShow);
///for test
/* finish = clock();
duration = (double)(finish - start) / CLOCKS_PER_SEC;
cout<< "img retrieve costs : "<< duration <<" seconds" <<endl;*/
/*
for(int i=0;i<5;i++){
string simImgPath = imgDataFilePath + similarImgPaths.at(i);
simImgs[i] = cvLoadImage(simImgPath.c_str());
char imgWindowName[1000];
sprintf(imgWindowName,windowName,i);
// cvShowImage(imgWindowName,simImgs[i]);
}*/
IplImage* simImg = NULL;
for(int i=0;i<imgNumberToShow;i++){
string simImgPath = imgDataFilePath + similarImgPaths.at(i);
if(!(simImg = cvLoadImage(simImgPath.c_str()))){
cout<< simImgPath <<"can't load"<<endl;
continue;
}
char imgRetrievalResultPath[1000];
sprintf(imgRetrievalResultPath,imgRetrievalResultFilePath,i);
// cvSaveImage(imgRetrievalResultPath,simImg);
}
if(simImg != NULL){
cvReleaseImage(&simImg);
}
string videoMD5filePath = "md5.txt";
ofstream videoMD5file(videoMD5filePath.c_str());
for(int i=0;i<imgNumberToShow;i++){
int dotPostion = similarImgPaths.at(i).find(".");
string md5 = similarImgPaths.at(i).substr(0,dotPostion);
cout << md5 << endl;
videoMD5file << md5 << endl;
}
videoMD5file.close();
/* int key = cvWaitKey(2000);
if(key == 27){
break;
}*/
//system("PAUSE");
//}
if(image != NULL){
cvReleaseImage(&image);
}
vector<string> emptySimilarImgs;
similarImgPaths.swap(emptySimilarImgs);
similarImgPaths.clear();
cvWaitKey(-1);
//system("pause");
return 0;
}
void test(){
//cvNamedWindow("keyframe");
/*IplImage* simImg1 = NULL;
IplImage* simImg2 = NULL;
IplImage* simImg3 = NULL;
IplImage* simImg4 = NULL;
IplImage* simImg5 = NULL;*/
char* testImgFilePath = "../%d.jpg";
char* windowName = "showSimImg%d";
int windowHeight = 200;
int windowWidth = 200;
for(int i=0;i<1;i++){
char imgWindowName[1000];
sprintf(imgWindowName,windowName,i);
cvNamedWindow(imgWindowName,0);
cvResizeWindow(imgWindowName,windowWidth,windowHeight);
cvMoveWindow(imgWindowName,i*250,100);
}
IplImage* simImgs[5] = {NULL};
string imgDataFilePath = "extractImg/";
for(int i=0;i<1;i++){
char simImgPath[1000];// = imgDataFilePath +i+ ".jpg";
sprintf(simImgPath,testImgFilePath,i);
simImgs[i] = cvLoadImage(simImgPath);
char imgWindowName[1000];
sprintf(imgWindowName,windowName,i);
cvShowImage(imgWindowName,simImgs[i]);
}
cvWaitKey(-1);
}