Skip to content

Commit 31df525

Browse files
small corrections
1 parent a2e32e4 commit 31df525

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

CoreProcessingPipelineScripts/CNN/Mask_RCNN/postprocessing/postprocessingCracksRings.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -665,11 +665,13 @@ def plot_lines(image, centerlines, measure_points, file_name, path_out):
665665
plt.figure(figsize = (imgwidth/plot_dpi, 2*(imgheight/plot_dpi)), dpi=plot_dpi)
666666
#fig, (ax1, ax2) = plt.subplots(2)
667667
plt.imshow(image)
668+
linewidth = (imgheight/1000)*5 # looks very variable depending on the image resolution whne set as a constant defaoult is 1.5
668669
else: # adjust image size if it`s exceeding 30000 pixels to 30000
669670
resized_height = imgheight*(30000/imgwidth)
670671
plt.figure(figsize = (30000/plot_dpi, 2*(resized_height/plot_dpi)), dpi=plot_dpi)
671672
#fig, (ax1, ax2) = plt.subplots(2)
672673
plt.imshow(image)
674+
linewidth = (resized_height/1000)*5 # looks very variable depending on the image resolution whne set as a constant defaoult is 1.5
673675

674676

675677
# Plot the lines to the image
@@ -682,14 +684,14 @@ def plot_lines(image, centerlines, measure_points, file_name, path_out):
682684
points = measure_points[i]
683685

684686
xc,yc = centerlines[i].coords.xy
685-
plt.plot(xc,yc,'g')
687+
plt.plot(xc,yc,'g', linewidth=linewidth)
686688

687689
xp, yp = points[0].coords.xy
688690
xp1, yp1 = points[1].coords.xy
689-
plt.plot([xp, xp1], [yp, yp1], 'r')
691+
plt.plot([xp, xp1], [yp, yp1], 'r', linewidth=linewidth)
690692

691693
xc,yc = centerlines[-1].coords.xy
692-
plt.plot(xc,yc,'g')
694+
plt.plot(xc,yc,'g', linewidth=linewidth)
693695
#plt.show()
694696

695697

@@ -705,15 +707,15 @@ def plot_lines(image, centerlines, measure_points, file_name, path_out):
705707
#print('loop', i)
706708

707709
xc,yc = centerlines1[i].coords.xy
708-
plt.plot(xc,yc,color[l])
710+
plt.plot(xc,yc,color[l], linewidth=linewidth)
709711

710712
points = measure_points1[i]
711713
xp, yp = points[0].coords.xy
712714
xp1, yp1 = points[1].coords.xy
713-
plt.plot([xp, xp1], [yp, yp1], 'r')
715+
plt.plot([xp, xp1], [yp, yp1], 'r', linewidth=linewidth)
714716

715717
xc,yc = centerlines1[-1].coords.xy # To print the last point
716-
plt.plot(xc,yc, color[l])
718+
plt.plot(xc,yc, color[l], linewidth=linewidth)
717719
#plt.show()
718720

719721
plt.savefig(os.path.join(export_path, f), bbox_inches = 'tight', pad_inches = 0)
@@ -778,7 +780,7 @@ def write_to_pos(centerlines, measure_points, file_name, image_name, DPI, path_o
778780
print("Writing .pos file")
779781
write_run_info("Writing .pos file")
780782
# Check if it is one or two parts in measure points
781-
# If two adjust naming. Nothink for the normal one and add "x" at the end for the second part
783+
# If two adjust naming. Nothing for the normal one and add "x" at the end for the second part
782784
#print('measure_point len', len(measure_points))
783785
#print('measure_point', measure_points)
784786
# Prepare date, time
@@ -943,7 +945,7 @@ class InferenceConfig(configCrack.__class__):
943945
# DETECTION
944946
else:
945947
print("Starting inference mode")
946-
# Check compulsary argument and print which are missing
948+
# Check compulsory argument and print which are missing
947949
print('Checking compulsory arguments')
948950
if args.input==None:
949951
print("Compulsory argument --input is missing. Specify the path to image file of folder")
@@ -985,7 +987,7 @@ class InferenceConfig(configCrack.__class__):
985987
json_list = []
986988
for f in os.listdir(path_out):
987989
if f.endswith('.json'):
988-
json_name = os.path.splitext(f)[0]
990+
#json_name = os.path.splitext(f)[0]
989991
json_name = f.replace('.json', '')
990992
json_list.append(json_name)
991993

@@ -1000,7 +1002,7 @@ class InferenceConfig(configCrack.__class__):
10001002
input_list = os.listdir(input)
10011003
input_path = input
10021004
else:
1003-
print("Image argument is neither valid file nor directory")
1005+
print("Image argument is neither valid file nor directory") # input or image?
10041006
write_run_info("Image argument is neither valid file nor directory")
10051007
#print("got until here", input_list, input_path)
10061008

@@ -1094,7 +1096,7 @@ class InferenceConfig(configCrack.__class__):
10941096
write_run_info("clean_up_mask cracks done")
10951097
print("clean_up_mask cracks done")
10961098

1097-
write_to_json(image_name=f,cutting_point=cutting_point, run_ID=run_ID,
1099+
write_to_json(image_name=f, cutting_point=cutting_point, run_ID=run_ID,
10981100
path_out=path_out, centerlines_rings=centerlines_rings,
10991101
clean_contours_rings=clean_contours_rings,
11001102
clean_contours_cracks=clean_contours_cracks)

CoreProcessingPipelineScripts/CNN/Mask_RCNN/training/prepareAnnotations.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,17 @@ def polylinetopolygon(polyline_str, width, height, buffer=30):
3131

3232
return list(x), list(y)
3333

34-
def processCVATxml(dataset):
35-
buffer = 30
34+
def pocessCVATxml(dataset, buffer = 30):
35+
#buffer = 30
3636
newJ = {}
3737
annotated_images = []
3838
shpAttrBase = {'name': 'polygon'}
3939
CVAT_ANNOTPATH = os.path.join(dataset, "CVAT_annotations")
40-
CVAT_annot_file_list = os.listdir(CVAT_ANNOTPATH)
40+
#CVAT_annot_file_list = os.listdir(CVAT_ANNOTPATH)
41+
CVAT_annot_file_list = [f for f in os.listdir(CVAT_ANNOTPATH) if not f.startswith('.')] #ignore hidden files
4142
for xml_name in CVAT_annot_file_list:
4243
# open load xml file
44+
print("Loading annotation file", xml_name)
4345
with open(os.path.join(CVAT_ANNOTPATH, xml_name)) as file:
4446
root = etree.parse(file).getroot()
4547
# Initiate new dictionary to add images and annotations to it
@@ -69,7 +71,7 @@ def processCVATxml(dataset):
6971
if key == "label":
7072
#print(value)
7173
if value != "RingBndy":
72-
print("Warning: Label is not RingBndy. Continue assuming all polylines are rings ")
74+
print("Warning: Label is not RingBndy. Continue assuming all polylines are rings")
7375
if key == "points":
7476
all_points_x, all_points_y = polylinetopolygon(polyline_str=value, width=width, height=height, buffer=buffer)
7577
shpAtt['all_points_x'] = all_points_x
@@ -114,7 +116,7 @@ def prepareAnnotations(dataset, overwrite_existing=False):
114116

115117
folder_paths =[TRAIN_PATH, VAL_PATH]
116118
# process and unite all xml files and prepare json with all annotations
117-
all_annotations, annotated_images = processCVATxml(dataset=dataset)
119+
all_annotations, annotated_images = pocessCVATxml(dataset=dataset, buffer = 30)
118120

119121
# prepare annotations
120122
for folder in folder_paths:

0 commit comments

Comments
 (0)