def hough_lines(img, rho, theta, threshold, min_line_len, max_line_gap): lines = cv2.HoughLinesP(img, rho, theta, threshold, np.array([]), minLineLength=min_line_len, maxLineGap=max_line_gap) line_img = np.zeros((*img.shape, 4), dtype=np.uint8) draw_lines(line_img, lines) return line_img
def plot(self, loc): # Orient the object to the origin and scale to fit the print bed dimensions self.model.geometry = orient.to_origin(self.model.geometry) self.model.geometry = orient.fit_bed(self.model.geometry, xdim.get(), ydim.get(), zdim.get()) # Apply isometric perspective to the geometry plot_geometry, camera = gtransform.perspective(self.model.geometry) # Draw lines between points of the geometry faces plot_geometry = draw_lines(plot_geometry, self.model.normal, camera, view.get()) # Clear pixel array to white and then change each pixel color based on the XY pixel map self.pxarray = pygame.PixelArray(loc) self.pxarray[:][:] = (255, 255, 255) for point in range(0, plot_geometry.shape[0]): x = int(embed_w/2 + plot_geometry[point, 0]) # X coordinate (0,0 of screen is top left) y = int(embed_h/2 + plot_geometry[point, 1]) # Y coordinate (0,0 of screen is top left) # Plot all front facing lines and back facing when wireplot is selected if plot_geometry[point, 2] == 1 or view.get() == 'wire': self.pxarray[x][y] = (0, 0, 0) # Color = black # Plot grey lines only if grey lines are selected and the line is not already plotted black elif plot_geometry[point, 2] == 0 and view.get() == 'grey' and self.pxarray[x][y] != 0: self.pxarray[x][y] = (210, 210, 210) # Color = grey # Plot pixel array to screen and refresh window/GUI pygame.surfarray.blit_array(loc, self.pxarray) pygame.display.flip() window.update()
def plot_transform(self, loc, transtype, data): if transtype == 'ortho': # Transform the original geometry according to the selected orthographic view new_geometry, new_normals = gtransform.transform( self.model.geometry, self.model.normal, transtype, data) # Draw lines between points and clip to viewing window based on window height and width new_geometry = draw_lines(new_geometry, new_normals, [0, 0, 1], view.get(), embed_w, embed_h) else: # Transform geometry based on the selected transformation self.model.coordinates, self.model.normals = gtransform.transform( self.model.coordinates, self.model.normals, transtype, data) # Apply selected perspective with appropriate settings of fz, phi, and theta new_geometry, camera = gtransform.perspective( persp.get(), self.model.coordinates, fz.get(), phi.get(), theta.get()) # Draw lines between points and clip to viewing window new_geometry = draw_lines(new_geometry, self.model.normals, camera, view.get(), embed_w, embed_h) # Clear pixel array to white and then change each pixel color based on the XY pixel map self.pxarray[:][:] = (255, 255, 255) for point in range(0, new_geometry.shape[0]): x = int( embed_w / 2 + new_geometry[point, 0]) # X coordinate (0,0 of screen is top left) y = int( embed_h / 2 + new_geometry[point, 1]) # Y coordinate (0,0 of screen is top left) # Plot all front facing lines and back facing when wireplot is selected if new_geometry[point, 2] == 1 or view.get() == 'wire': self.pxarray[x][y] = (0, 0, 0) # Color = black # Plot grey lines only if grey lines are selected and the line is not already plotted black elif new_geometry[point, 2] == 0 and view.get( ) == 'grey' and self.pxarray[x][y] != 0: self.pxarray[x][y] = (210, 210, 210) # Color = grey # Plot pixel array to screen and refresh window/GUI pygame.surfarray.blit_array(loc, self.pxarray) pygame.display.flip() window.update()
def initial_plot(self, loc): # Copy original geometry to new internal variable to be used for transformations (keep original # geometry unchanged for use in displaying the orthographic views of the object) self.model.coordinates, self.model.normals = self.model.geometry, self.model.normal # Apply selected perspective with appropriate settings of fz, phi, and theta plot_geometry, camera = gtransform.perspective(persp.get(), self.model.coordinates, fz.get(), phi.get(), theta.get()) # Draw lines between points and clip to viewing window based on window height and width plot_geometry = draw_lines(plot_geometry, self.model.normals, camera, view.get(), embed_w, embed_h) # Clear pixel array to white and then change each pixel color based on the XY pixel map self.pxarray = pygame.PixelArray(loc) self.pxarray[:][:] = (255, 255, 255) for point in range(0, plot_geometry.shape[0]): x = int( embed_w / 2 + plot_geometry[point, 0]) # X coordinate (0,0 of screen is top left) y = int( embed_h / 2 + plot_geometry[point, 1]) # Y coordinate (0,0 of screen is top left) # Plot all front facing lines and back facing when wireplot is selected if plot_geometry[point, 2] == 1 or view.get() == 'wire': self.pxarray[x][y] = (0, 0, 0) # Color = black # Plot grey lines only if grey lines are selected and the line is not already plotted black elif plot_geometry[point, 2] == 0 and view.get( ) == 'grey' and self.pxarray[x][y] != 0: self.pxarray[x][y] = (210, 210, 210) # Color = grey # Plot pixel array to screen and refresh window/GUI pygame.surfarray.blit_array(loc, self.pxarray) pygame.display.flip() window.update()