show_image_old_working.html 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <!doctype html>
  2. <head>
  3. <title>Dimension Extraction</title>
  4. <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}"/>
  5. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  6. <script src="https://unpkg.com/pdfjs-dist@latest/build/pdf.min.js"></script>
  7. </head>
  8. <body>
  9. <!--<div class="split left">-->
  10. <div class="container">
  11. <div class="column column-one">
  12. <h1>Drawing</h1>
  13. <p> <a href="http://localhost:5000/"> Upload another drawing </a> </p>
  14. {% if filename %}
  15. <div class="images">
  16. <img id="drawing" src="{{ url_for('send_file', filename=filename) }}">
  17. </div>
  18. <!-- <input type="file" id="pdf-upload"/>
  19. <hr/>
  20. <canvas class="frame"></canvas>-->
  21. {% else %}
  22. <h1>no image for whatever reason</h1>
  23. {% endif %}
  24. </div>
  25. <!--<div class="split middle">-->
  26. <div class="column column-two" id="measurements">
  27. <h1>Extracted Measurements</h1>
  28. <font size="3" face="Courier New" >
  29. <form>
  30. <table>
  31. <tr>
  32. <td style="text-align:center"><h3>Key Value</h3></td>
  33. <td style="text-align:center"><h3>Target Value</h3></td>
  34. <td style="text-align:center"><h3>Actual Value</h3></td>
  35. <td style="text-align:center"><h3>Relevant Isos</h3></td>
  36. </tr>
  37. {{ text | safe}}
  38. <!-- {% for key in dims %}
  39. <td><h4> {{key}} </h4></td>
  40. {% for d in dims[key] %}
  41. <tr>
  42. <td style="text-align:center"><input type="checkbox" name="relevant[]" value="checked"></td>
  43. <td style="text-align:center"> {{ d }}</td>
  44. <td style="text-align:center"><input type="text" name="{{ d }}" size="10"></td>
  45. </tr>
  46. {% endfor %}
  47. {% endfor %}-->
  48. </table>
  49. </form>
  50. </font>
  51. <div id="result">Result {{ number }}</div>
  52. </div>
  53. <!--<div class="split right">-->
  54. <div class="column column-three">
  55. <h1>Additional Infos</h1>
  56. {{ links }}
  57. </div>
  58. </div>
  59. <script>
  60. function set_redis(key, value) {
  61. $.ajax({
  62. type: "POST",
  63. url: "/redis/set/" + key,
  64. data: JSON.stringify({ value: value }),
  65. dataType: "json",
  66. contentType: "json",
  67. success: function(data)
  68. {
  69. (data.GET);
  70. }
  71. });
  72. }
  73. function get_redis(key) {
  74. $.ajax({
  75. type: "GET",
  76. url: "redis/get/" + key,
  77. data: "format=json",
  78. dataType: "text",
  79. success: function(data)
  80. {
  81. $("#result").text(data.GET);
  82. }
  83. });
  84. }
  85. </script>
  86. <script>
  87. $(document).ready(function(){
  88. $("input[type=number]").on("change keyup input", function(){
  89. var array_value = [];
  90. array_value[0] = $(this).attr('name');
  91. array_value[1] = $(this).val();
  92. var key = 'last' + "_" +'{{og_filename}}';
  93. //console.log({{ dim }});
  94. set_redis(key, array_value);
  95. });
  96. $("input[type=checkbox]").change(function(){
  97. // Print entered value in a div box
  98. $("#result").text($(this).attr('name'));
  99. var key1 = 'last' + "_" +'{{og_filename}}';
  100. var array_value1 = [];
  101. if ($(this).is(':checked')) {
  102. console.log($(this).attr('name') + ' is now checked');
  103. array_value1[0] = 'relevant.' + $(this).attr('name');
  104. array_value1[1] = true;
  105. } else {
  106. console.log($(this).attr('name') + ' is now unchecked');
  107. array_value1[0] = $(this).attr('name');
  108. array_value1[1] = false;
  109. }
  110. set_redis(key1, array_value1);
  111. });
  112. $("input[type=number]").focus(function(){
  113. // highlight values, does not work so far
  114. var number = $(this).attr('name');
  115. var coords = $(this).attr('data-coords');
  116. highlight_areas(coords, "red");
  117. var detail = $(this).attr('data-details');
  118. console.log(detail, "green");
  119. highlight_details(detail, "green");
  120. });
  121. $("input[type=number]").blur(function(){
  122. $("div").removeClass("red");
  123. $("div").removeClass("green");
  124. });
  125. function highlight_areas(coords, color){
  126. let w = {{w}}
  127. let h = {{h}}
  128. let pos = $("#drawing").position();
  129. let drawing_x = pos.left;
  130. let drawing_y = pos.top;
  131. let array_coords = coords.split(",");
  132. let coords_x = parseFloat(array_coords[0]);
  133. let coords_xmax = parseFloat(array_coords[2]);
  134. let coords_y = parseFloat(array_coords[1]);
  135. let coords_ymax = parseFloat(array_coords[3]);
  136. let coords_width = (coords_xmax - coords_x);
  137. let coords_height = (coords_ymax - coords_y);
  138. let width = $("#drawing").width();
  139. let height = $("#drawing").height();
  140. let rel_width = coords_width/h*width*1.4;
  141. let rel_height = coords_height/w*height*1.4;
  142. let x = width*(coords_x*height/width/w);
  143. let y = height*(coords_y*width/height/h);
  144. console.log(w, h, rel_width, rel_height,x,y);
  145. let $point1 = jQuery("<div class="+color+"/>").css({top: (drawing_y + y -5) + 'px', left: (drawing_x + x-5) + 'px', width: rel_width , height: rel_height});
  146. $(".images").append($point1);
  147. };
  148. function highlight_details(coords, color){
  149. let w = {{w}}
  150. let h = {{h}}
  151. let pos = $("#drawing").position();
  152. let drawing_x = pos.left;
  153. let drawing_y = pos.top;
  154. let array_coords = coords.split(",");
  155. let coords_x = parseFloat(array_coords[0]);
  156. let coords_y = parseFloat(array_coords[1]);
  157. let width_div = (parseFloat(array_coords[2]) - parseFloat(array_coords[0]));
  158. let height_div = (parseFloat(array_coords[3]) - parseFloat(array_coords[1]));
  159. let width = $("#drawing").width();
  160. let rel_width = width_div/h*width;
  161. let height = $("#drawing").height();
  162. let rel_height = height*height_div/w;
  163. let x = width*(coords_x*height/width/w);
  164. let y= height*(coords_y*width/height/h);
  165. console.log(rel_width, rel_height);
  166. if (array_coords[3] > 10000) {
  167. rel_height = height - y;
  168. }
  169. let $point = jQuery("<div class="+color+"/>").css({top: (drawing_y + y) + 'px', left: (drawing_x + x) + 'px', width: (rel_width) + 'px', height: (rel_height) + 'px'});
  170. $(".images").append($point);
  171. };
  172. });
  173. </script>
  174. </body>