0% found this document useful (0 votes)
150 views

Report Raspberry Pi Project With References

This document discusses a Raspberry Pi project that uses OpenCV to count vehicles in a video feed from a road camera. It uses background subtraction to isolate moving objects, erosion to remove small contours, and moments to determine the center point of each object. If the center crosses a green line, the counter increments. The code samples show how to install OpenCV and imutils, initialize background subtraction, process each frame to identify and count vehicles, and display the output with the counter and tracking lines.

Uploaded by

mastafadhil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
150 views

Report Raspberry Pi Project With References

This document discusses a Raspberry Pi project that uses OpenCV to count vehicles in a video feed from a road camera. It uses background subtraction to isolate moving objects, erosion to remove small contours, and moments to determine the center point of each object. If the center crosses a green line, the counter increments. The code samples show how to install OpenCV and imutils, initialize background subtraction, process each frame to identify and count vehicles, and display the output with the counter and tracking lines.

Uploaded by

mastafadhil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Raspberry Pi : OpenCV Car Counter

Raspberry Pi OpenCV Car Counter is a project to count vehicles or moving objects based on video
feed from the road. Red dots will be used to count the cars, Green line will be used to as the
trajectory and will be the counter, while the Blue writings will be the counter.

We will use OpenCV and Imutils and here are the codings :

$ sudo apt-get install python-opencv


$ sudo pip install imutils

Python car-counter.py

import
cv2
backsub = cv2.BackgroundSubtractorMOG() #background subtraction to isolate moving
cars
capture = cv2.VideoCapture("/home/pi/Downloads/video.mp4")
counter = 0
x = 0
y = 0
sen = 0
minArea=1
lineCount = 50
if capture.isOpened():
ret, frame = capture.read()
else:
ret = False
while ret:
ret, frame = capture.read()
if ret==False:
break

fgmask = backsub.apply(frame, None, 0.01)


erode=cv2.erode(fgmask,None,iterations=3) #erosion to erase unwanted small
contours
moments=cv2.moments(erode,True) #moments method applied
area=moments['m00']

if moments['m00'] >=minArea:
x=int(moments['m10']/moments['m00'])
y=int (moments['m01']/moments['m00'])
if x<lineCount:
sen=sen<<1
else:
sen=(sen<<1)|1
sen=sen&0x03
if sen==1:
counter=counter+1

cv2.circle(frame,(x,y),5,(0,0,255),-1) #center, radius, colour, -1=fill

cv2.line(frame,(lineCount,0),(lineCount,200),(0,255,0),2)
font = cv2.FONT_HERSHEY_SIMPLEX
cv2.putText(frame,'counter='+str(counter), (10,30),font,1, (255, 0, 0), 2)
#cv2.putText(frame,'x='+str(x)+' y='+str(y), (10,60),font,1, (255, 0, 0), 2)
cv2.imshow("counter", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break

http://shahrulnizam.com/raspberry-pi-lesson-opencv-car-counter/
Raspberry Pi Traffic Analyzer

Hardwares Needed :

 Raspberry Pi 2 Model B ARM v7 with 1 GB RAM


 5 V 2 A switching Power Supply with MicroUSB cable
 Logitech HD Pro C920
 Monoprice flexible mini tripod
 WiPi for internet connectivity
https://www.mathworks.com/matlabcentral/fileexchange/52456-analyzing-traffic-using-a-webcam-
a-raspberry-pi-and-thingspeak

other references :

https://www.instructables.com/id/Image-Recognition-With-TensorFlow-on-Raspberry-Pi/

https://www.youtube.com/watch?v=npZ-8Nj1YwY

https://towardsdatascience.com/real-time-car-pedestrian-lane-detection-using-tensorflow-object-
detection-api-and-an-ios-fbb1b7cbb157

https://towardsdatascience.com/track-vehicles-and-people-using-yolov3-and-tensorflow-
4f3d0e5b1b5f

https://www.pyimagesearch.com/2019/12/02/opencv-vehicle-detection-tracking-and-speed-
estimation/

http://shahrulnizam.com/raspberry-pi-lesson-opencv-car-counter/
https://www.mathworks.com/matlabcentral/fileexchange/52456-analyzing-traffic-using-a-webcam-
a-raspberry-pi-and-thingspeak

https://www.mathworks.com/videos/programming-raspberry-pi-with-simulink-87003.html?
type=shadow

You might also like