-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFinalOutput.cpp
More file actions
193 lines (125 loc) · 4.47 KB
/
Copy pathFinalOutput.cpp
File metadata and controls
193 lines (125 loc) · 4.47 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
#include "myheader.h"
#include "groundtruth.h"
#include "ui_groundtruth.h"
#include "QMessageBox"
/*---------------------------------Writng Final Output Files of Ground Truth-------------------------------------*/
IITkgp_functions::folder fol;
void writexml(char *xmlname, char *labelimage, int numlabel)
{
IITkgp_functions::ImageProcFunc ipf;
FILE *fp;
char *name;
fp = fopen(xmlname,"w");
fprintf(fp,"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
time_t now = time(0);
struct tm tstruct;
char buf[80];
tstruct = *localtime(&now);
// Visit http://en.cppreference.com/w/cpp/chrono/c/strftime
// for more information about date/time format
strftime(buf, sizeof(buf), "%d-%m-%Y", &tstruct);
fprintf(fp,"<Anveshwak vertion=\"1.1\" date=\"%s\" >\n",buf);
fprintf(fp,"\t<Document name =\"%s\" height =\"%d\" width =\"%d\">\n",imagename,src.rows,src.cols);
fprintf(fp,"\t\t<Annotation name=\"%s\" labels=\"%d\"> \n",labelimage,numlabel);
for(int i=0;i<Labels.size();i++)
{
string labelname = Labels[i].toUtf8().constData();
name = (char *)malloc(4000*sizeof(char));
strcpy(name,labelname.c_str());
int number = ipf.NumberofForegroundPixel(LabelImages[i]);
if(number > 0)
{
fprintf(fp,"\t\t\t<Labels name=\"%s\" index=\"%d\"> </Labels>\n",name,i);
}
}
fprintf(fp,"\t\t</Annotation>\n");
fprintf(fp,"\t</Document>\n");
fprintf(fp,"</Anveshwak>");
fclose(fp);
}
void IITkgp_functions::WriteOutput::FinalOutput(void)
{
QMessageBox::information(0,"Final Output","All Processing Blocks are labelled and Writing the Final Label Output");
printf("All Labeling Is Done\n");
QString foldername;
foldername = QString::fromLocal8Bit(substring);
char *name;
IITkgp_functions::ImageProcFunc ipf;
/*
for(int i=0;i<Labels.size();i++)
{
int number = ipf.NumberofForegroundPixel(LabelImages[i]);
if(number > 0)
{
QString s;
//s = foldername+"_Label_"+Labels[i]+".png";
s = "Label_"+Labels[i]+".png";
string tes = s.toUtf8().constData();
char *ss;
ss = (char *)malloc(4000*sizeof(char));
strcpy(ss,tes.c_str());
name = (char *)malloc(4000*sizeof(char));
name = fol.CreateNameIntoFolder(substring,ss);
imwrite(name,LabelImages[i]);
}
//free(tempname);
//free(name);
}
*/
// char *temps;
// temps = (char *)malloc(4000*sizeof(char));
//temps = substring;
//strcat(temps,"_LabelAllInOne.png");
name = (char *)malloc(4000*sizeof(char));
//name = fol.CreateNameIntoFolder(substring,temps);
name = fol.CreateNameIntoFolder(substring,"LabelAllInOne.png");
char *labelimgname = name;
imwrite(name,LabelImageInOne);
LabelImageInOne.release();
//
// temps = (char *)malloc(4000*sizeof(char));
// temps = substring;
// strcat(temps,"_info.txt");
name = (char *)malloc(4000*sizeof(char));
name = fol.CreateNameIntoFolder(substring,"Imageinfo.txt");
FILE *fp;
fp = fopen(name,"w");
fprintf(fp,"LabelName\tLabelNumber\tNumberOfPB\tNumberOfPixel\n");
int numoflabels = 0;
for(int i=0;i<Labels.size();i++)
{
string labelname = Labels[i].toUtf8().constData();
name = (char *)malloc(4000*sizeof(char));
strcpy(name,labelname.c_str());
int number = ipf.NumberofForegroundPixel(LabelImages[i]);
if(number > 0)
{
numoflabels = numoflabels + 1;
fprintf(fp,"%s\t%d\t%d\t%d\n",name,i,LabelCount[i],number);
}
}
fclose(fp);
// Create XML File
name = (char *)malloc(4000*sizeof(char));
name = fol.CreateNameIntoFolder(substring,"Imageinfo.xml");
writexml(name,labelimgname,numoflabels);
QMessageBox::information(0,"Final Output","All Processing are done");
/*************************************Release Memory************************************************/
free(substring);
free(tempname);
contours.clear();
hierarchy.clear();
free(LabelFlag);
free(LabelCount);
for(int i=0;i<Labels.size();i++)
free(LabelColor[i]);
free(LabelColor);
ColorLabelImage.release();
Blocks.clear();
src.release();
src_binary.release();
src_ub.release();
src_gray.release();
src_ROI.release();
LabelImages.clear();
}