Browse Source

works except for xmax and ymax

bscheibel 4 years ago
parent
commit
b6aba868e7

+ 6 - 3
clustering_precomputed_dbscan.py

@@ -12,6 +12,7 @@ def get_average_xy(list_input):
     resultFile = open(csv_name, 'w')
     wr = csv.writer(resultFile, delimiter=";")
     wr.writerow(["element", "xmin","ymin","xmax","ymax", "ausrichtung","point_xmi_ymi","point_xma_ymi","point_xmi_yma","point_xma_yma"])
+
     for element in list_input:
         xavg_elem = 0
         yavg_elem = 0
@@ -46,6 +47,7 @@ def get_average_xy(list_input):
         #element.extend([xavg_elem, yavg_elem])
         #print(element)
         #new_list.append(element)
+
         ##### GET CORNER POINTS
         point_xmi_ymi = [xmin,ymin]
         point_xma_ymi = [xmax,ymin]
@@ -53,6 +55,7 @@ def get_average_xy(list_input):
         point_xma_yma = [xmax,ymax]
         wr.writerow([element,xmin,ymin,xmax,ymax, ausrichtung,point_xmi_ymi,point_xma_ymi,point_xmi_yma,point_xma_yma])
 
+
     resultFile.close()
     #print(new_list)
     return csv_name
@@ -102,7 +105,7 @@ def dist(rectangle1, rectangle2):
     return distance
 
 def clustering(distance_matrix):
-    db = DBSCAN(eps=5, min_samples=1, metric="precomputed").fit(dm)  ##3.93 until now, bei 5 shon mehr erkannt, 7 noch mehr erkannt aber auch schon zu viel; GV12 ist 4.5 gut für LH zu wenig
+    db = DBSCAN(eps=3, min_samples=1, metric="precomputed").fit(dm)  ##3.93 until now, bei 5 shon mehr erkannt, 7 noch mehr erkannt aber auch schon zu viel; GV12 ist 4.5 gut für LH zu wenig
     #db = OPTICS(min_samples=1,xi=0.1, metric="precomputed").fit(dm)
     labels = db.labels_
     # Number of clusters in labels
@@ -115,8 +118,8 @@ def clustering(distance_matrix):
     data_df.groupby(['cluster','ausrichtung'])['element'].apply(','.join).reset_index().to_csv("values_clusteredfrom_precomputed_dbscan.csv",sep=";", header=False, index=False)
 
 
-file = "/home/bscheibel/PycharmProjects/dxf_reader/drawings/5152166_Rev04.html"
-#file = "/home/bscheibel/PycharmProjects/dxf_reader/drawings/5129275_Rev01-GV12.html"
+#file = "/home/bscheibel/PycharmProjects/dxf_reader/drawings/5152166_Rev04.html"
+file = "/home/bscheibel/PycharmProjects/dxf_reader/drawings/5129275_Rev01-GV12.html"
 result = order_bounding_boxes_in_each_block.get_bound_box(file)
 #print(result)
 get_average_xy(result)

+ 71 - 55
organize_drawing_according_to_details.py

@@ -13,6 +13,8 @@ def get_details(result): #search for all details in drawing and store it in list
             details_.append(element)
 
     details = []
+    xbiggest = 0
+    ybiggest = 0
     for elem in details_: #now go to newly created list of all details and get the min and max coordinates of the respective bbox around the detail
         #print(elem)
         ymin = 100000000
@@ -20,76 +22,90 @@ def get_details(result): #search for all details in drawing and store it in list
         xmin = 100000000
         xmax = 0
         text = ""
-        for blub in elem: #check if coordinates are bigger or smaller
-            text += blub[4]
+        for ele in elem: #check if coordinates are bigger or smaller
+            text += ele[4]
             #print(text)
-            if float(blub[1]) < ymin:
-                ymin = float(blub[1])
+            if float(ele[1]) < ymin:
+                ymin = float(ele[1])
                 # print("y_min:",y_min)
-            if float(blub[0]) < xmin:
-                xmin = float(blub[0])
-            if float(blub[3]) > ymax:
-                ymax = float(blub[3])
-            if float(blub[2]) > xmax:
-                xmax = float(blub[2])
+            if float(ele[0]) < xmin:
+                xmin = float(ele[0])
+            if float(ele[3]) > ymax:
+                ymax = float(ele[3])
+            if float(ele[2]) > xmax:
+                xmax = float(ele[2])
         details.append(list((xmin, ymin,xmax, ymax,text))) # create new list with the textual details and the min and max coordinates of these details
         number = len(details)
 
+    if ymax > ybiggest:  ###get biggest x and y values
+        ybiggest = ymax
+    if xmax > xbiggest:
+        xbiggest = xmax
+
     #print(details)
-    return details, number
+    return details, number, ybiggest, xbiggest
 
 
 file = "/home/bscheibel/PycharmProjects/dxf_reader/drawings/5129275_Rev01-GV12.html"
 result = order_bounding_boxes_in_each_block.get_bound_box(file)
-details, number = get_details(result)
-details = sorted(details, key=lambda x: sqrt((x[0] - 0)**2 + (x[1] - 0)**2)) #sort by distance from 0,0
-print(details, number)
-
+details, number, ybiggest, xbiggest = get_details(result)
+#details = sorted(details, key=lambda x: sqrt((x[0] - 0)**2 + (x[1] - 0)**2)) #sort by distance from 0,0
+details = sorted(details, key=lambda x: x[0]) #sort by distance from 0,0
 
+#print(details, number)
 
 sections = []
-max_x_last_element = 0
-max_y_last_element = 0
-border = 0
-i = 0
-overlapping = []
-for x in details:
-    min_x = x[0]
-    #print(min_x)
-    if max_x_last_element != 0: #start compare second and first element #check if min_x of new element is bigger than max_x of last element to see if they overlap in their xs
-        distance = min_x - max_x_last_element
-        if distance < 0: #if they overlap then there has to be segmentation of y as well
-            print("überschneidend")
-            ov = []
-            ov.append((x[0],))
-            ov.append(details[i-1])
-            ov = sorted(ov, key=lambda x: x[1])
-            print(ov)
-            y_lower_min = ov[1][1]
-            print(y_lower_min)
-            sections.append(details[i-1][x])
-
-
-            overlapping.append((x,details[i-1]))
+for first in details:
+    x_min = -1
+    y_min = -1
+    x_max = -1
+    y_max = -1
+    firstx_max = first[2]
+    firstx_min = first[0]
+    firsty_max = first[3]
+    firsty_min = first[1]
 
-        #print(distance)
-        else:
-            border_x = max_x_last_element+(distance/2)
-            sections.append((border_x, 100000000))
-    max_x_last_element = x[2]
-    i += 1
+    distance_xmax = 100000000000
+    distance_xmin = 100000000000
+    distance_ymin = 100000000000
+    distance_ymax = 100000000000
 
-#print(overlapping)
+    for second in details:
+        secondx_min = second[0]
+        secondx_max = second[2]
+        secondy_min = second[1]
+        secondy_max = second[3]
 
-"""
-for y in details:
-    min_y = y[1]
-    if max_y_last_element != 0:
-        distance = min_y - max_y_last_element
-        border_y = max_y_last_element + (distance/2)
-        sections_y.append(border_y)
-    max_y_last_element = y[3]
+        if secondx_max < firstx_min and abs(firsty_min-secondy_min) < 90 and first != second:  ###check for left side, are there any other details at the left side at a certain y-span
+            #print(first,second)
+            if abs(firstx_min - secondx_max)/2 < distance_xmax:
+                distance_xmax = abs(firstx_min - secondx_max)/2
+                x_min = secondx_max + distance_xmax
+        if secondx_min > firstx_max and abs(firsty_min-secondy_min) < 190 and first != second: ####check for right side
+            if abs(secondx_min - firstx_max)/2 < distance_xmin:
+                #print(first, second)
+                distance_xmin = abs(secondx_min - firstx_max)/2
+                x_max = firstx_max + distance_xmin
+        if firsty_min > secondy_max and abs(firstx_min-secondx_min) < 40 and first != second: ####check above
+            if abs(firsty_min - secondy_max)/2 < distance_ymin:
+                #print(first, second)
+                distance_ymin = abs(firsty_min - secondy_max)/2
+                y_min= firsty_min
+        if firsty_max < secondy_min and abs(firstx_min-secondx_min) < 40 and first != second: ####check below
+            if abs(firsty_max - secondy_min)/2 < distance_ymax:
+                #print(first, second)
+                distance_ymax = abs(firsty_max - secondy_min)/2
+                y_max= secondy_min
 
-print(sections_y)"""
+    if y_min == -1:
+        y_min = firsty_min
+    if x_min == -1:
+        x_min = 0
+    if x_max == -1:
+        x_max = 1000000000
+    if y_max == -1:
+        y_max = 1000000000
+    sections.append((first,x_min, y_min,x_max,y_max))
 
-#oben,links beginnen
+for section in sections:
+    print(section)

+ 7 - 7
read_from_clustered_merged.py

@@ -8,26 +8,26 @@ with open("/home/bscheibel/PycharmProjects/dxf_reader/values_clusteredfrom_preco
         row3 = eval(row3)
         element = ""
         merged_elements = []
-        for blub in row3:
+        for elem in row3:
 
             if len(row3) == 1:
-                print(blub[4])
+                print(elem[4])
 
             else:
 
-                if isinstance(blub[0],list):
-                    merged_elements += blub
+                if isinstance(elem[0],list):
+                    merged_elements += elem
                     #print(merged_elements)
                     if len(merged_elements) < len(row3):
                         continue
                     if int(ausrichtung) == 1:
-                        blub = sorted(merged_elements, key=lambda k: [float(k[3])], reverse=True)
+                        elem = sorted(merged_elements, key=lambda k: [float(k[3])], reverse=True)
 
-                    for elem in blub:
+                    for elem in elem:
                         element += elem[4] + " "
 
                 else:
-                    element += blub[4] + " "
+                    element += elem[4] + " "
 
 
         print(element)

File diff suppressed because it is too large
+ 126 - 330
temporary/list_to_csv_with_corner_points.csv