def __init__(self, image=None): if image is not None: self.bgr = image self.licenplatevalidator = LicensePlate() self.confidence = 0.0 self.isFound = False
from detect_angle import detect_angle import html from misc.switch import switch #from os import listdir from os.path import exists #,isfile, join app = Flask(__name__) #, static_folder='static', static_url_path='') UPLOAD_FOLDER = 'uploads' WEBFILE_FOLDER = 'webfiles' app.qualityanalyzer = AnalyzeImageQuality() app.classifier = Classifier() app.detector = VehicleDetector() app.licenseplatedetector = LicensePlateDetector() app.licenseplate = LicensePlate() app.vehicleidentifier = VIN() app.results = [] app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER app.config['WEBFILE_FOLDER'] = WEBFILE_FOLDER app.config["CACHE_TYPE"] = "null" app.config['ALLOWED_EXTENSIONS'] = set( ['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif']) app.config['MAX_CONTENT_LENGTH'] = 3 * 1024 * 1024 # 1 Mb limit app.image_fn = os.path.join(app.config['UPLOAD_FOLDER'], "image.jpg") app.result_fn = os.path.join(app.config['UPLOAD_FOLDER'], "result.txt") app.filename = "" #cache = Cache(config={'CACHE_TYPE': 'redis'})
class LicensePlateDetector: def __init__(self, image=None): if image is not None: self.bgr = image self.licenplatevalidator = LicensePlate() self.confidence = 0.0 self.isFound = False def initialize(self): self.bgr = None def preprocess(self, image): self.bgr = image gray = cv2.cvtColor(self.bgr, cv2.COLOR_BGR2GRAY) self.gray = icontrast(255 - gray) self.laplacian = Laplacian(gray) #self.sobel = Sobel(gray) #self.entropy = Entropy(gray) #self.garbor = Garbor(gray) self.DoG = DoG(gray) self.lthr = AdaptiveThreshold(self.laplacian) self.tophat = tophatmask(gray) #tophatblackhat(gray) masks = [] #masks.append(self.tophat) masks.append(self.DoG) self.compose = maskize(self.lthr, masks) self.contour = np.zeros((self.compose.shape[:2]), np.uint8) def showall(self): showResult("laplacian", self.laplacian) showResult("lthr", self.lthr) #showResult("DoG",self.DoG) showResult("tophat", self.tophat) showResult("compose", self.compose) def process(self, image): return self.detect(image) #self.preprocess(image) #self.showall() def detect(self, origin, isdebug=False): start = time.time() # Default Size h, w, c = origin.shape size = 200.0 # Resize img = cv2.resize(origin, (int(w * size / h), int(size))) #showResult("img",img) for case in switch(AnalyzeImageQuality.dayornight(img)): if case('Day'): # Extract Good Features corners = refinedGoodFeatures(origin, img) mask = checkFeatures(img, corners, isdebug) closing = close(mask) refined_gfmask = refine_gfimage(img, closing) #showResult("refined_gfmask",refined_gfmask) finalmasks = mkfinalmasks(img, refined_gfmask, isday=True, isdebug=isdebug) break if case('Night'): finalmasks = mkfinalmasks(img, None, isday=isdebug) break for colrindex, fmask in enumerate(finalmasks): if (fmask > 0).sum() == 0: continue bboxes = mask2plates(img, fmask) # Resize if bboxes is not None: bboxes = resizeBBoxes(bboxes, h / size) rois = BBoxes2ROIs(origin, bboxes) for i, roi in enumerate(rois): confidence = self.licenplatevalidator.process( roi, mode=colrs[colrindex], isdebug=isdebug) print confidence if confidence > 0.7: #pts = self.licenplatevalidator.getRefinedROI() #bbox = refineBBox(bboxes[i],pts) bbox = resizeBBox(bboxes[i], ratio=0.9) print("total elapsed time: " + str(int((time.time() - start) * 1000) / 1000.0) + "s") return confidence, [bbox], [roi] ''' # Check Result if isdebug and bboxes is not None: drawBBox(origin,bboxes,debug=True) for i in range(len(rois)): showResult("cropped",rois[i]) ''' return 0.0, None, None
#https://docs.opencv.org/2.4/modules/features2d/doc/feature_detection_and_description.html#mser #https://stackoverflow.com/questions/17647500/exact-meaning-of-the-parameters-given-to-initialize-mser-in-opencv-2-4-x #https://fossies.org/dox/opencv-3.3.0/mser_8py_source.html # Text Detection #http://blog.csdn.net/windtalkersm/article/details/53027685 #http://digital.cs.usu.edu/~vkulyukin/vkweb/teaching/cs7900/Paper1.pdf # Fill in contour #https://stackoverflow.com/questions/44185854/extract-text-from-image-using-mser-in-opencv-python # opencv Python tutorial #https://github.com/opencv/opencv/tree/master/samples/python from licenseplate import LicensePlate from detector import LicensePlateDetector ### import time lp = LicensePlate() lpdetector = LicensePlateDetector() def main(): start = time.time() # Load Image image = cv2.imread(fullpath) # Load Model #detector = VehicleDetector() # Detect Vehicle bbox_car = detect(opencv2skimage(image)) #mpimg.imread(path) if bbox_car is not None: img_car = cropImg_by_BBox(image, bbox_car) # Detect License Plate start_detect_lp = time.time()