예제 #1
0
def mask2plates(img, finalmask, isdebug=False):
    #showResult("masktest",finalmask)
    #ret,binary = cv2.threshold(finalmask,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)\
    binary = compositeThreshold(finalmask, mode='otsu')
    closing = close(binary)
    if isdebug:
        showResult("mask2plates:masktest", closing)
    # Find Candidate
    return findBBox(img, closing, isdebug=isdebug)
예제 #2
0
    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
예제 #3
0
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