Example #1
0
def find_loop_mesh(imgInfo, showVisuals=False, zoom=0, virtCenter=(-1,-1)):
    """|
    
    :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
    :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

    """
    if showVisuals:
        (x,y,x2,y2),imageClone,image3,store,virtCenter = meshGen.generate_meshing_info(imgInfo,method=meshGen.LUCID_CENTER_PROC,showVisuals=showVisuals,zoom=zoom,virtCenter=virtCenter)
        cv.Rectangle(imageClone,(x,y),(x2,y2),cv.Scalar( 120, 120, 120 ))
    else:
        (x,y,x2,y2),image3 = meshGen.generate_meshing_info(imgInfo,method=meshGen.LUCID_CENTER_PROC,showVisuals=showVisuals,zoom=zoom,virtCenter=virtCenter)
   
    xres = x2-((x2-x)//2)
    yrestemp = -1
    yrestemp2 = -1
    yres = 0
    while y<y2 and (yrestemp < 0 or yrestemp2 < 0):
        y+=1
        y2-=1
        if image3[y,xres]>0:
            yrestemp = y
        if image3[y2,xres]>0:
            yrestemp2 = y2
    if y>=y2:
        yres = y2-((y2-y)//2)
    else:
        yres = yrestemp2 - ((yrestemp2-yrestemp)//2)
    if showVisuals:
        for num in range(len(store)):
             cv.Line( image3, virtCenter, store[num],cv.Scalar( 120, 120, 120 ),2,8 );
	cv.Line( imageClone, (xres-3,yres-3), (xres+3,yres+3),cv.Scalar( 120, 120, 120 ),2,8 );
	cv.Line( imageClone, (xres-3,yres+3), (xres+3,yres-3),cv.Scalar( 120, 120, 120 ),2,8 );

        cv.Line( imageClone, (virtCenter[0],virtCenter[1]-3), (virtCenter[0],virtCenter[1]+3),cv.Scalar( 120, 120, 120 ),2,8 );
	cv.Line( imageClone, (virtCenter[0]-3,virtCenter[1]), (virtCenter[0]+3,virtCenter[1]),cv.Scalar( 120, 120, 120 ),2,8 );
        #real center
        cv.Line( imageClone, ((659//2),(463//2)-15), ((659//2),(463//2)+15),cv.Scalar( 120, 120, 120 ),2,8 );
        cv.Line( imageClone, ((659//2)-15,(463//2)), ((659//2)+15,(463//2)),cv.Scalar( 120, 120, 120 ),2,8 );

        displayCv(('Resultat',imageClone),('RaysVisu',image3))
	cv.WaitKey(0)
    return "meshing",xres,yres
Example #2
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
Example #3
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)