def detect_by_gf(origin,
                 isdebug=False):
    if origin is None:
        return None
    # Default Size
    h,w,c = origin.shape
    size = 200.0
    # Resize
    img = cv2.resize(origin,(int(w*size/h),int(size)))   
    # Extract Good Features
    corners = refinedGoodFeatures(origin,img,
                                  model='LP')
    mask = checkFeatures(img,corners,True)
    # Find Candidate
    bboxes = findBBox(img,mask,
                      model='LP',
                      debug=True)
    # Resize
    if bboxes is not None:
        bboxes = resizeBBoxes(bboxes,h/size)
    # Check Result
    if isdebug and bboxes is not None:
        drawBBox(origin,bboxes,debug=True)
    # Crop Rois
    rois = BBoxes2ROIs(origin,bboxes)
    if isdebug and rois is not None:
        for i in range(len(rois)):
            showResult("cropped",rois[i])
            
    return bboxes,rois
Example #2
0
def processLP(image, bbox_car, bboxes_lp, confidence):
    markImg = None
    if bboxes_lp is not None:
        # Select LP with highest confidence
        bbox_lp = bboxes_lp[0]
        ###
        if confidence > 0.5:
            app.results.append(r"车牌 : 有")
            # Mark Image
            bbox_lp_refined = shiftBBoxes(
                bbox_car, [bbox_lp]) if bbox_car is not None else bbox_lp
            markImg = drawBBox(image, [bbox_lp_refined], bbox_car)
            #
            if confidence > 0.85 and bbox_car is not None:
                app.results.append(r"车牌 : 全面")
                res, reps = detect_angle(image, bbox_lp_refined, bbox_car)
                app.results.append(r"分析结果 : " + res)
                for rep in reps:
                    app.results.append(rep)
            else:
                app.results.append(r"分析结果 : 没通过")
                app.results.append(r"车牌 : 不全面")

        else:
            app.results.append(r"车牌 : 没有")
            markImg = drawBBox(image, None, bbox_car)
    else:
        app.results.append(r"车牌 : 不全面")
        markImg = drawBBox(image, None, bbox_car)
    return markImg
Example #3
0
def processLP(image,bbox_car,bboxes_lp,confidence):
    markImg = None
    if bboxes_lp is not None: 
        # Select LP with highest confidence
        bbox_lp = bboxes_lp[0]
        ###
        if confidence > 0.5:
            app.results.append(r"License plate : Yes")
            # Mark Image
            bbox_lp_refined = shiftBBoxes(bbox_car,[bbox_lp]) if bbox_car is not None else bbox_lp
            markImg = drawBBox(image,[bbox_lp_refined],bbox_car)  
            #
            if confidence > 0.85 and bbox_car is not None:
                app.results.append(r"License plate : FRONT")                                    
                res,reps = detect_angle(image,bbox_lp_refined,bbox_car)
                app.results.append(r"Analysis result : " + res)
                for rep in reps:
                    app.results.append(rep)
            else:
                app.results.append(r"Analysis result : No Pass " + str(confidence))
                app.results.append(r"License plate : No Front")

        else:
            app.results.append(r"License plate : NO")
            markImg = drawBBox(image,None,bbox_car)
    else:
        app.results.append(r"License plate : No Front")
        markImg = drawBBox(image,None,bbox_car)
    return markImg
Example #4
0
 def detect_by_data(self, img, debug=False):
     # Detect
     bbox = self.detect(img)  #mpimg.imread(path)
     # Check Result
     if bbox is not None and debug:
         drawBBox(img, [bbox])
     ##
     return bbox
Example #5
0
def detect(img, debug=False):

    rclasses, rscores, rbboxes = process_image(img)
    #visualization.plt_bboxes(img, rclasses, rscores, rbboxes)
    # Refine BBoxes
    bbox = VehicleDetector.pick_one_vehicle(img, rclasses, rscores, rbboxes)
    if debug:
        drawBBox(img, [bbox], drawmline=False)
    return bbox
Example #6
0
 def detect_by_filename(self, path, debug=False):
     # Load File
     img = mpimg.imread(path)  #img = cv2.imread(path)
     # Detect
     bbox = self.detect(img)  #mpimg.imread(path)
     # Check Result
     if bbox is not None and debug:
         drawBBox(img, [bbox])
     ##
     return bbox
def detect_by_seg_gf(origin,
                     isdebug=False):
    if origin is None:
        return None
    # Default Size
    h,w,c = origin.shape
    size = 200.0
    #origin = opencv2skimage(origin)
    # Resize
    img = cv2.resize(origin,(int(w*size/h),int(size)))
    # Blur
    blur = cv2.GaussianBlur(img,(5,5),3)
    # Equalization Hist
    #origin = equalizehist(origin)
    
    # Extract Good Features
    corners = refinedGoodFeatures(origin,img,
                                  model='LP')
    corners_,handwrite =  refinedCorners(img,corners,False)
    checkFeatures(img,corners,True)
    # Opencv2Skimage
    skimg = cv2.cvtColor(blur, cv2.COLOR_BGR2RGB)
    # Segmentation
    out,labels = seg(skimg,Debug=False)
    # Eval Label
    labels = refineLabels(out,labels,corners_,howmany=20)
    # Show Result
    out = drawLabels(skimg,labels,Debug=isdebug)
    if out is None:
        return None
    changebgcolr(out,labels)
    #showResult("labelout",skimage2opencv(out))
    # Find Candidate 
    bboxes = findBBox(img,out,
                      model='LP',
                      debug=isdebug)
    # Resize
    if bboxes is not None:
        bboxes = resizeBBoxes(bboxes,h/size)
    # Check Candidate
    if isdebug and bboxes is not None:
        drawBBox(origin,bboxes,debug=isdebug)
    # Crop Rois
    rois = BBoxes2ROIs(origin,bboxes)
    if isdebug and rois is not None:
        for i in range(len(rois)):
            showResult("cropped",rois[i])
    '''
    if isdebug:
        #labels2boundaries(labels)
        contours = labels2contours(labels)
        drawBBox(img,contours,debug=True)
    '''
    return bboxes,rois
def detect_by_probability(origin,
                 isdebug=False):
    if origin is None:
        return None
    # Default Size
    h,w,c = origin.shape
    size = 200.0
    # Resize
    img = cv2.resize(origin,(int(w*size/h),int(size)))
    #showResult("img",img)
    #  
    if dayornight(img):
        # Extract Good Features
        corners = refinedGoodFeatures(origin,img)
        mask = checkFeatures(img,corners,False)
        closing=close(mask)
        refined_gfmask = refine_gfimage(img,closing)
        #showResult("refined_gfmask",refined_gfmask)
        finalmask = mkfinalmask(img,refined_gfmask,isday=True)
    else:
        finalmask = mkfinalmask(img,None,isday=False)
    #
    #showResult("masktest",finalmask)
    #ret,binary = cv2.threshold(finalmask,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
    binary = compositeThreshold(finalmask,mode='otsu')
    kernel = cv2.getStructuringElement(cv2.MORPH_RECT,(5,5))
    closing=cv2.morphologyEx(binary, cv2.MORPH_CLOSE, kernel)
    if isdebug:
        showResult("masktest",closing)
    # Find Candidate
    bboxes = findBBox(img,closing,isdebug=True)
    # Resize
    if bboxes is not None:
        bboxes = resizeBBoxes(bboxes,h/size)
    # Check Result
    if isdebug and bboxes is not None:
        drawBBox(origin,bboxes,debug=True)
    # Crop Rois
    rois = BBoxes2ROIs(origin,bboxes)
    if isdebug and rois is not None:
        for i in range(len(rois)):
            showResult("cropped",rois[i])
            
    return bboxes,rois
Example #9
0
def detect_by_cascade(origin, resize_h=720, en_scale=1.06, isdebug=False):
    if origin is None:
        return None
    # Default Size
    height, width, channels = origin.shape
    # Resize
    resized = cv2.resize(origin, (int(width * resize_h / height), resize_h))
    # Colr2Gray
    gray = cv2.cvtColor(resized, cv2.COLOR_RGB2GRAY)
    # Detect by Cascade
    watches = watch_cascade.detectMultiScale(gray,
                                             en_scale,
                                             1,
                                             minSize=(36, 9))

    cropped_images = []
    bboxes = []
    for (x, y, w, h) in watches:
        xmin = x - w * 0.1
        ymin = y - h * 0.6
        xmin = xmin if xmin >= 0 else 0
        xmin = ymin if ymin >= 0 else 0
        xmax = xmin + 1.2 * w
        ymax = ymin + 1.1 * h
        bboxes.append(
            np.array([[xmin, ymin], [xmax, ymin], [xmax, ymax], [xmin, ymax]]))

        cropped = cropped_from_image(
            gray, (int(xmin), int(ymin), int(1.2 * w), int(1.1 * h)))
        cropped_images.append(cropped)
    # Resize
    if bboxes is not None:
        bboxes = resizeBBoxes(bboxes, height / float(resize_h))

    # Check Result
    if isdebug and bboxes is not None:
        drawBBox(origin, bboxes, debug=True)
    # Crop Rois
    rois = BBoxes2ROIs(origin, bboxes)
    if isdebug and rois is not None:
        for i in range(len(rois)):
            showResult("cropped", rois[i])

    return bboxes, rois  #cropped_images
Example #10
0
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()
        confidence, bboxes_lp, rois = lpdetector.process(img_car)
        print("detecting LP elapsed time: " +
              str(int((time.time() - start_detect_lp) * 1000) / 1000.0) + "s")
        # Check Result
        if bboxes_lp is not None:
            bboxes_lp_refined = shiftBBoxes(bbox_car, bboxes_lp)
            print "confidence:", confidence
            drawBBox(image, bboxes_lp_refined, bbox_car, debug=True)
            '''
            for roi in rois:
                start_refine_lp = time.time()
                lp.process(roi,isdebug=True)
                print("refining LP elapsed time: "+str(int((time.time() - start_refine_lp)*1000)/1000.0)+"s")
                #pipline.recognizeLP2(seg_blocks,mid)
                print("confidence:"+str(lp.confidence*100)+"%")
            '''

        else:
            drawBBox(image, None, bbox_car, debug=True)
    else:
        start_detect_lp = time.time()
        confidence, bboxes_lp, rois = lpdetector.process(image)
        print("detecting LP elapsed time: " +
              str(int((time.time() - start_detect_lp) * 1000) / 1000.0) + "s")
        if bboxes_lp is not None:
            print "confidence:", confidence
            drawBBox(image, bboxes_lp, None, debug=True)

    print("total elapsed time: " +
          str(int((time.time() - start) * 1000) / 1000.0) + "s")