p_ml.js
5.58 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
const { ipcRenderer } = require("electron");
const { BrowserWindow } = require("electron").remote;
const content = document.getElementById('content');
const btn = document.getElementById('start');
const next = document.getElementById('next');
const Chart = require("chart.js");
const ctx = document.getElementById("chart").getContext('2d');;
var list_length = new Array();
let l_list = new Array();
let p_list = new Array();
var mysql = require('mysql');
var list;
//mysql 연동
var connection = mysql.createConnection({
user:'root',
password:'1234',
database : 'dataextraction'
})
connection.connect();
btn.addEventListener("click", ()=>{
content.innerHTML = '<i class="fas fa-spinner fa-3x fa-spin" style="color:dimgray; position: absolute; bottom:45%; right:45%;"></i>';
connection.query("SELECT * FROM photo" , function(error, results, fields){
if(error){
}
else{
list = results;
//이미지 라벨링 요청
ipcRenderer.send('image_labels', list );
}
});
})
var label_name = Array();
var photo_list = Array();
var label_result = Array();
//라벨링 결과 획득 및 이미지 그룹화 시작
ipcRenderer.on("labels_result", (e, result) => {
var myHTML = '';
label_result = result;
//print photo with labels
result.forEach(element=>{
myHTML +="<div class='photo'><div class='p_title'><p>"+element.name+"</p></div>"
myHTML += '<div class="image"><img src="'+element.path+'"></div><div class ="labels">';
element.labels.forEach(label=>{
myHTML+='<p> #'+label.description+'</p>';
find_labellist(label.description, element.path);
});
myHTML+='</div></div>';
})
content.innerHTML = myHTML;
sort_labellist();
});
//이미지 그룹화
function find_labellist(label, path){
var idx = label_name.indexOf(label);
if(idx == -1){
label_name.push(label);
photo_list.push([path.toString()]);
}
else{
photo_list[idx].push(path.toString());
}
}
//라벨 리스트 정렬 (라벨 순위)
function sort_labellist(){
for(var i =0; i< photo_list.length; i++){
for(var j = i+1; j <photo_list.length; j++){
if(photo_list[j].length > photo_list[i].length){
var tmp = Array();
tmp = photo_list[i];
photo_list[i] = photo_list[j];
photo_list[j] = tmp;
var str = String();
str = label_name[i];
label_name[i] = label_name[j];
label_name[j] = str;
}
}
}
l_list = label_name;
p_list = photo_list;
myHTML = String();
photo_list.forEach(element => {
list_length.push(element.length);
});
//차트 생성
var mychart = new Chart(ctx,{
type: 'horizontalBar',
data :{
labels : label_name.slice(0, 20),
datasets:[{
label : "nums of images",
data : list_length.slice(0, 20),
borderSkipped:'top',
borderWidth :1,
borderColor : '#4e73df',
backgroundColor:'#4e73df',
hoverBorderWidth: 2,
barPercentage: 0.8,
categoryPercentage:1,
}],
},
options:{
maintainAspectRatio: false,
title: {
display: true,
text: 'PHOTO KEYWORD'
},
scales: {
xAxes: [{
stacked: true,
gridLines:{
offsetGridLines :true,
},
ticks:{
beginAtZero :true
}
}],
yAxes: [{
ticks :{
fontSize : 10
},
stacked: true,
}]
},
tooltips: {
callbacks: {
labelColor: function(tooltipItem, chart) {
return {
borderColor : '#4e73df',
backgroundColor:'#4e73df',
};
},
labelTextColor: function(tooltipItem, chart) {
return '#FFFFFF';
}
}
},
onClick : function(e){
//라벨 차트에서 라벨 클릭 시 해장 라벨을 가진 사진 모두 출력
var activePoints = mychart.getElementsAtEvent(e);
var idx= activePoints[0]._index;
var myHTML = '<div class="keyword"><h1>#'+label_name[idx]+'</h1></div><div class="k_content">';
photo_list[idx].forEach(photo=>{
myHTML += '<div class="keyword_photo"><img src="'+photo+'"></div>';
});
myHTML+="</div>"
document.getElementById("next").style.visibility = "visible";
content.style.overflowY = "hidden";
content.innerHTML = myHTML;
},
layout:{
padding:{
left:0,
right:0,
top:10,
bottom:0,
}
}
}
})
}
//print all photos with labels
next.addEventListener("click", ()=>{
var myHTML = '';
label_result.forEach(element=>{
myHTML +="<div class='photo'><div class='p_title'><p>"+element.name+"</p></div>"
myHTML += '<div class="image"><img src="'+element.path+'"></div><div class ="labels">';
element.labels.forEach(label=>{
myHTML+='<p> #'+label.description+'</p>';
});
myHTML+='</div></div>';
})
content.innerHTML = myHTML;
document.getElementById("next").style.visibility = "hidden";
content.style.overflowY = "auto";
});