def test_chars_identify(): ''' 字符鉴别 :return: ''' print("Testing Chars Identify") file = "resources/image/chars_identify.jpg" src = cv2.imread(file) imshow("src", src) result = [] plate = CharsSegment() ci = CharsIdentify() plate_license = [] if plate.charsSegment(src, result) == 0: plate_license = ci.identify(np.array(result)[..., None]) pred = "" for index in plate_license: pred += index2str[index] print("Plate License: ", "苏E771H6") print("Plate Identify: ", pred) if pred == "苏E771H6": print("Identify Correct") else: print("Identify Not Correct")
def test_plate_judge(): ''' 车牌判断 :return: ''' print("Testing Plate Judge") file = "resources/image/plate_judge.jpg" src = cv2.imread(file) result = [] plate = PlateLocate() plate.setDebug(False) plate.setLifemode(True) if plate.plateLocate(src, result) == 0: for res in result: imshow("plate judge", res) judge_result = PlateJudge().judge(np.array(result)) if len(judge_result) != 0: for res in judge_result: imshow("plate judge", res)
def test_chars_recognise(): print("Testing Chars Recognise") file = "resources/image/chars_recognise.jpg" src = cv2.imread(file) imshow("src", src) cr = CharsRecognise() print("Chars Recognise: ", cr.charsRecognise(src))
def test_char_segment(): print("Testing Chars Segment") file = "resources/image/chars_segment.jpg" src = cv2.imread(file) imshow("src", src) result = [] plate = CharsSegment() if plate.charsSegment(src, result) == 0: for i in range(len(result)): imshow("plate segment " + str(i), result[i])
def test_plate_detect(): print("Testing Plate Detect") file = "resources/image/plate_detect.jpg" src = cv2.imread(file) result = [] pd = PlateDetect() pd.setPDLifemode(True) if pd.plateDetect(src, result) == 0: for res in result: imshow("plate detect", res)
def test_plate_locate(): print("Testing Plate Locate") file = "resources/image/test.jpg" src = cv2.imread(file) result = [] plate = PlateLocate() plate.setDebug(False) plate.setLifemode(True) if plate.plateLocate(src, result) == 0: for res in result: imshow("plate locate", res)
def test_plate_recognize(): print("Testing Plate Recognize") file = "resources/image/test.jpg" src = cv2.imread(file) imshow("src", src) result_detection = [] pd = PlateDetect() pd.setPDLifemode(True) pd.plateDetect(src, result_detection) cr = CharsRecognise() for res in result_detection: imshow("Plate Recognize", res) print("Chars Recognise: ", cr.charsRecognise(res))
def test_plate_locate(): ''' 车牌定位 :return: ''' print("Testing Plate Locate") file = "resources/image/test.jpg" # file = "/Users/huijunzhang/Downloads/pic/pic2.jpg" src = cv2.imread(file) result = [] plate = PlateLocate() plate.setDebug(False) plate.setLifemode(True) if plate.plateLocate(src, result) == 0: for res in result: imshow("plate locate", res)
def colorSearch(self, src, color, out_rect): ''' :param src: :param color: :param out_rect: minAreaRect :return: binary ''' color_morph_width = 10 color_morph_height = 2 match_gray = colorMatch(src, color, False) if self.m_debug: imshow('match_gray_' + str(color), match_gray) # imwrite("resources/image/tmp/", "match_gray.jpg", match_gray) _, src_threshold = cv2.threshold(match_gray, 0, 255, cv2.THRESH_OTSU + cv2.THRESH_BINARY) element = cv2.getStructuringElement( cv2.MORPH_RECT, (color_morph_width, color_morph_height)) src_threshold = cv2.morphologyEx(src_threshold, cv2.MORPH_CLOSE, element) if self.m_debug: imshow('color', src_threshold) # imwrite("resources/image/tmp/", "color.jpg", src_threshold) out = src_threshold.copy() _, contours, _ = cv2.findContours(src_threshold, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) for cnt in contours: mr = cv2.minAreaRect(cnt) if self.verifySizes(mr): out_rect.append(mr) return out
images = [] labels = [] for i in range(self.batch_size): image, label = self.image_label_queue.get() images.append(image) labels.append(label) images = np.asarray(images, dtype=np.float32) images = images / 255 * 2 - 1 return images, labels if __name__ == "__main__": #Test batch_size = 32 dataset_params = { 'batch_size': batch_size, 'path': '../resources/train_data/chars', 'labels_path': '../resources/train_data/chars_list_train.pickle', 'thread_num': 1 } train_dataset_reader = DataSet(dataset_params) images, labels = train_dataset_reader.batch() imshow('tmp', images[0]) imshow('tmp', images[1]) images, labels = train_dataset_reader.batch() imshow('tmp', images[0]) imshow('tmp', images[1])