def SimpleRecognizePlate(image): t0 = time.time() bboxes, images = detect_by_probability( image) #detect.detectPlateRough(image) if images is None: return for image in images: #image = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY) image = cv2.resize(image, (136, 36)) image = kojy_gray(image) #image = maximizeContrast(255 - image) image_gray = fm.findContoursAndDrawBoundingBox(image) showResult("plate-colr", image) showResult("plate-gray,", image_gray) blocks, res, confidence = segmentation.slidingWindowsEval(image_gray) #for i in range(len(blocks)): # showResult("plate-gray,",blocks[i]) if confidence > 4.5: print "车牌:", res, "置信度:", confidence else: print "不确定的车牌:", res, "置信度:", confidence print time.time() - t0, "s"
def SimpleRecognizePlate(image): t0 = time.time() images = detect.detectPlateRough(image, image.shape[0], top_bottom_padding_rate=0.1) res_set = [] for j, plate in enumerate(images): plate, rect, origin_plate = plate # plate = cv2.cvtColor(plate, cv2.COLOR_RGB2GRAY) plate = cv2.resize(plate, (136, 36 * 2)) t1 = time.time() ptype = td.SimplePredict(plate) if (ptype > 0) and (ptype < 5): plate = cv2.bitwise_not(plate) image_rgb = fm.findContoursAndDrawBoundingBox(plate) image_rgb = fv.finemappingVertical(image_rgb) cache.verticalMappingToFolder(image_rgb) print("e2e:", e2e.recognizeOne(image_rgb)) image_gray = cv2.cvtColor(image_rgb, cv2.COLOR_RGB2GRAY) # image_gray = horizontalSegmentation(image_gray) cv2.imshow("image_gray", image_gray) # cv2.waitKey() cv2.imwrite("./" + str(j) + ".jpg", image_gray) # cv2.imshow("image",image_gray) # cv2.waitKey(0) print("校正", time.time() - t1, "s") # cv2.imshow("image,",image_gray) # cv2.waitKey(0) t2 = time.time() val = segmentation.slidingWindowsEval(image_gray) # print val print("分割和识别", time.time() - t2, "s") if len(val) == 3: blocks, res, confidence = val if confidence / 7 > 0.7: image = drawRectBox(image, rect, res) res_set.append(res) for i, block in enumerate(blocks): block_ = cv2.resize(block, (25, 25)) block_ = cv2.cvtColor(block_, cv2.COLOR_GRAY2BGR) image[j * 25:(j * 25) + 25, i * 25:(i * 25) + 25] = block_ if image[j * 25:(j * 25) + 25, i * 25:(i * 25) + 25].shape == block_.shape: pass if confidence > 0: print("车牌:", res, "置信度:", confidence / 7) else: pass # print "不确定的车牌:", res, "置信度:", confidence print(time.time() - t0, "s") return image, res_set
def SimpleRecognizePlate(image): t0 = time.time() images = detect.detectPlateRough(image,image.shape[0],top_bottom_padding_rate=0.1) res_set = [] for j,plate in enumerate(images): plate, rect, origin_plate =plate # plate = cv2.cvtColor(plate, cv2.COLOR_RGB2GRAY) plate =cv2.resize(plate,(136,36*2)) t1 = time.time() ptype = td.SimplePredict(plate) if ptype>0 and ptype<5: plate = cv2.bitwise_not(plate) image_rgb = fm.findContoursAndDrawBoundingBox(plate) image_rgb = fv.finemappingVertical(image_rgb) cache.verticalMappingToFolder(image_rgb) print "e2e:", e2e.recognizeOne(image_rgb) image_gray = cv2.cvtColor(image_rgb,cv2.COLOR_RGB2GRAY) # image_gray = horizontalSegmentation(image_gray) cv2.imshow("image_gray",image_gray) # cv2.waitKey() cv2.imwrite("./"+str(j)+".jpg",image_gray) # cv2.imshow("image",image_gray) # cv2.waitKey(0) print "校正",time.time() - t1,"s" # cv2.imshow("image,",image_gray) # cv2.waitKey(0) t2 = time.time() val = segmentation.slidingWindowsEval(image_gray) # print val print "分割和识别",time.time() - t2,"s" if len(val)==3: blocks, res, confidence = val if confidence/7>0.7: image = drawRectBox(image,rect,res) res_set.append(res) for i,block in enumerate(blocks): block_ = cv2.resize(block,(25,25)) block_ = cv2.cvtColor(block_,cv2.COLOR_GRAY2BGR) image[j * 25:(j * 25) + 25, i * 25:(i * 25) + 25] = block_ if image[j*25:(j*25)+25,i*25:(i*25)+25].shape == block_.shape: pass if confidence>0: print "车牌:",res,"置信度:",confidence/7 else: pass # print "不确定的车牌:", res, "置信度:", confidence print time.time() - t0,"s" return image,res_set
def SimpleRecognizePlate(image): t0 = time.time() images = detect.detectPlateRough(image) for image in images: image = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY) image =cv2.resize(image,(136,36)) image_gray = fm.findContoursAndDrawBoundingBox(image) cv2.imshow("image,",image_gray) cv2.waitKey(0) blocks,res,confidence = segmentation.slidingWindowsEval(image_gray) if confidence>4.5: print "车牌:",res,"置信度:",confidence else: print "不确定的车牌:", res, "置信度:", confidence print time.time() - t0,"s"
def recognizeLP(gray): t0 = time.time() if gray is None: return gray = cv2.resize(gray, (136, 36)) blocks, res, confidence = segmentation.slidingWindowsEval(gray) for i in range(len(blocks)): showResult("plate-gray,", blocks[i]) if confidence > 4.5: print "车牌:", res, "置信度:", confidence else: print "不确定的车牌:", res, "置信度:", confidence print time.time() - t0, "s" return blocks, res, confidence
def SimpleRecognizePlate(image): images = detect.detectPlateRough( image, image.shape[0], top_bottom_padding_rate=0.1) res_set = [] for j, plate in enumerate(images): plate, rect, origin_plate = plate plate = cv2.resize(plate, (136, 36 * 2)) ptype = td.SimplePredict(plate) if ptype > 0 and ptype < 5: plate = cv2.bitwise_not(plate) image_rgb = fm.findContoursAndDrawBoundingBox(plate) image_rgb = fv.finemappingVertical(image_rgb) image_gray = cv2.cvtColor(image_rgb, cv2.COLOR_RGB2GRAY) val = segmentation.slidingWindowsEval(image_gray) if len(val) == 3: blocks, res, confidence = val if confidence > 0: print "车牌号码: %s" % res else: pass return image, res_set
def RecognizePlateJson(image): images = detect.detectPlateRough(image, image.shape[0], top_bottom_padding_rate=0.1) jsons = [] for j, plate in enumerate(images): plate, rect, origin_plate = plate cv2.imwrite("./" + str(j) + "_rough.jpg", plate) # print "车牌类型:",ptype # plate = cv2.cvtColor(plate, cv2.COLOR_RGB2GRAY) plate = cv2.resize(plate, (136, int(36 * 2.5))) t1 = time.time() ptype = td.SimplePredict(plate) if ptype > 0 and ptype < 5: plate = cv2.bitwise_not(plate) # demo = verticalEdgeDetection(plate) image_rgb = fm.findContoursAndDrawBoundingBox(plate) image_rgb = fv.finemappingVertical(image_rgb) cache.verticalMappingToFolder(image_rgb) # print time.time() - t1,"校正" image_gray = cv2.cvtColor(image_rgb, cv2.COLOR_BGR2GRAY) cv2.imwrite("./" + str(j) + ".jpg", image_gray) # image_gray = horizontalSegmentation(image_gray) t2 = time.time() val = segmentation.slidingWindowsEval(image_gray) if len(val) == 3: blocks, res, confidence = val if confidence / 7 > 0.0: image = drawRectBox(image, rect, res) for i, block in enumerate(blocks): block_ = cv2.resize(block, (25, 25)) block_ = cv2.cvtColor(block_, cv2.COLOR_GRAY2BGR) image[j * 25:(j * 25) + 25, i * 25:(i * 25) + 25] = block_ if image[j * 25:(j * 25) + 25, i * 25:(i * 25) + 25].shape == block_.shape: pass plate_name = res res_json = {} if confidence / 7 > 0.0: res_json["Name"] = plate_name.decode() res_json["Type"] = td.plateType[ptype] res_json["Confidence"] = confidence / 7 res_json["x"] = int(rect[0]) res_json["y"] = int(rect[1]) res_json["w"] = int(rect[2]) res_json["h"] = int(rect[3]) # print "车牌:",res,"置信度:",confidence/7 jsons.append(res_json) else: pass # print "不确定的车牌:", res, "置信度:", confidence # print jsons # print json.dumps(jsons,ensure_ascii=False,encoding="gb2312") return json.dumps(jsons, ensure_ascii=False, encoding="gb2312")