sam
sam

Reputation: 494

how to use counter if a certain condition is met?

I am working on a video analysis project. I have a situation where if a person comes in front of the object (e.g. bag)(bounding boxes intersect ) my pre-defined function should wait for 100 counts before calling it as a belonging of a person. I have written the following code :

count = 0
iou_value = oneObject.intersection_over_union(image,humanRegion_bbs,belongings_bbs)
if iou_value is not None and iou_value > th_iou and count > 100 :
        oneObject.setBelongings(belongingsList) #this sets the belongings to the person

I want this setBelongings() to wait for 100 counts before running. This is just a part of a long code I have added. The whole code runs once each frame of a video

Upvotes: 0

Views: 64

Answers (1)

Andreas
Andreas

Reputation: 2521

You could split the if condition into 2 part. Check for iou_value in the first if and if the condition is false, reset the count to 0. If the condition is true, check whether the count value exceeds 100. If that is true, execute setBelongings

iou_value = oneObject.intersection_over_union(image,humanRegion_bbs,belongings_bbs)

if iou_value is not None and iou_value > th_iou:
    if count > 100 :
        oneObject.setBelongings(belongingsList) #this sets the belongings to the person
else:
    count = 0

Upvotes: 1

Related Questions