Spaces:
Sleeping
Sleeping
Update doors_fasterrcnn.py
Browse files- doors_fasterrcnn.py +15 -3
doors_fasterrcnn.py
CHANGED
|
@@ -253,7 +253,7 @@ def adjustannotations(OutputPdfStage1):
|
|
| 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
|
|
@@ -284,6 +284,16 @@ def add_annotations_to_pdf(image, pdf_name, lines, sanda, char_width, line_midpo
|
|
| 284 |
annot = page.add_freetext_annot(rect, text, fontsize=10, fontname="helv", text_color=(1, 0, 0))
|
| 285 |
annot.update()
|
| 286 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 287 |
#Annotation for drawin lines as in the markups
|
| 288 |
for i in range(len(lines)):
|
| 289 |
l_points = [fitz.Point(*sanda[i][0])* derotationMatrix, fitz.Point(*lines[i][0])* derotationMatrix, fitz.Point(*lines[i][1])* derotationMatrix, fitz.Point(*sanda[i][1])* derotationMatrix]
|
|
@@ -388,14 +398,16 @@ def main_run(img_pillow,pdf_fullpath, weights_path, pdf_name,pdfpath,ratio): ###
|
|
| 388 |
doors_info = ev_model(img_pillow, model, device, 0.9)
|
| 389 |
width_pixels, lines, sanda, line_midpoint, doubleD_bbox, doubleD_width = get_door_info(doors_info)
|
| 390 |
real_width = pxl2meter(width_pixels, ratio)
|
|
|
|
| 391 |
char_width = width_as_char(real_width)
|
|
|
|
| 392 |
|
| 393 |
pdf_document = add_annotations_to_pdf(img_pillow, pdf_fullpath, lines, sanda, char_width, line_midpoint, doubleD_bbox)
|
| 394 |
modified_pdf_data = pdf_document.tobytes()
|
| 395 |
OutputPdfStage2=adjustannotations(modified_pdf_data)
|
| 396 |
#Dataframe for Doors count
|
| 397 |
-
|
| 398 |
-
doors_count = {'Type': ['Single Doors'], 'Quantity': [len(real_width)]}
|
| 399 |
df_doors = pd.DataFrame(doors_count)
|
| 400 |
|
| 401 |
doc2 =fitz.open('pdf',OutputPdfStage2)
|
|
|
|
| 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, char_d_width):
|
| 257 |
image_width, image_height = image.size
|
| 258 |
|
| 259 |
# Create a new PDF document
|
|
|
|
| 284 |
annot = page.add_freetext_annot(rect, text, fontsize=10, fontname="helv", text_color=(1, 0, 0))
|
| 285 |
annot.update()
|
| 286 |
|
| 287 |
+
for i in range(len(doubleD_bbox)):
|
| 288 |
+
#a7seb ana el midpoint beta3 el bbox 3ashan a7ot el width feha
|
| 289 |
+
x,y = calculate_midpoint((doubleD_bbox[i][0], doubleD_bbox[i][1]), (doubleD_bbox[i][2],doubleD_bbox[i][3]))
|
| 290 |
+
p_midpoint = fitz.Point(x, y) * derotationMatrix
|
| 291 |
+
rect = fitz.Rect(p_midpoint.x, p_midpoint.y, p_midpoint.x + 200, p_midpoint.y + 50)
|
| 292 |
+
text = char_d_width[i]
|
| 293 |
+
annot = page.add_freetext_annot(rect, text, fontsize=10, fontname="helv", text_color=(1, 0, 0))
|
| 294 |
+
annot.update()
|
| 295 |
+
|
| 296 |
+
|
| 297 |
#Annotation for drawin lines as in the markups
|
| 298 |
for i in range(len(lines)):
|
| 299 |
l_points = [fitz.Point(*sanda[i][0])* derotationMatrix, fitz.Point(*lines[i][0])* derotationMatrix, fitz.Point(*lines[i][1])* derotationMatrix, fitz.Point(*sanda[i][1])* derotationMatrix]
|
|
|
|
| 398 |
doors_info = ev_model(img_pillow, model, device, 0.9)
|
| 399 |
width_pixels, lines, sanda, line_midpoint, doubleD_bbox, doubleD_width = get_door_info(doors_info)
|
| 400 |
real_width = pxl2meter(width_pixels, ratio)
|
| 401 |
+
real_double = pxl2meter(doubleD_width, ratio)
|
| 402 |
char_width = width_as_char(real_width)
|
| 403 |
+
char_d_width = width_as_char(real_double)
|
| 404 |
|
| 405 |
pdf_document = add_annotations_to_pdf(img_pillow, pdf_fullpath, lines, sanda, char_width, line_midpoint, doubleD_bbox)
|
| 406 |
modified_pdf_data = pdf_document.tobytes()
|
| 407 |
OutputPdfStage2=adjustannotations(modified_pdf_data)
|
| 408 |
#Dataframe for Doors count
|
| 409 |
+
doors_count = {'Type': ['Single Doors', 'Double Doors'], 'Quantity': [len(real_width), len(real_double)]}
|
| 410 |
+
#doors_count = {'Type': ['Single Doors'], 'Quantity': [len(real_width)]}
|
| 411 |
df_doors = pd.DataFrame(doors_count)
|
| 412 |
|
| 413 |
doc2 =fitz.open('pdf',OutputPdfStage2)
|