예제 #1
0
파일: meshGen.py 프로젝트: mxcube/lucid
def generate_meshing_info(imgInfo,method = LUCID_RECT_BBOX,showVisuals=False,zoom=0,virtCenter=None):

    """|
    
    :param imgInfo: Information about the input image. Two types allowed yet : Image path or Numpy array
    :type imgInfo: String or Numpy array
    :param method: Method option for the generation of meshing information
    :type method: LUCID_CENTER_PROC (for use on centering), LUCID_RECT_BBOX (for generate rectangle for meshing, return Xmin, Ymin, Xmax, Ymax), LUCID_POLY_BBOX (for generate polygon for meshing, return an array of points)
    :param showVisuals: Display for debug
    :type showVisuals: Boolean
    :param zoom: Zoom level
    :type zoom: uint
    :param virtCenter: A virtual center if reqal center use is not wanted
    :type virtCenter: Tuple (uint,uint)

    :returns: (label,x,y) result from loop_detection function

    """
   
    image=imgInfo2cvImage(imgInfo)

    image2=cv.CloneImage(image)
    image3=cv.CloneImage(image)
    cv.Zero(image3)

    #image treatment
    dilate(image,image,2)
    cv.AdaptiveThreshold(image,image2,255,cv.CV_ADAPTIVE_THRESH_MEAN_C,cv.CV_THRESH_BINARY_INV,21+50*zoom,2)   
    storage = cv.CreateMemStorage()
    contours = cv.FindContours(cv.CloneImage(image2),storage,cv.CV_RETR_EXTERNAL,cv.CV_CHAIN_APPROX_SIMPLE,(0,0))
    contours=cv.ApproxPoly(contours,storage,cv.CV_POLY_APPROX_DP,3,True);
    cv.DrawContours(image3,contours,cv.RGB(255,255,255),cv.RGB (255,255,255),2)
    #Virtual center treatment
    virtCenter = virtualCenterTreatment(image3,virtCenter)
    #Rays treatment
    store,storeInfo = findInternalPoints(image3,image,4,virtCenter)
    #Adapt rays
    ellipsecoord = fitLoop(store,storeInfo,image,virtCenter)
    imageClone = cv.CloneImage(image)
    #Choose type of box for meshing
    if method==LUCID_CENTER_PROC:
        if showVisuals:
            return getBoundingBox(method,store,storeInfo,(image.width//2,image.height//2)),imageClone,image3,store,virtCenter
        else:
            return getBoundingBox(method,store,storeInfo,(image.width//2,image.height//2)),image3
    else:
        if showVisuals:
            return getBoundingBox(method,store,storeInfo,(image.width//2,image.height//2))
        else:
            return getBoundingBox(method,store,storeInfo,(image.width//2,image.height//2))
예제 #2
0
파일: centerId.py 프로젝트: easyfox/LUCID
def face_detection(imgInfo,showVisuals=False,zoom=0):
    
    """|
    
    :param imgInfo: Information about the input image. Two types allowed yet : Image path or Numpy array
    :type imgInfo: String or Numpy array
    :param showVisuals: Display for debug
    :type showVisuals: Boolean
    :param zoom: Zoom level
    :type zoom: uint

    :returns: (label,x,y) result from loop_detection function

    """ 

    image=imgInfo2cvImage(imgInfo)

    image2=cv.CloneImage(image)
    if zoom == 0:
        cv.AdaptiveThreshold(image2,image2,255,cv.CV_ADAPTIVE_THRESH_MEAN_C,cv.CV_THRESH_BINARY_INV,45,6)
    else:
        cv.AdaptiveThreshold(image2,image2,255,cv.CV_ADAPTIVE_THRESH_MEAN_C,cv.CV_THRESH_BINARY_INV,121,6)

    image3=cv.CloneImage(image2)
    cv.Zero(image3)

    storage = cv.CreateMemStorage()
    contours = cv.FindContours(cv.CloneImage    
    (image2),storage,cv.CV_RETR_EXTERNAL,cv.CV_CHAIN_APPROX_SIMPLE,(0,0))

    cv.DrawContours(image3,contours,cv.RGB(255,255,255),cv.RGB (255,255,255),2,cv.CV_FILLED)
    cv.Smooth(image3,image3,cv.CV_MEDIAN,11)
    
    image4 = cv.CloneImage(image3)

    if zoom == 0:
        erode(image4,image4,9)
        dilate(image4,image4,9)
    else:
        erode(image4,image4,25)
        dilate(image4,image4,25)


    count = white_detect(image4)

    if showVisuals:  
        displayCv(('Resultat',image),('ErosionDilation',image4),('AdaptiveThresh',image2),('FinalTreatmentVisualisation',image3))
        cv.WaitKey(0)
    return count
예제 #3
0
파일: centerId.py 프로젝트: easyfox/LUCID
def loop_detection(imgInfo,showVisuals=False,zoom=0):

    """|

    :param imgInfo: Information about the input image. Two types allowed yet : Image path or Numpy array
    :type imgInfo: String or Numpy array
    :param showVisuals: Display for debug
    :type showVisuals: Boolean
    :param zoom: Zoom level
    :type zoom: uint

    :returns: (label,x,y) result from loop_detection function

    """
    image=imgInfo2cvImage(imgInfo)
    image2=cv.CloneImage(image)

    #if zoom == 0:
    cv.AdaptiveThreshold(image2,image2,255,cv.CV_ADAPTIVE_THRESH_MEAN_C,cv.CV_THRESH_BINARY_INV,45,6)
    #else:
        #cv.Threshold(image2,image2,30,255,cv.CV_THRESH_BINARY)

    image3=cv.CloneImage(image2)
    cv.Zero(image3)
    storage = cv.CreateMemStorage()
    contours = cv.FindContours(cv.CloneImage    
    (image2),storage,cv.CV_RETR_EXTERNAL,cv.CV_CHAIN_APPROX_SIMPLE,(0,0))

    cv.DrawContours(image3,contours,cv.RGB(255,255,255),cv.RGB (255,255,255),2,cv.CV_FILLED)
    cv.Smooth(image3,image3,cv.CV_MEDIAN,11)
    
    image4 = cv.CloneImage(image3)

    #check if the loop is in the image
    count = white_detect(image4[10:image4.height-10,10:image4.width-10])
    if count < 50:
        return ("No loop detected",-1,-1)
    
    #dilation and erosion if there is no zoom
    if zoom == 0:
        erode(image4,image4,11)
        dilate(image4,image4,11)

    count = white_detect(image4[10:image4.height-10,10:image4.width-10])
    if count < 50:
        (xcenter,ycenter) = find_approx_loop(image3)
        if showVisuals==1:
            cv.Line(image,(int(xcenter),int(0)),(int(xcenter),int(image.height)),cv.RGB(120.0,120.0,120.0))
            cv.Line(image,(int(0),int(ycenter)),(int(image.width),int(ycenter)),cv.RGB(120.0,120.0,120.0))
            displayCv(('Resultat',image),('ErosionDilation',image4),('AdaptiveThresh',image2),('FinalTreatmentVisualisation',image3))
            cv.WaitKey(0)
        return ('ApproxCoord',xcenter-15,ycenter)
    if zoom == 0:
        (xcenter,ycenter) = only_robot(image3)
        if xcenter > 0:
            if showVisuals:
                cv.Line(image,(int(xcenter),int(0)),(int(xcenter),int(image.height)),cv.RGB(120.0,120.0,120.0))
    	        cv.Line(image,(int(0),int(ycenter)),(int(image.width),int(ycenter)),cv.RGB(120.0,120.0,120.0))
                displayCv(('Resultat',image),('ErosionDilation',image4),('AdaptiveThresh',image2),('FinalTreatmentVisualisation',image3))
            return ("ArmRobot",xcenter,ycenter)
    clean_the_robot(image3,image4)
    adjust_detection(image3)
    if zoom == 0:
        (xcenter,ycenter) = calculate_center(image3,image3)
    else:
        (xcenter,ycenter) = calculate_center(image3,image3)
    if showVisuals:
        cv.Line(image,(int(xcenter),int(0)),(int(xcenter),int(image.height)),cv.RGB(120.0,120.0,120.0))
        cv.Line(image,(int(0),int(ycenter)),(int(image.width),int(ycenter)),cv.RGB(120.0,120.0,120.0))  
        displayCv(('Resultat',image),('ErosionDilation',image4),('AdaptiveThresh',image2),('FinalTreatmentVisualisation',image3))
        cv.WaitKey(0)
    return ("Coord",xcenter,ycenter)