def enhanceVideo(frame, resize): if (resize): frame = cv2.resize(frame, (640, 352)) enhancedFrame = retinex.automatedMSRCR(frame) return enhancedFrame
def retinex_shadow_removal(image, retinex_type): with open('config.json', 'r') as f: config = json.load(f) if retinex_type == 'automatedMSRCR': return retinex.automatedMSRCR(image, config['sigma_list']) elif retinex_type == 'MSRCRP': return retinex.MSRCP(image, config['sigma_list'], config['low_clip'], config['high_clip']) elif retinex_type == 'MSRCR': return retinex.MSRCR(image, config['sigma_list'], config['G'], config['b'], config['alpha'], config['beta'], config['low_clip'], config['high_clip']) else: return image
def __data_generation(self, list_IDs_temp): 'Generates data containing batch_size samples' # Initialization X = [ np.empty((self.batch_size, self.dim[0], self.dim[1], 3)), np.empty((self.batch_size, self.dim[0], self.dim[1], 3)) ] Y = np.empty((self.batch_size), dtype=int) for i, ID in enumerate(list_IDs_temp): # ID is name of file img = cv2.imread(ID) img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) img = cv2.resize(img, (self.dim[1], self.dim[0])) if self.type_gen == 'train': img = self.sequence_augment(img) new_img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY) new_img = np.expand_dims(new_img, -1) new_img = automatedMSRCR(new_img, [10, 20, 30]) new_img = cv2.cvtColor(new_img[:, :, 0], cv2.COLOR_GRAY2RGB) X[0][i] = img / 255.0 X[1][i] = new_img / 255.0 else: new_img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY) new_img = np.expand_dims(new_img, -1) new_img = automatedMSRCR(new_img, [10, 20, 30]) new_img = cv2.cvtColor(new_img[:, :, 0], cv2.COLOR_GRAY2RGB) X[0][i] = img / 255.0 X[1][i] = new_img / 255.0 Y[i] = self.labels[ID] return X, Y
with open('config.json', 'r') as f: config = json.load(f) # 遍历读入的图像 for img_name in img_list: if img_name == '.gitkeep': continue # 读入图像 img = cv2.imread(os.path.join(data_path, img_name)) img_histogram = coloredHistoEqual(img) img_gamma = adjust_gamma(img) # 多尺度Retinex带色彩恢复 img_msrcr = retinex.MSRCR(img, config['sigma_list'], config['G'], config['b'], config['alpha'], config['beta'], config['low_clip'], config['high_clip']) img_amsrcr = retinex.automatedMSRCR(img, config['sigma_list']) # MSR with chromaticity preservation img_msrcp = retinex.MSRCP(img, config['sigma_list'], config['low_clip'], config['high_clip']) # 实验结果 shape = img.shape cv2.imshow('Image', img) cv2.imshow('retinex', img_msrcr) cv2.imshow('Histogram equalization', img_histogram) cv2.imshow('Gamma Correction', img_gamma) cv2.imshow('Automated retinex', img_amsrcr) cv2.imshow('MSRCP', img_msrcp) cv2.waitKey()
ret, frame = cap.read() bboxes = classifier.detectMultiScale(frame) for box in bboxes: x, y, width, height = box x2, y2 = int(x + 1.0*width), int(y + 1.2*height) x, y = int(x-0.0*width), int(y-0.2*height) img = frame[y:y2, x:x2] print(type(img)) img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) img = cv2.resize(img, (299, 299)) new_img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY) new_img = np.expand_dims(new_img, -1) new_img = automatedMSRCR(new_img, [10, 20, 30]) new_img = cv2.cvtColor(new_img[:, :, 0], cv2.COLOR_GRAY2RGB) preds = model.predict([np.expand_dims(img / 255.0, 0), np.expand_dims(new_img / 255.0, 0)]) if preds[0][0] > 0.90: rectangle(frame, (x, y), (x2, y2), (0,0,255), 1) else: rectangle(frame, (x, y), (x2, y2), (0,255,0), 1) out.write(frame) imshow('face detection', frame) if cv2.waitKey(25) & 0xFF == ord('q'): break cap.release()
def prepare_body_retinex(image): image = prepare_body(image) image = retinex.automatedMSRCR(image, [15, 80, 250]) return image