예제 #1
0
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
예제 #2
0
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
예제 #3
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
예제 #4
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
예제 #5
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