def convert_to_line_segs(track): line_segs = [] last_pt = track[-1].copy() for pt in track: line_segs.append(line_seg.line_seg(last_pt, pt)) last_pt = pt return line_segs
def get_sensor(self): sensor_mid = [self.x + self.sensor_offset*cos(self.orientation), self.y + self.sensor_offset*sin(self.orientation)] sensor_left = [sensor_mid[0] - self.sensor_width*sin(self.orientation), sensor_mid[1] + self.sensor_width*cos(self.orientation)] sensor_right = [sensor_mid[0] + self.sensor_width*sin(self.orientation), sensor_mid[1] - self.sensor_width*cos(self.orientation)] return line_seg.line_seg(sensor_left, sensor_right)
# to change the contrast on the full-sized image img2 = cv2.imread(depth_im, -1) img2 = util.normalize_depth(img2) img2 = util.clahe(img2, iter=2) # crops the image img2 = img2[mouse_Y[0]:mouse_Y[1], mouse_X[0]:mouse_X[1]] P["img2"] = img2 # *********************************** SECTION 1 ***************************************** # FIND DEPTH / CURVATURE DISCONTINUITIES. curve_disc, depth_disc, edgelist = edge_detect(P) #CREATES LINE SEGMENTS seglist = line_seg(edgelist, tol=5) if context.ShowEdgeListWnd: draw.draw_edge_list(seglist, P) line_pairs = [] cntr_pairs = [] img_size = copy.deepcopy(P["img_size"]) height = img_size[0] width = img_size[1] blank_im = np.zeros((height, width, 3), np.uint8) print("img size", img_size) window_size = 3 def roipoly(src, poly):
import numpy as np import cv2 import line_seg #im = cv2.imread('images/text.png') im1 = cv2.imread('images/text3.jpg') im1 = cv2.resize(im1, None, fx=4, fy=4, interpolation=cv2.INTER_CUBIC) #im = cv2.resize(im,None,fx=4,fy=4,interpolation=cv2.INTER_CUBIC) #im = im[19:110,:] lines = line_seg.line_seg() j = 0 for i in range(len(lines)): if i < len(lines) - 1: im = im1[lines[i] - 2:lines[i + 1] + 2, 0:im1.shape[1]] height = im.shape[0] width = im.shape[1] imgray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY) #thresh = cv2.adaptiveThreshold(imgray,255,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY_INV,21,20) thresh = cv2.threshold(imgray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1] thresh_real = cv2.threshold(imgray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1] #thresh_inv = cv2.adaptiveThreshold(imgray,255,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY_INV,21,20) kernel = np.ones((5, 5), np.uint8) blob = cv2.dilate(thresh, kernel, iterations=4) blob = cv2.erode(blob, kernel, iterations=4) count = np.zeros(shape=(height, )) for y in range(height): for x in range(width): if blob[y][x] == 255: