Esempio n. 1
0
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
Esempio n. 2
0
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)