pythonsimplecvblobs

Using X and Y positions from different tuples as input \


I need to use the x and y positions of two separate tuples as a single tuple in order to input it into the next part of my code, any help is appreciated.

img1 = Image('img1.jpg')
blobs1 = img1.findBlobs()
if blobs1:
    print blobs1
else:
    print ERROR

img2 = Image('img2.jpg')
blobs2 = img2.findBlobs()
if blobs2:
    print blobs2
else:
    print ERROR

This prints two lines

[SimpleCV.Features.Blob.Blob object at (500, 600) with area 50]
[SimpleCV.Features.Blob.Blob object at (200, 800) with area 67]

How can I use the X position of the first line and the Y position of the second line as the X- and Y-positions of a new tuple, to obtain the color at the new XY position in a different image?

pixcol = Image('img.jpg')
colrgb = pixcol[ 'new XY tuple' ] 
print colrgb

Solution

  • EDITED

    use blob.coordinates()

    pixcol = Image('img.jpg')
    
    tup1 = pixcol.findBlobs().x # tup1 = X
    tup2 = pixcol.findBlobs().y # tup2 = Y
    
    colrgb = pixcol[(tup1,tup2)] # insert the tuple
    print colrgb
    

    So in your real code, you'd have:

    ...
    if blobs1:
        tup1 = blobs1.x
    ...
    if blobs2:
        tup2 = blobs2.x
    ...
    pixcol = Image('img.jpg')
    colrgb = pixcol[(tup1,tup2)]
    print colrgb