def VIS_POLYGONS(img, polygons): if img.shape[0] > 300 or img.shape[1] > 300: return print('VIS_POLYGONS: polygons count:', len(polygons), [p.len for p in polygons]) if len(polygons) == 0: return tails_colors = ((0, 127, 0), (0, 255, 0)) points_color = (0, 0, 0) separator = DEBUG.separator(img) images = [] im = DEBUG.__draw_polygons(img.copy(), polygons, (0, 255, 0), 1, tails_colors, points_color) images.extend([im, separator]) if len(polygons) > 1: for p in polygons: im = DEBUG.__draw_polygons(img.copy(), [p], (0, 255, 0), 1, tails_colors, points_color) images.extend([im, separator]) wnd = CvNamedWindow('polygons', cv2.WINDOW_NORMAL) wnd.imshow(np.hstack(images)) cv2.waitKey() wnd.destroy()
def VIS_assemble_ellipses_from_parts(bgr, part, next_part, ellipses): if bgr.shape[0] > 300 or bgr.shape[1] > 300: return green = (0, 255, 0) red = (0, 0, 255) blue = (255, 0, 0) im = bgr.copy() cv2.polylines(im, [part.points], False, green, 2) x, y = part.first_pt im[y - 3:y + 3, x - 3:x + 3] = [0, 255, 0] x, y = part.last_pt im[y - 3:y + 3, x - 3:x + 3] = [0, 127, 0] if next_part: cv2.polylines(im, [next_part.points], False, red, 2) x, y = next_part.first_pt im[y - 3:y + 3, x - 3:x + 3] = [0, 0, 255] x, y = next_part.last_pt im[y - 3:y + 3, x - 3:x + 3] = [0, 0, 127] for poly in ellipses: cv2.polylines(im, [poly.points], False, blue, 2) wnd = CvNamedWindow('DEBUG') wnd.imshow(im) cv2.waitKey() wnd.destroy()
def VIS_ALL_CONTOURS(img, contours): if img.shape[0] > 300 or img.shape[1] > 300: return print('contours LEN:', len(contours)) if len(contours) == 0: return separator = DEBUG.separator(img) images = [] tails_colors = ((0, 127, 0), (0, 255, 0)) points_color = (0, 0, 0) im = DEBUG.__draw_contours(img.copy(), contours, (0, 255, 0), 1, tails_colors, points_color) images.extend([im, separator]) if len(contours) > 1: for c in contours: im = DEBUG.__draw_contours(img.copy(), [c], (0, 255, 0), 1, tails_colors, points_color) images.extend([im, separator]) print(f'VIS_ALL_CONTOURS: contour len {c.len()}') wnd = CvNamedWindow('contours', cv2.WINDOW_NORMAL) wnd.imshow(np.hstack(images)) cv2.waitKey() wnd.destroy()
def VIS_EDGES(edges): if DEBUG.should_not_vis(edges): return wnd = CvNamedWindow('DEBUG EDGES') wnd.imshow(edges) cv2.waitKey() wnd.destroy()
def visualize(contours, image, winname): draw_contours(contours, image, (0, 255, 0), thickness=2, draw_measurements=False) wnd = CvNamedWindow(winname, cv2.WINDOW_NORMAL) wnd.imshow(image) cv2.waitKey() wnd.destroy()
def visualize_contours(contours, image, winname): contours = sorted(contours, key=lambda c: c.len(), reverse=True) wnd = CvNamedWindow(winname, cv2.WINDOW_NORMAL) for part in contours: cv2.drawContours(image, [part.points()], -1, utils.random_color(), 2) print('part', part.len()) wnd.imshow(image) cv2.waitKey() wnd.destroy(winname)
def VIS_CONTOURS(edges, contours): print(f'DEBUG.VIS_CONTOURS: contours count {len(contours)}') if DEBUG.should_not_vis(edges): return im = np.zeros_like(edges) cv2.drawContours(im, contours, -1, 255, 1) images = [im] for c in contours: im = np.zeros_like(edges) cv2.drawContours(im, [c], -1, 255, 1) images.append(im) wnd = CvNamedWindow('DEBUG CONTOURS') wnd.imshow(np.hstack(images)) cv2.waitKey() wnd.destroy()