Ask Your Question
0

Counting a point that intersect a line in opencv python

asked 2015-04-22 20:27:45 -0600

wisnu rizky gravatar image

Hello everyone, I am working in vehicle counting with opencv and python programming. I already complete step: 1. Detect moving vehicle with BackgroundSubtractorMOG2 2. Draw rectangle on it, then poin a centroid of that 3. Draw a line (to indicate of the counting)

if that centroid accros/intercept with the line I want count that 1. but in my code sometime it add sometime no. Here the line code:

cv2.line(frame,(0,170),(300,170),(200,200,0),2)

and there the centroid:

if w > 20 and h > 25: 
            cv2.rectangle(frame, (x,y), (x+w,y+h), (180, 1, 0), 1)

            x1=w/2      
            y1=h/2
            cx=x+x1
            cy=y+y1
            centroid=(cx,cy)

            cv2.circle(frame,(int(cx),int(cy)),4,(0,255,0),-1)

my counting code:

if cy==170:   
 counter=counter+1

Can anyone help me. please. for your advice thankyou!

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2015-04-23 01:04:47 -0600

You check if cy is EXACTLY on your line. But you want to know if it crossed the line. Do you have any tracking of the detected objects? In this case, you could check if the cy was below 170 in the last frame and at least 170 in the new frame. If this was the case, mark the track as counted, so that you don't count it several times.

edit flag offensive delete link more

Comments

@FooBar: thank you for your comment, actually I only want if the detected crossed over the line than it count as one. So, I used if cy==170. Sorry, if I am wrong to use that algoritm, for more detail please open this https://drive.google.com/file/d/0B-6V... for the screenshoot. Thank you for your help.

wisnu rizky gravatar imagewisnu rizky ( 2015-04-23 02:57:27 -0600 )edit
0

answered 2015-07-28 14:54:59 -0600

Did you get this to work? Could you please share the full code? Thank you :)

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-04-22 20:27:45 -0600

Seen: 5,145 times

Last updated: Apr 23 '15