mercredi 18 juillet 2018

How to collect tuple values in if statement?

I have a code which consists of if statement in for loop as below,

for i in range(len(contours)):

    x, y, w, h = cv2.boundingRect(contours[i])
    mask[y:y+w, x:x+w] = 0
    cv2.drawContours(mask, contours, i, (255, 255, 255), -1)
    r = float(cv2.countNonZero(mask[y:y+h, x:x+w])) / (w * h)

    if r > 0.5 and w > 8 and h > 8:
        cv2.rectangle(rgb, (x, y), (x+w, y+h), (255, 255, 255), -1)
        cv2.circle(rgb, (x+w/2,y+h/2), 3, (180, 25, 20), -1)
        start_target_states = x+w/2 , y+h/2
        print "start_target_states: %s" % (start_target_states,)

when running this code, it results as below;

start_target_states: (704, 463)
start_target_states: (83, 15)

However, start_target_states variable must be named as start_state for the first result, afterwards, it must be named as target_state for the second result. For example;

target_state: (704, 463)
start_state: (83, 15)

Moreover, I want to assign these two tuples to variable name. So that I can use them later.I mean,

TargetState = target_state
StartState = start_state

I have tried to modify if statement to reach my purpose, unfortunately I could not get succeed. How can I do what I want?

Aucun commentaire:

Enregistrer un commentaire