File size: 9,867 Bytes
bce4323
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
<!DOCTYPE html>
<html>
<head>

	<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
	<meta http-equiv="Pragma" content="no-cache" />
	<meta http-equiv="Expires" content="0" />
	<meta charset="utf-8" />
	<title>ATUALLI MOSAICO WEB</title>
	<style>

		.center {
			margin-left: auto;
			margin-right: auto;
		}

		.holder_default {
			width: 560px;
			height: 350px;
			border: 4px dashed #ccc;
		
		}

		#holder.hover {
			width: 560px;
			height: 350px;
			border: 4px dashed #0c0 !important;
		}

		.hidden {
			display: none;
		}

		.visible {
			display: block;
		}

		* {
			box-sizing: border-box;
		}

		.menu {
			float: left;
			width: 20%;
		}

		.menuitem {
			padding: 8px;
			margin-top: 7px;
			border-bottom: 1px solid #f1f1f1;
		}

		.main {
			float: left;
			width: 60%;
			padding: 0 20px;
			overflow: hidden;
		}

		.right {
			//background-color: lightblue;
			float: left;
			width: 20%;
			padding: 10px 15px;
			margin-top: 7px;
		}

		@media only screen and (max-width:1000px) {
			/* For tablets: */
			.main {
				width: 80%;
				padding: 0;
			}

			.right {
				width: 100%;
			}
		}

		@media only screen and (max-width:800px) {
			/* For mobile phones: */
			.menu, .main, .right {
				width: 100%;
			}
		}

	</style>

</head>


<head>
	<title> HTML 5 </title>
	<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.js"></script>
</head>
<body>

	<!--table style="width:100%" class="center">
		<div style="text-align: center">
			<h1>Seleciona a imagem para Reconhecimento</h1>
		</div>
		<tr>
			<td style="width:100%" class="center">
				<form name="myForm" id="myForm" enctype="multipart/form-data" method="post" action="javascript:actionTensor()">
					<div class="row">
						<input type="file" name="filesToUpload[]" id="filesToUpload" multiple="multiple" />
						<output id="filesInfo"></output>
					</div>

					<div id="holder" style="" id="holder" class="holder_default">
						<img src="" id="image_droped" style="width:100%;display:none;" />
						<canvas id="canvas_droped" style="width:100%;display:block;"></canvas>
					</div>

					<div class="row">
						<input type="submit" value="Submit" />
					</div>
				</form>
				<textarea rows="20" cols="75" id="result"> RESULTADO </textarea>
			</td>

		</tr>
	</table-->

	<div style="background-color:#f1f1f1;padding:15px;">
		<h1>Selecione a imagem para Reconhecimento</h1>
	</div>

	<div style="overflow:auto">
		

		<div class="main">
			<form name="myForm" id="myForm" enctype="multipart/form-data" method="post" action="javascript:actionTensor()">
				<div class="row">
					<input type="file" name="filesToUpload[]" id="filesToUpload" multiple="multiple" />
					<output id="filesInfo"></output>
				</div>

				<div id="holder" style="" id="holder" class="holder_default">
					<img src="" id="image_droped" style="width:100%;display:none;" />
					<canvas id="canvas_droped" style="width:100%;display:block;"></canvas>
				</div>

				<div class="row">
					<label><input name="ftol" id="ftol" type="text" value="0.0" placeholder="Tolerancia">Tolerancia</label><br>
					<label><input name="area" id="area" type="text" value="0.0" placeholder="Area">Area</label><br>
					<div class="row">
                        <select id="idprovider" name="provider">
                            <option value="Tensor" selected>Tensor</option>
                            <option value="Google">Google</option>
                            <option value="HugFace">HugFace</option>
                            <option value="Tensor+Google">Tensor+Google</option>
                            <option value="Tensor+HugFace">Tensor+HugFace</option>
                            <option value="Tensor+Scylla">Tensor+Scylla</option>
                        </select>
					</div>

					<div class="row">
						<select id="idobjeto" name="objetos">
							<option value="Tudo" selected>Tudo</option>
							<option value="Pessoas">Pessoas</option>
							<option value="Veiculos">Veiculos</option>
							<option value="Pessoas+Veiculos">Pessoas+Veiculos</option>
							<option value="Placas">Placas</option>
						</select>
					</div>
					<input type="submit" value="Submit" />
				</div>
				
			</form>
		</div>

		<div class="right">
			<textarea rows="20" cols="50" id="result"> RESULTADO </textarea>
		</div>
	</div>


	<script>

	var espera = 0;

	function drawLine(ctx, x, y, stopX, stopY, color) {
		//ctx.clearRect(0, 0, can.width, can.height);
		ctx.strokeStyle = color;
		ctx.beginPath();
		ctx.moveTo(x, y);
		ctx.lineTo(stopX, stopY);
		ctx.closePath();
		ctx.stroke();

	}
	function drawBox(ctx, x, y, x2, y2, color) {
		//ctx.clearRect(0, 0, can.width, can.height);
		//ctx.strokeStyle = color;
		//ctx.beginPath();
		//ctx.rect(x, y, stop, stopY);
		//ctx.closePath();
	//	ctx.stroke();

		ctx.beginPath();
		ctx.lineWidth = "2";
		ctx.strokeStyle = color;
		ctx.rect(x, y, x2, y2);
		ctx.stroke();

	}

	//----------App.js---------------------//
	$(document).ready(function () {
		var holder = document.getElementById('holder');
		holder.ondragover = function () { this.className = 'hover'; return false; };
		holder.ondrop = function (e) {
			//this.className = 'hidden';
			e.preventDefault();
			var file = e.dataTransfer.files[0];
			var reader = new FileReader();
			reader.onload = function (event) {
			//	document.getElementById('text_droped').className = 'hidden';
				//document.getElementById('image_droped').className = 'visible';
				$('#image_droped').attr('src', event.target.result);
				var img = document.getElementById("image_droped");
				img.onload = function () {

					var c = document.getElementById("canvas_droped");
					var ctx = c.getContext("2d");
					c.setAttribute('width', 560);
					c.setAttribute('height', 350);
					ctx.drawImage(img, 0, 0, 560, 350);
					//	drawBox(ctx, 0, 0, 200, 200, 'green');
					document.myForm.submit();
				}
			}
			reader.readAsDataURL(file);
		};
	});


	function fileSelect(evt) {
		if (window.File && window.FileReader && window.FileList && window.Blob) {
			var files = evt.target.files;

			var result = '';
			var file;
			for (var i = 0; file = files[i]; i++) {
				// if the file is not an image, continue
				if (!file.type.match('image.*')) {
					continue;
				}

				reader = new FileReader();
				reader.onload = (function (tFile) {
					return function (evt) {
						//	document.getElementById('text_droped').className = 'hidden';
						var holder = document.getElementById('holder');
						holder.className = 'hover';
					//	document.getElementById('image_droped').className = 'visible';
						$('#image_droped').attr('src', event.target.result);
						var img = document.getElementById("image_droped");

						img.onload = function () {

							var c = document.getElementById("canvas_droped");
							var ctx = c.getContext("2d");
							c.setAttribute('width', 560);
							c.setAttribute('height', 350);
							ctx.drawImage(img, 0, 0, 560, 350);
							//	drawBox(ctx, 0, 0, 200, 200, 'green');
							document.myForm.submit();
						}

					};
				}(file));
				reader.readAsDataURL(file);
			}
		} else {
			alert('The File APIs are not fully supported in this browser.');
		}
	}

	function actionTensor()
	{
	
			document.getElementById('result').value = 'AGUARDE...';

			var xhttp = new XMLHttpRequest();

			xhttp.onload = function (e) {

				espera = 0;
				var img = document.getElementById("image_droped");

				var json = JSON.parse(this.responseText);
				var wi = 560;
				var hi = 350;

				var c = document.getElementById("canvas_droped");
				var ctx = c.getContext("2d");
				ctx.drawImage(img, 0, 0, 560, 350);
				var color = "#32CD32"
				for (var i = 0; i < json.tensorflow.length; i++) {
					var nome = json.tensorflow[i].nome;
					var score = json.tensorflow[i].score;
					var x = json.tensorflow[i].x * wi;
					var y = json.tensorflow[i].y * hi;
					var h = json.tensorflow[i].h * hi;
					var w = json.tensorflow[i].w * wi;
					var classe = json.tensorflow[i].classe;


					drawBox(ctx, x, y, w, h, color);
					ctx.fillStyle = color;
					ctx.font = "14px Arial";
					ctx.fillText(nome + " (" + classe + ") " + score + " ", x, y - 4);
				}

				document.getElementById('result').value = this.responseText;

			};
			xhttp.onerror = function (e) {
				espera = 0;
				document.getElementById('result').value = "ERRO: Tente Novamente..";
			};

		
			var ftol = document.getElementById('ftol').value;
			var farea = document.getElementById('area').value;
			var dvideo = "http://192.168.0.19:8121/upfoto";
		 //   //var dvideo = "http://192.168.0.19:8121/upfoto?ftol="+ftol+"&farea="+farea+"&";
		//	var dvideo = "http://painel.atualli.com:8087/upfoto?ftol=" + ftol + "&farea=" + farea + "&";

			var videoobj = document.getElementById("image_droped");
			var video = videoobj.getAttribute('src');

			var provider = document.getElementById("idprovider").value;
			var objeto = document.getElementById("idobjeto").value;

			var widthx = videoobj.width;
			var heightx = videoobj.height;
			var json = JSON.stringify({ "image": video, "ftol": ftol, "farea": farea, "provider": provider, "objetos": objeto, "width": "" + widthx + "", "height": "" + heightx + "" });
		
			xhttp.open("POST", dvideo, true);
		//	xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xhttp.setRequestHeader("Accept", "application/json");
		//	xhttp.setRequestHeader("Content-Type", "application/json");
			

			xhttp.send(json);
		//	xhttp.send(video);
			espera = 1;
		
	}

	function fespera()
	{
		if (espera > 0) {

			document.getElementById('result').value = "AGUARDE.." + espera;
			espera++;
		}
		setTimeout(fespera, 1000);

	}

	document.getElementById('filesToUpload').addEventListener('change', fileSelect, false);
	fespera();
	</script>
</body>
</html>