def detect_stop_sign(image, boundaryR): lowerR = np.array(boundaryR[0][0], dtype='uint8') upperR = np.array(boundaryR[0][1], dtype='uint8') img = edge_enhancement(image) alpha = 1.5 beta = 50 res = cv2.convertScaleAbs(img, alpha=alpha, beta=beta) hsv = cv2.cvtColor(res, cv2.COLOR_BGR2HSV) H, S, V = cv2.split(hsv) S = S + 50 hsvR = cv2.merge((H, S, V)) kernel = np.ones((3, 3), np.uint8) maskR = cv2.inRange(hsvR, lowerR, upperR) maskR = cv2.morphologyEx(maskR, cv2.MORPH_CLOSE, kernel) maskR = cv2.morphologyEx(maskR, cv2.MORPH_OPEN, kernel) cntR, max_cntR, approx_cntR = geom.find_main_contour_approx(maskR) try: shapeR, thresh = detect(max_cntR, maskR) if shapeR == 'octagon' and cv2.countNonZero(maskR) > 1000: cv2.putText(image, 'STOP', (image.shape[1] - 100, image.shape[0] - 20), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2) except: pass return image
def prepare_stop_pic(image): img = edge_enhancement(image) # alpha = 1.5 # beta = 50 # res = cv2.convertScaleAbs(img, alpha = alpha, beta = beta) hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) # hsv[:,:,1] = hsv[:,:,1] + 50 # H, S, V = cv2.split(hsv) # S = S + 50 # hsvR = cv2.merge((H, S, V)) return hsv
def prepare_addr_pic(image): img = edge_enhancement(image) lab = cv2.cvtColor(img, cv2.COLOR_BGR2LAB) L, A, B = cv2.split(lab) if np.mean(L) < 120: img = adjust_gamma(img, gamma=0.6) L, A, B = cv2.split(cv2.cvtColor(img, cv2.COLOR_BGR2LAB)) greenA = A.copy() greenA[A < 90] = 0 greenA[A > 115] = 0 greenB = B.copy() greenB[B < 140] = 0 greenB[B > 160] = 0 maskG = cv2.bitwise_and(greenA, greenA, mask=greenB) kernel = np.ones((3, 3), np.uint8) maskG = cv2.morphologyEx(maskG, cv2.MORPH_OPEN, kernel) maskG = cv2.morphologyEx(maskG, cv2.MORPH_CLOSE, kernel) maskG = cv2.morphologyEx(maskG, cv2.MORPH_DILATE, kernel) return maskG
import cv2 import num_detect.number_geom as geom from bright.bright_function import edge_enhancement ################# datafolder = '/Users/soua/Desktop/Project/sterling_demo' img_path = datafolder + '/Img_89.jpg' # 202 s : 56 -> +50 / v : 104 -> 255 - = 151 # img_path = datafolder + '/Img_284.jpg' # 203 s : 84 -> +50 / v : 81 -> 255 - = 175 # img_path = datafolder + '/Img_390.jpg' # 103 s : 41 -> + 100 / v : 141 -> 255 - = 115 # img_path = datafolder + '/Img_907.jpg' # 101 s : 90 / v : 71 -> 235 - = 164 # img_path = datafolder + '/Img_1398.jpg' # 101 s : 78 / v : 69 # img_path = datafolder + '/Img_1077.jpg' # 201 s : 35 / V : 138 img = cv2.imread(img_path) img = edge_enhancement(img) cv2.imshow('before scaling', img) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) hist = cv2.calcHist([gray], [0], None, [256], [0, 256]) hist_size = len(hist) accm = [] accm.append(float(hist[0])) for idx in range(1, hist_size): accm.append(accm[idx - 1] + float(hist[idx])) max = accm[-1] clip_hist_percent = 1 clip_hist_percent *= (max / 100.0) clip_hist_percent /= 2.0