Spaces:
Sleeping
Sleeping
Update doors_fasterrcnn.py
Browse files- doors_fasterrcnn.py +24 -73
doors_fasterrcnn.py
CHANGED
|
@@ -223,7 +223,7 @@ def pxl2meter(width_pixels, ratio):
|
|
| 223 |
def width_as_char(real_width):
|
| 224 |
char_width = []
|
| 225 |
for width in real_width:
|
| 226 |
-
char_width.append(f"{width}
|
| 227 |
return char_width
|
| 228 |
|
| 229 |
def adjustannotations(OutputPdfStage1):
|
|
@@ -343,72 +343,6 @@ def add_annotations_to_pdf(image, pdf_name, lines, sanda, char_width, line_midpo
|
|
| 343 |
annot.set_border(width=0.2, dashes=(1, 2)) # Optional border styling
|
| 344 |
annot.set_colors(stroke=(1, 0, 0), fill=None) # Set the stroke color to red
|
| 345 |
annot.update()
|
| 346 |
-
|
| 347 |
-
#for i in range(len(doubleD_bbox)):
|
| 348 |
-
# rect_coords should be a tuple: (x1, y1, x2, y2)
|
| 349 |
-
#tpl1 = (doubleD_bbox[i][0], doubleD_bbox[i][1])
|
| 350 |
-
#tpl2 = (doubleD_bbox[i][2], doubleD_bbox[i][3])
|
| 351 |
-
#tpl_derotated = fitz.Point(*tpl1) * derotationMatrix
|
| 352 |
-
#tpl2_derotated = fitz.Point(*tpl2) * derotationMatrix
|
| 353 |
-
#print("Derotated tuples:")
|
| 354 |
-
#print(tpl_derotated)
|
| 355 |
-
#print("Derotated tuples 2:")
|
| 356 |
-
#print(tpl2_derotated)
|
| 357 |
-
#coordinates_derotated = [tpl_derotated[0],tpl_derotated[1],tpl2_derotated[0],tpl2_derotated[1]]
|
| 358 |
-
#x1, y1 = tpl_derotated
|
| 359 |
-
#x2, y2 = tpl2_derotated
|
| 360 |
-
#x1 = int(x1)
|
| 361 |
-
#y1 = int(y1)
|
| 362 |
-
#x2 = int(x2)
|
| 363 |
-
#y2 = int(y2)
|
| 364 |
-
#x1, x2 = min(x1, x2), max(x1, x2)
|
| 365 |
-
#y1, y2 = min(y1, y2), max(y1, y2)
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
#print("x1:")
|
| 369 |
-
#print(x1)
|
| 370 |
-
#print("y1:")
|
| 371 |
-
#print(y1)
|
| 372 |
-
#print("x2:")
|
| 373 |
-
#print(x2)
|
| 374 |
-
#print("y2:")
|
| 375 |
-
#print(y2)
|
| 376 |
-
|
| 377 |
-
#rect = fitz.Rect(x1, y1, x2, y2)
|
| 378 |
-
#print("RECT:")
|
| 379 |
-
#print(rect)
|
| 380 |
-
#rect_annot = page.add_rect_annot(rect)
|
| 381 |
-
#rect_annot.set_border(width=2) # Adjust border width
|
| 382 |
-
#rect_annot.set_colors(stroke=(1, 0, 0)) # Red rectangle
|
| 383 |
-
#rect_annot.update()
|
| 384 |
-
|
| 385 |
-
# annot = page.add_line_annot(lines[i][0], lines[i][1])
|
| 386 |
-
# # annot = page.add_line_annot(sanda[i][0], lines[i][0])
|
| 387 |
-
# # annot = page.add_line_annot(sanda[i][1], lines[i][1])
|
| 388 |
-
# annot.set_border(width=2, dashes=None) # Optional border styling
|
| 389 |
-
# annot.set_colors(stroke=(1, 0, 0)) # Set the line color to red
|
| 390 |
-
# annot.update()
|
| 391 |
-
|
| 392 |
-
#annot = page.add_line_annot(fitz.Point(*lines[i][0]) * derotationMatrix, fitz.Point(*lines[i][1]) * derotationMatrix)
|
| 393 |
-
#annot.set_border(width=2, dashes=None) # Optional border styling
|
| 394 |
-
#annot.set_colors(stroke=(1, 0, 0)) # Set the line color to red
|
| 395 |
-
#annot.set_info(content=str(1.0)+' m',subject='Perimeter Measurement', title="ADR Team")
|
| 396 |
-
#annot.update()
|
| 397 |
-
|
| 398 |
-
#annot = page.add_line_annot(fitz.Point(*sanda[i][0]) * derotationMatrix, fitz.Point(*lines[i][0]) * derotationMatrix)
|
| 399 |
-
#annot.set_border(width=2, dashes=None) # Optional border styling
|
| 400 |
-
#annot.set_colors(stroke=(1, 0, 0)) # Set the line color to red
|
| 401 |
-
#annot.set_info(content=str(1.0)+' m',subject='Perimeter Measurement', title="ADR Team")
|
| 402 |
-
#annot.update()
|
| 403 |
-
|
| 404 |
-
#annot = page.add_line_annot(fitz.Point(*sanda[i][1]) * derotationMatrix, fitz.Point(*lines[i][1]) * derotationMatrix)
|
| 405 |
-
#annot.set_border(width=2, dashes=None) # Optional border styling
|
| 406 |
-
#annot.set_colors(stroke=(1, 0, 0)) # Set the line color to red
|
| 407 |
-
#annot.set_info(content=str(1.0)+' m',subject='Perimeter Measurement', title="ADR Team")
|
| 408 |
-
#annot.update()
|
| 409 |
-
# output_pdf_path = pdf_name+"_annotated.pdf"
|
| 410 |
-
# Save the PDF with annotations
|
| 411 |
-
|
| 412 |
page.set_rotation(rotationOld)
|
| 413 |
return pdf_document
|
| 414 |
|
|
@@ -463,12 +397,29 @@ def main_run(img_pillow,pdf_fullpath, weights_path, pdf_name,pdfpath,ratio): ###
|
|
| 463 |
|
| 464 |
df_doors = df_doors.fillna(' ')
|
| 465 |
gc,spreadsheet_service,spreadsheetId, spreadsheet_url , namepathArr=google_sheet_Legend.legendGoogleSheets(df_doors , pdf_name,pdfpath)
|
| 466 |
-
list1=pd.DataFrame(columns=['content', 'id', 'subject'])
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 472 |
# modify this return
|
| 473 |
# OutputPdfStage2=OutputPdfStage2.read()
|
| 474 |
# doc2 =fitz.open('pdf',OutputPdfStage2)
|
|
|
|
| 223 |
def width_as_char(real_width):
|
| 224 |
char_width = []
|
| 225 |
for width in real_width:
|
| 226 |
+
char_width.append(f"{width}")
|
| 227 |
return char_width
|
| 228 |
|
| 229 |
def adjustannotations(OutputPdfStage1):
|
|
|
|
| 343 |
annot.set_border(width=0.2, dashes=(1, 2)) # Optional border styling
|
| 344 |
annot.set_colors(stroke=(1, 0, 0), fill=None) # Set the stroke color to red
|
| 345 |
annot.update()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 346 |
page.set_rotation(rotationOld)
|
| 347 |
return pdf_document
|
| 348 |
|
|
|
|
| 397 |
|
| 398 |
df_doors = df_doors.fillna(' ')
|
| 399 |
gc,spreadsheet_service,spreadsheetId, spreadsheet_url , namepathArr=google_sheet_Legend.legendGoogleSheets(df_doors , pdf_name,pdfpath)
|
| 400 |
+
list1=pd.DataFrame(columns=['content', 'id', 'subject','color'])
|
| 401 |
+
|
| 402 |
+
# for page in doc:
|
| 403 |
+
for page in doc2:
|
| 404 |
+
# Iterate through annotations on the page
|
| 405 |
+
for annot in page.annots():
|
| 406 |
+
# Get the color of the annotation
|
| 407 |
+
annot_color = annot.colors
|
| 408 |
+
if annot_color is not None:
|
| 409 |
+
# annot_color is a dictionary with 'stroke' and 'fill' keys
|
| 410 |
+
stroke_color = annot_color.get('stroke') # Border color
|
| 411 |
+
print('strokeee',stroke_color)
|
| 412 |
+
# fill_color = annot_color.get('fill') # Fill color
|
| 413 |
+
# if fill_color:
|
| 414 |
+
# v='fill'
|
| 415 |
+
# print('fill')
|
| 416 |
+
if stroke_color:
|
| 417 |
+
v='stroke'
|
| 418 |
+
# x,y,z=int(annot_color.get(v)[0]*255),int(annot_color.get(v)[1]*255),int(annot_color.get(v)[2]*255)
|
| 419 |
+
list1.loc[len(list1)] =[annot.info['content'],annot.info['id'],annot.info['subject'],[255,0,0]]
|
| 420 |
+
|
| 421 |
+
|
| 422 |
+
print('list1',list1)
|
| 423 |
# modify this return
|
| 424 |
# OutputPdfStage2=OutputPdfStage2.read()
|
| 425 |
# doc2 =fitz.open('pdf',OutputPdfStage2)
|