Spaces:
Sleeping
Sleeping
Update doors_fasterrcnn.py
Browse files- doors_fasterrcnn.py +26 -3
doors_fasterrcnn.py
CHANGED
|
@@ -105,6 +105,9 @@ def get_door_info(doors_info):
|
|
| 105 |
lines = []
|
| 106 |
sanda = []
|
| 107 |
line_midpoint = []
|
|
|
|
|
|
|
|
|
|
| 108 |
single_door = 0
|
| 109 |
for door_inf in doors_info:
|
| 110 |
xmin, ymin, xmax, ymax = door_inf[0]
|
|
@@ -169,7 +172,19 @@ def get_door_info(doors_info):
|
|
| 169 |
width = distance((xmin,ymin), (xmin,ymax))
|
| 170 |
width_pixels.append(width)
|
| 171 |
|
| 172 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
|
| 174 |
def pxl2meter(width_pixels, ratio):
|
| 175 |
real_width = []
|
|
@@ -238,7 +253,7 @@ def adjustannotations(OutputPdfStage1):
|
|
| 238 |
print("Annotations updated and saved ")
|
| 239 |
return output_pdf_io.read()
|
| 240 |
|
| 241 |
-
def add_annotations_to_pdf(image, pdf_name, lines, sanda, char_width, line_midpoint):
|
| 242 |
image_width, image_height = image.size
|
| 243 |
|
| 244 |
# Create a new PDF document
|
|
@@ -276,6 +291,14 @@ def add_annotations_to_pdf(image, pdf_name, lines, sanda, char_width, line_midpo
|
|
| 276 |
annot.set_border(width=2, dashes=None) # Optional border styling
|
| 277 |
annot.set_colors(stroke=(1, 0, 0)) # Set the line color to red
|
| 278 |
annot.update()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 279 |
# annot = page.add_line_annot(lines[i][0], lines[i][1])
|
| 280 |
# # annot = page.add_line_annot(sanda[i][0], lines[i][0])
|
| 281 |
# # annot = page.add_line_annot(sanda[i][1], lines[i][1])
|
|
@@ -333,7 +356,7 @@ def main_run(img_pillow,pdf_fullpath, weights_path, pdf_name,pdfpath,ratio): ###
|
|
| 333 |
|
| 334 |
# START INFERENCE
|
| 335 |
doors_info = ev_model(img_pillow, model, device, 0.9)
|
| 336 |
-
width_pixels, lines, sanda, line_midpoint = get_door_info(doors_info)
|
| 337 |
real_width = pxl2meter(width_pixels, ratio)
|
| 338 |
char_width = width_as_char(real_width)
|
| 339 |
|
|
|
|
| 105 |
lines = []
|
| 106 |
sanda = []
|
| 107 |
line_midpoint = []
|
| 108 |
+
doubleD_bbox = []
|
| 109 |
+
doubleD_width = []
|
| 110 |
+
|
| 111 |
single_door = 0
|
| 112 |
for door_inf in doors_info:
|
| 113 |
xmin, ymin, xmax, ymax = door_inf[0]
|
|
|
|
| 172 |
width = distance((xmin,ymin), (xmin,ymax))
|
| 173 |
width_pixels.append(width)
|
| 174 |
|
| 175 |
+
#double door
|
| 176 |
+
if door_inf[1] == 1:
|
| 177 |
+
doubleD_bbox.append([int(xmin), int(ymin), int(xmax), int(ymax)])
|
| 178 |
+
bbox_width = xmax - xmin
|
| 179 |
+
bbox_height = ymax - ymin
|
| 180 |
+
if bbox_width > bbox_height:
|
| 181 |
+
door_width = bbox_width
|
| 182 |
+
doubleD_width.append(door_width)
|
| 183 |
+
else:
|
| 184 |
+
door_width = bbox_height
|
| 185 |
+
doubleD_width.append(door_width)
|
| 186 |
+
|
| 187 |
+
return width_pixels, lines, sanda, line_midpoint, doubleD_bbox, doubleD_width
|
| 188 |
|
| 189 |
def pxl2meter(width_pixels, ratio):
|
| 190 |
real_width = []
|
|
|
|
| 253 |
print("Annotations updated and saved ")
|
| 254 |
return output_pdf_io.read()
|
| 255 |
|
| 256 |
+
def add_annotations_to_pdf(image, pdf_name, lines, sanda, char_width, line_midpoint, doubleD_bbox):
|
| 257 |
image_width, image_height = image.size
|
| 258 |
|
| 259 |
# Create a new PDF document
|
|
|
|
| 291 |
annot.set_border(width=2, dashes=None) # Optional border styling
|
| 292 |
annot.set_colors(stroke=(1, 0, 0)) # Set the line color to red
|
| 293 |
annot.update()
|
| 294 |
+
for i in range(len(doubleD_bbox)):
|
| 295 |
+
# rect_coords should be a tuple: (x1, y1, x2, y2)
|
| 296 |
+
rect = fitz.Rect(fitz.Point(*doubleD_bbox[i])* derotationMatrix)
|
| 297 |
+
rect_annot = page.add_rect_annot(rect)
|
| 298 |
+
rect_annot.set_border(width=2) # Adjust border width
|
| 299 |
+
rect_annot.set_colors(stroke=(1, 0, 0)) # Red rectangle
|
| 300 |
+
rect_annot.update()
|
| 301 |
+
|
| 302 |
# annot = page.add_line_annot(lines[i][0], lines[i][1])
|
| 303 |
# # annot = page.add_line_annot(sanda[i][0], lines[i][0])
|
| 304 |
# # annot = page.add_line_annot(sanda[i][1], lines[i][1])
|
|
|
|
| 356 |
|
| 357 |
# START INFERENCE
|
| 358 |
doors_info = ev_model(img_pillow, model, device, 0.9)
|
| 359 |
+
width_pixels, lines, sanda, line_midpoint, doubleD_bbox, doubleD_width = get_door_info(doors_info)
|
| 360 |
real_width = pxl2meter(width_pixels, ratio)
|
| 361 |
char_width = width_as_char(real_width)
|
| 362 |
|