Skip to content

Commit

Permalink
try opencv
Browse files Browse the repository at this point in the history
  • Loading branch information
YuXHe15 committed Oct 25, 2023
1 parent 5ba8f0f commit 38bd46a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
12 changes: 6 additions & 6 deletions amworkflow/src/geometries/composite_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class CreateWallByPointsUpdate():
def __init__(self, coords: list, th: float, height: float, is_close: bool = True):
self.coords = Pnt(coords).coords
self.height = height
self.R = None
self.R = 300
self.interpolate = 8
self.th = th
self.is_close = is_close
Expand All @@ -288,12 +288,12 @@ def __init__(self, coords: list, th: float, height: float, is_close: bool = True
self.rgt_coords = []
self.side_coords: list
self.create_sides()
self.pnts = Segments(self.side_coords)
self.G = nx.from_dict_of_lists(self.pnts.pts_digraph, create_using=nx.DiGraph)
# self.pnts = Segments(self.side_coords)
# self.G = nx.from_dict_of_lists(self.pnts.pts_digraph, create_using=nx.DiGraph)
# self.all_loops = list(nx.simple_cycles(self.H)) # Dangerous! Ran out of memory.
self.loop_generator = nx.simple_cycles(self.G)
self.check_pnt_in_wall()
self.postprocessing()
# self.loop_generator = nx.simple_cycles(self.G)
# self.check_pnt_in_wall()
# self.postprocessing()

def create_sides(self):
if self.R is not None:
Expand Down
41 changes: 38 additions & 3 deletions some_thoughts_20230822_new/try_new_thought/trail_3.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from amworkflow.src.geometries.composite_geometry import CreateWallByPointsUpdate
import numpy as np
from amworkflow.api import amWorkflow as aw
import cv2 as cv

th = 8
l = 10
Expand Down Expand Up @@ -44,6 +45,40 @@
pmfo = np.vstack((pmf, pout_nd))

wall = CreateWallByPointsUpdate(pmfo, th, height)
poly = wall.Shape()
wall.visualize(all_polygons=False, display_central_path=True)
aw.tool.write_stl(poly, "sucess_new_scheme",store_dir="/home/yhe/Documents/new_am2/amworkflow/some_thoughts_20230822_new/try_new_thought")
lft_coords = wall.lft_coords
rgt_coords = wall.rgt_coords
pieces = []
for i in range(len(lft_coords)-1):
pieces.append([lft_coords[i], lft_coords[i+1], rgt_coords[i+1], rgt_coords[i]])

def create_canvas(width: float, height: float):
image = np.zeros((height, width), dtype=np.uint8)
return image

def create_poly(pnts: list):
vertices = np.array(pnts, np.int32)
vertices = vertices.reshape((-1, 1, 2))
return vertices

def add_poly(image: np.ndarray, poly: np.ndarray):
cv.fillPoly(image, [poly], 255)

def find_contours(image):
contours, _ = cv.findContours(image, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)

return contours

# poly = wall.Shape()
# wall.visualize(all_polygons=False, display_central_path=False)
# aw.tool.write_stl(poly, "sucess_new_scheme",store_dir="/home/yhe/Documents/new_am2/amworkflow/some_thoughts_20230822_new/try_new_thought")
image = create_canvas(150, 150)
for p in pieces:
poly = create_poly(p)
add_poly(image, poly)
contours = np.array(find_contours(image))[0].reshape(-1, 2)
print(contours)
# contour_image = cv.cvtColor(image, cv.COLOR_GRAY2BGR)
# cv.drawContours(contour_image, contours, -1, (0, 255, 0), 2)
# cv.imshow("Contours", contour_image)
# cv.waitKey(0)
# cv.destroyAllWindows()

0 comments on commit 38bd46a

Please sign in to comment.