Ejemplo n.º 1
0
    def localize(self, tags):
        global arr_blob_pos
	arr_blob_pos = []
	for tag in tags.tags:
	    for color_rec in arr_color_codes:
            	if (color_rec[3]== tag.id):
		    #print "Got a tag of interest"
		    #This blob should be converted to a tag. Do it
                    blob_from_tag = Blob()
		    blob_from_tag.red = color_rec[0]
		    blob_from_tag.green = color_rec[1]
		    blob_from_tag.blue = color_rec[2]
                    blob_from_tag.x = tag.x
                    blob_from_tag.y = tag.y
		    arrx = [tag.cwCorners[0], tag.cwCorners[2], tag.cwCorners[4], tag.cwCorners[6]]
		    arry = [tag.cwCorners[1], tag.cwCorners[3], tag.cwCorners[5], tag.cwCorners[7]]
		    minx = min(arrx)
		    maxx = max(arrx)
                    miny = min(arry)
                    maxy = max(arry)
		    if (minx < 0):
			minx = 0
		    if (maxx < 0):
			maxx = 0
		    if (miny < 0):
			miny = 0
		    if (maxy < 0):
			maxy = 0
		    blob_from_tag.left = int(minx)
		    blob_from_tag.top = int(miny)
		    blob_from_tag.right = int(maxx)
		    blob_from_tag.bottom = int(maxy)
	            arr_blob_pos.append(blob_from_tag)
Ejemplo n.º 2
0
def mergeBlobs(blobs):
    x = 0;
    y = 0;
    left = 0;
    right = 0;
    top = 0;
    bottom = 0;
    area = 0;
    for b in blobs:
        x = x + (b.x * b.area)
        y = y + (b.y * b.area)
        left = left + (b.left * b.area)
        right = right + (b.right * b.area)
        top = top + (b.top * b.area)
        bottom = bottom + (b.bottom * b.area)
        area = area + b.area
    result = Blob()
    result.x = x / area
    result.y = y / area
    result.left = left / area
    result.right = right / area
    result.top = top / area
    result.bottom = bottom / area
    result.area = x * y
    return result
Ejemplo n.º 3
0
 def localize(self, tags):
     global arr_blob_pos
     arr_blob_pos = []
     for tag in tags.tags:
         for color_rec in arr_color_codes:
             if color_rec[3] == tag.id:
                 # print "Got a tag of interest"
                 # This blob should be converted to a tag. Do it
                 blob_from_tag = Blob()
                 blob_from_tag.red = color_rec[0]
                 blob_from_tag.green = color_rec[1]
                 blob_from_tag.blue = color_rec[2]
                 blob_from_tag.x = tag.x
                 blob_from_tag.y = tag.y
                 arrx = [tag.cwCorners[0], tag.cwCorners[2], tag.cwCorners[4], tag.cwCorners[6]]
                 arry = [tag.cwCorners[1], tag.cwCorners[3], tag.cwCorners[5], tag.cwCorners[7]]
                 minx = min(arrx)
                 maxx = max(arrx)
                 miny = min(arry)
                 maxy = max(arry)
                 if minx < 0:
                     minx = 0
                 if maxx < 0:
                     maxx = 0
                 if miny < 0:
                     miny = 0
                 if maxy < 0:
                     maxy = 0
                 blob_from_tag.left = int(minx)
                 blob_from_tag.top = int(miny)
                 blob_from_tag.right = int(maxx)
                 blob_from_tag.bottom = int(maxy)
                 arr_blob_pos.append(blob_from_tag)
Ejemplo n.º 4
0
def mergeBlobs(blobs):
    global tempBlobs3
    x = 0;
    y = 0;
    left = 0;
    right = 0;
    top = 0;
    bottom = 0;
    area = 0;
    bigBlob = Blob()
    result = Blob()   
    tempBlobs = copy.deepcopy(blobs)
    tempBlobs = [x for x in tempBlobs if x.name == "Green"]
    temp2Blobs = copy.deepcopy(tempBlobs)
    tempBlobs3 = copy.deepcopy(tempBlobs)
    endBlobs = []
    xDistance = 0
    yDistance = 0
    maxXDistance = 0
    maxYDistance = 0
    while len(tempBlobs) > 0:
        for b in tempBlobs:
            if b.area > area:
                area = b.area
                bigBlob = copy.deepcopy(b)
        area = 0
        
        size = len(tempBlobs)
        counter = 0
        while counter < size:
            counter = 0
            size = len(tempBlobs)
            for c in tempBlobs:
                xDistance = abs(((bigBlob.right - bigBlob.left)/2 + bigBlob.left) - ((c.right - c.left)/2 + c.left))              
                yDistance = abs(((bigBlob.bottom - bigBlob.top)/2 + bigBlob.top) - ((c.bottom - c.top)/2 + c.top))
                maxXDistance = abs(abs((bigBlob.right - bigBlob.left)/2) + abs((c.right - c.left)/2))
                maxYDistance = abs(abs((bigBlob.bottom - bigBlob.top)/2) + abs((c.bottom - c.top)/2))
                if (maxXDistance >= xDistance and maxYDistance >= yDistance) and bigBlob.left > c.left:
                    bigBlob.left = c.left
                if (maxXDistance >= xDistance and maxYDistance >= yDistance) and bigBlob.right < c.right:
                    bigBlob.right = c.right
                if (maxXDistance >= xDistance and maxYDistance >= yDistance) and bigBlob.top > c.top:
                    bigBlob.top = c.top
                if (maxXDistance >= xDistance and maxYDistance >= yDistance) and bigBlob.bottom < c.bottom:
                    bigBlob.bottom = c.bottom
                if (maxXDistance >= xDistance and maxYDistance >= yDistance):
                    temp2Blobs.remove(c)
                else: 
                    counter = counter + 1
                bigBlob.area = abs((bigBlob.right - bigBlob.left)*(bigBlob.top - bigBlob.bottom))
                bigBlob.x = (bigBlob.right - bigBlob.left)/2 + bigBlob.left
                bigBlob.y = (bigBlob.bottom - bigBlob.top)/2 + bigBlob.top
            tempBlobs = copy.deepcopy(temp2Blobs)
        endBlobs.append(copy.deepcopy(bigBlob))
    area = 0
    for d in endBlobs:
        if d.area > area:
            area = d.area
            result = copy.deepcopy(d)
    return result
def mergeBlobs(blobsInfo):
    x = 0
    y = 0
    left = 0
    right = 0
    top = 0
    bottom = 0
    area = 0

    overlapsFound = 1
    blobs = blobsInfo.blobs

    for b in blobs:

        blobs2 = copy.deepcopy(blobs)

        for b2 in blobs2:
            if (b.name == b2.name and b != b2):
                overlapping = 0

                blobx = b2.left
                while blobx < b2.right and overlapping == 0:
                    bloby = b2.top
                    while bloby < b2.bottom and overlapping == 0:
                        if blobx >= b.left and blobx <= b.right and bloby >= b.top and bloby <= b.bottom:
                            overlapping = 1
                        bloby = bloby + 1
                    blobx = blobx + 1

                if overlapping == 1:
                    x = b.x + (b2.x * b2.area)
                    y = b.y + (b2.y * b2.area)
                    left = b.left + (b2.left * b2.area)
                    right = b.right + (b2.right * b2.area)
                    top = b.top + (b2.top * b2.area)
                    bottom = b.bottom + (b2.bottom * b2.area)
                    area = b.area + b2.area

                    result = Blob()
                    result.x = x / area
                    result.y = y / area
                    result.left = left / area
                    result.right = right / area
                    result.top = top / area
                    result.bottom = bottom / area
                    result.area = x * y

                    b = result
                    blobs.remove(b2)

    return blobs
Ejemplo n.º 6
0
def mergeBlobs(blobs):
    global bigBlob, pub
    x = 0
    y = 0
    left = 0
    right = 0
    top = 0
    bottom = 0
    area = 0

    # Sort the blobs and find the big blob
    bBA = 0
    for blob in blobs:
        if blob.area > bBA:
            bBA = blob.area
            bigBlob = blob

    # Filter blobs, remove all blobs not within area
    blobs = filter(filterBlob, blobs)
    if len(blobs) == 0:
        blobs.append(bigBlob)
    firstBlob = blobs[0]
    maxLeft = firstBlob.left
    maxRight = firstBlob.right
    maxTop = firstBlob.top
    maxBottom = firstBlob.bottom

    for blob in blobs:
        maxLeft = blob.left if blob.left < maxLeft else maxLeft
        maxRight = blob.right if blob.right > maxRight else maxRight
        maxTop = blob.top if blob.top < maxTop else maxTop
        maxBottom = blob.bottom if blob.bottom > maxBottom else maxBottom

    # Create new blob based on prior blobs (i.e. merged)
    result = Blob()
    result.x = (maxLeft + maxRight) / 2
    result.y = (maxTop + maxBottom) / 2
    result.left = maxLeft
    result.right = maxRight
    result.top = maxTop
    result.bottom = maxBottom
    result.area = x * y

    pub.publish(result.x)
    print "Error: ", result.x - 320
    return result
Ejemplo n.º 7
0
def mergeBlobs(blobs):
    x = 0
    y = 0
    left = 0
    right = 0
    top = 0
    bottom = 0
    area = 0
    bigBlob = Blob()
    result = Blob()
    blobCopy = copy.deepcopy(blobs)
    tempBlobs = [x for x in blobCopy if x.name == "Out"]
    temp2Blobs = copy.deepcopy(tempBlobs)
    tempBlobs2 = [x for x in blobCopy if x.name == "In"]
    temp2Blobs2 = copy.deepcopy(tempBlobs2)
    endBlobs = []
    endBlobs2 = []
    endBlobs3 = []
    xDistance = 0
    yDistance = 0
    maxXDistance = 0
    maxYDistance = 0
    while len(tempBlobs) > 0:
        for b in tempBlobs:
            if b.area > area:
                area = b.area
                bigBlob = copy.deepcopy(b)
        area = 0

        size = len(tempBlobs)
        counter = 0
        while counter < size:
            counter = 0
            size = len(tempBlobs)
            for c in tempBlobs:
                xDistance = abs((
                    (bigBlob.right - bigBlob.left) / 2 + bigBlob.left) -
                                ((c.right - c.left) / 2 + c.left))
                yDistance = abs((
                    (bigBlob.bottom - bigBlob.top) / 2 + bigBlob.top) -
                                ((c.bottom - c.top) / 2 + c.top))
                maxXDistance = abs(
                    abs((bigBlob.right - bigBlob.left) / 2) +
                    abs((c.right - c.left) / 2))
                maxYDistance = abs(
                    abs((bigBlob.bottom - bigBlob.top) / 2) +
                    abs((c.bottom - c.top) / 2))
                if (maxXDistance >= xDistance and
                        maxYDistance >= yDistance) and bigBlob.left > c.left:
                    bigBlob.left = c.left
                if (maxXDistance >= xDistance and
                        maxYDistance >= yDistance) and bigBlob.right < c.right:
                    bigBlob.right = c.right
                if (maxXDistance >= xDistance
                        and maxYDistance >= yDistance) and bigBlob.top > c.top:
                    bigBlob.top = c.top
                if (maxXDistance >= xDistance and maxYDistance >= yDistance
                    ) and bigBlob.bottom < c.bottom:
                    bigBlob.bottom = c.bottom
                if (maxXDistance >= xDistance and maxYDistance >= yDistance):
                    temp2Blobs.remove(c)
                else:
                    counter = counter + 1
                bigBlob.area = abs((bigBlob.right - bigBlob.left) *
                                   (bigBlob.top - bigBlob.bottom))
                bigBlob.x = (bigBlob.right - bigBlob.left) / 2 + bigBlob.left
                bigBlob.y = (bigBlob.bottom - bigBlob.top) / 2 + bigBlob.top
            tempBlobs = copy.deepcopy(temp2Blobs)
        endBlobs.append(copy.deepcopy(bigBlob))
    while len(tempBlobs2) > 0:
        for b in tempBlobs2:
            if b.area > area:
                area = b.area
                bigBlob = copy.deepcopy(b)
        area = 0

        size = len(tempBlobs2)
        counter = 0
        while counter < size:
            counter = 0
            size = len(tempBlobs2)
            for c in tempBlobs2:
                xDistance = abs((
                    (bigBlob.right - bigBlob.left) / 2 + bigBlob.left) -
                                ((c.right - c.left) / 2 + c.left))
                yDistance = abs((
                    (bigBlob.bottom - bigBlob.top) / 2 + bigBlob.top) -
                                ((c.bottom - c.top) / 2 + c.top))
                maxXDistance = abs(
                    abs((bigBlob.right - bigBlob.left) / 2) +
                    abs((c.right - c.left) / 2))
                maxYDistance = abs(
                    abs((bigBlob.bottom - bigBlob.top) / 2) +
                    abs((c.bottom - c.top) / 2))
                if (maxXDistance >= xDistance and
                        maxYDistance >= yDistance) and bigBlob.left > c.left:
                    bigBlob.left = c.left
                if (maxXDistance >= xDistance and
                        maxYDistance >= yDistance) and bigBlob.right < c.right:
                    bigBlob.right = c.right
                if (maxXDistance >= xDistance
                        and maxYDistance >= yDistance) and bigBlob.top > c.top:
                    bigBlob.top = c.top
                if (maxXDistance >= xDistance and maxYDistance >= yDistance
                    ) and bigBlob.bottom < c.bottom:
                    bigBlob.bottom = c.bottom
                if (maxXDistance >= xDistance and maxYDistance >= yDistance):
                    temp2Blobs2.remove(c)
                else:
                    counter = counter + 1
                bigBlob.area = abs((bigBlob.right - bigBlob.left) *
                                   (bigBlob.top - bigBlob.bottom))
                bigBlob.x = (bigBlob.right - bigBlob.left) / 2 + bigBlob.left
                bigBlob.y = (bigBlob.bottom - bigBlob.top) / 2 + bigBlob.top
            tempBlobs2 = copy.deepcopy(temp2Blobs2)
        endBlobs2.append(copy.deepcopy(bigBlob))
    area = 0
    for d in endBlobs:
        for e in endBlobs2:
            if (d.left < e.left and d.right > e.right and d.top < e.top
                    and d.bottom > e.bottom):
                endBlobs3.append(d)
    area = 0
    for f in endBlobs3:
        if f.area > area:
            area = f.area
            result = copy.deepcopy(f)
    return result
Ejemplo n.º 8
0
def mergeBlobs(blobs):
    global bigRedBlob,bigPinkBlob, pub
    x = 0
    y = 0
    left = 0
    right = 0
    top = 0
    bottom = 0
    area = 0
    
    pinkBlobs = []
    redBlobs = []
    
    for blob in blobs:
        if blob.name == "BallRed":
            redBlobs.append(blob)
        elif blob.name == "GoalPink":
            pinkBlobs.append(blob)

    # Sort the blobs and find the big blob
    bBA = 0
    for blob in redBlobs:
        if blob.area > bBA:
            bBA = blob.area
            bigRedBlob = blob
    bBA = 0
    for blob in pinkBlobs:
        if blob.area > bBA:
            bBA = blob.area
            bigPinkBlob = blob

    # Filter blobs, remove all blobs not within area
    pBlobs = filter(filterBlob, pinkBlobs)
    rBlobs = filter(filterBlob, redBlobs)
    if len(pBlobs) == 0: 
        pBlobs.append(bigPinkBlob)
    if len(rBlobs) == 0:
        rBlobs.append(bigRedBlob)
    
    firstPinkBlob = pBlobs[0]
    maxLeft = firstPinkBlob.left
    maxRight = firstPinkBlob.right
    maxTop = firstPinkBlob.top
    maxBottom = firstPinkBlob.bottom

    for blob in pBlobs:
        maxLeft = blob.left if blob.left < maxLeft else maxLeft
        maxRight = blob.right if blob.right > maxRight else maxRight
        maxTop = blob.top if blob.top < maxTop else maxTop
        maxBottom = blob.bottom if blob.bottom > maxBottom else maxBottom

    # Create new blob based on prior blobs (i.e. merged)
    pResult = Blob()
    pResult.x = (maxLeft + maxRight) / 2
    pResult.y = (maxTop + maxBottom) / 2 
    pResult.left = maxLeft
    pResult.right = maxRight
    pResult.top = maxTop
    pResult.bottom = maxBottom
    pResult.area = x * y
    pResult.name = firstPinkBlob.name
    
    firstRedBlob = rBlobs[0]
    maxLeft = firstRedBlob.left
    maxRight = firstRedBlob.right
    maxTop = firstRedBlob.top
    maxBottom = firstRedBlob.bottom

    for blob in rBlobs:
        maxLeft = blob.left if blob.left < maxLeft else maxLeft
        maxRight = blob.right if blob.right > maxRight else maxRight
        maxTop = blob.top if blob.top < maxTop else maxTop
        maxBottom = blob.bottom if blob.bottom > maxBottom else maxBottom
    
    rResult = Blob()
    rResult.x = (maxLeft + maxRight) / 2
    rResult.y = (maxTop + maxBottom) / 2
    rResult.left = maxLeft 
    rResult.right = maxRight
    rResult.top = maxTop
    rResult.bottom = maxBottom
    rResult.area = x * y
    rResult.name = firstRedBlob.name
    
    blobArray = Blobs()
    blobArray.blobs = [pResult, rResult]
    pub.publish(blobArray)
    return blobArray