0

I am busy working on some very simple vehicle detection software using Python and OpenCV. I want to take a screen capture on the moment an object hits the line I have created.

Searching on Google resulted in nothing or some very big C++ projects. Since I am very unskilled with C++ I tought I would try to ask it here.

My code:

import cv2

face_cascade = cv2.CascadeClassifier('cars.xml')
vc = cv2.VideoCapture('dataset/traffic3.mp4')

if vc.isOpened():
    rval , frame = vc.read()
else:
    rval = False

while rval:
    rval, frame = vc.read()


    cv2.line(frame, (430, 830), (430, 100),(0,255,0), 3)
    cv2.line(frame, (700, 700), (700, 100),(0,0,255), 3)

    cv2.imshow("Result",frame)
    cv2.waitKey(1);

vc.release()

So I want to take a screencapture the moment a vehicle passes on of the 2 lines?

Can somebody help me? Thanks.

  • 1
    You're just drawing a line on the frame. How are you detecting the cars? Take a look at this question: https://stackoverflow.com/questions/36254452/counting-cars-opencv-python-issue/36274515#36274515 – zindarod Oct 30 '17 at 15:43

1 Answers1

0

OpenCV's Cascade classifier will return a collection of Rect objects that correspond to bounding boxes around each car it detected in the image. If you don't know how to use the classifier, look at this tutorial in C++ to get an idea of how it works. Translating it to Python shouldn't be too hard.

Once you have these bounding boxes, you only need to test whether they intersect one of your lines to detect vehicles passing on the line.

Sunreef
  • 4,452
  • 21
  • 33