# Detect Speed with a Raspberry Pi, Camera and OpenCV

**URL:** <https://forum.core-electronics.com.au/t/detect-speed-with-a-raspberry-pi-camera-and-opencv/11784>\
**Category:** Guides\
**Created:** [12 October 2021 02:11 UTC](https://forum.core-electronics.com.au/t/detect-speed-with-a-raspberry-pi-camera-and-opencv/11784 "2021-10-12T02:11:21Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![Tim](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/tim/32/3324_2.png) [@Tim](https://forum.core-electronics.com.au/u/Tim)\
**Post date:** [30 August 2022 23:29 UTC](https://forum.core-electronics.com.au/t/detect-speed-with-a-raspberry-pi-camera-and-opencv/11784/21 "2022-08-30T23:29:44Z")

</div>

Heyya mates @HaRmX96210944@odje210947 ,

So long as you have enabled the toggle switch that you can see in the image below you will have a web server that you can access. This will also provide you with an IP Address that you can type into the URL of any internet browser on any locally connected device. With that IP Address (it will look like something like **| [http://172.17.0.1:8080](http://172.17.0.1:8080) |** ) typed and entered into the URL you will access the speed-cam web server. You may have to enter a username and password if it is your first time.

 ![image](https://canada1.discourse-cdn.com/flex028/uploads/core_electronics/original/2X/8/889429f191d130714bd91b13ae9b7b38656bb544.jpeg)

Hopefully that helps you both 😊,  
Tim

---

<div class="post-metadata">

**Author:** ![HaRmX96210944](https://avatars.discourse-cdn.com/v4/letter/h/47e85d/32.png) [@HaRmX96210944](https://forum.core-electronics.com.au/u/HaRmX96210944)\
**Post date:** [31 August 2022 03:27 UTC](https://forum.core-electronics.com.au/t/detect-speed-with-a-raspberry-pi-camera-and-opencv/11784/22 "2022-08-31T03:27:52Z")

</div>

sorry but i cant access

---

<div class="post-metadata">

**Author:** ![Douglas250260](https://avatars.discourse-cdn.com/v4/letter/d/958977/32.png) [@Douglas250260](https://forum.core-electronics.com.au/u/Douglas250260)\
**Post date:** [11 June 2023 20:37 UTC](https://forum.core-electronics.com.au/t/detect-speed-with-a-raspberry-pi-camera-and-opencv/11784/23 "2023-06-11T20:37:38Z")

</div>

Hi & thanks for the material!

I am new to Raspberry Pi although I have now 2 Pi 4 B’s. Having gone through the tutorial 2x I have been able to pull up an operational speed camera menu box but cannot access the output via a web page. Using a Pi camera v2 camera, the camera is not seen in the Raspberry Pi Configuration interface choices but using sudo raspi-config I1 shows Legacy Camera enable and getting images with raspistill.

I have hours into this and willing to pay for support.

Please advise, thanks in advance DAG

---

<div class="post-metadata">

**Author:** ![Grant184682](https://avatars.discourse-cdn.com/v4/letter/g/e68b1a/32.png) [@Grant184682](https://forum.core-electronics.com.au/u/Grant184682)\
**Post date:** [14 July 2023 00:17 UTC](https://forum.core-electronics.com.au/t/detect-speed-with-a-raspberry-pi-camera-and-opencv/11784/24 "2023-07-14T00:17:27Z")

</div>

Looks like this thread has gone a bit quiet and a few folk with unresolved problems, somewhat discouraging. I have same issue as previous 2 posters. Pi4B 4GB, Buster and Pi HQ camera. Camera working tested with raspistill and webpage available locally which displays the webserver.txt file only. The speedcam is not recording anything (tested with a toy car on the workbench). Also , the ip address displayed in the menu item B is not the same as my pi address as seen on the router. If I try the ip address in the menu item B then there is no page displayed.

Any assistance will be appreciated  
Many thanks

---

<div class="post-metadata">

**Author:** ![Grant184682](https://avatars.discourse-cdn.com/v4/letter/g/e68b1a/32.png) [@Grant184682](https://forum.core-electronics.com.au/u/Grant184682)\
**Post date:** [15 July 2023 07:24 UTC](https://forum.core-electronics.com.au/t/detect-speed-with-a-raspberry-pi-camera-and-opencv/11784/25 "2023-07-15T07:24:50Z")

</div>

I have success now just following the install guide on the github page. The install process is also much faster.

---

<div class="post-metadata">

**Author:** ![Michael261434](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@Michael261434](https://forum.core-electronics.com.au/u/Michael261434)\
**Post date:** [27 November 2023 23:29 UTC](https://forum.core-electronics.com.au/t/detect-speed-with-a-raspberry-pi-camera-and-opencv/11784/26 "2023-11-27T23:29:53Z")

</div>

I’ve been looking through the code, is there a way to convert KPH to MPH within the program?

---

<div class="post-metadata">

**Author:** ![Jeff105671](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/jeff105671/32/3729_2.png) [@Jeff105671](https://forum.core-electronics.com.au/u/Jeff105671)\
**Post date:** [28 November 2023 00:24 UTC](https://forum.core-electronics.com.au/t/detect-speed-with-a-raspberry-pi-camera-and-opencv/11784/27 "2023-11-28T00:24:35Z")

</div>

The code can be found here:  
[speed-camera/speed-cam.py at master](https://github.com/pageauc/speed-camera/blob/master/speed-cam.py)

The settings start at line 87. The one you want is “MO\_SPEED\_MPH\_ON”.

---

<div class="post-metadata">

**Author:** ![Michael261434](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@Michael261434](https://forum.core-electronics.com.au/u/Michael261434)\
**Post date:** [28 November 2023 14:31 UTC](https://forum.core-electronics.com.au/t/detect-speed-with-a-raspberry-pi-camera-and-opencv/11784/28 "2023-11-28T14:31:47Z")

</div>

Has anyone had any issues with vehicles running through the frame too fast for the program to capture? I’m using Raspberry Pi Camera Module 3 standard lens and RPI4.

---

<div class="post-metadata">

**Author:** ![Blayden](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/blayden/32/7535_2.png) [@Blayden](https://forum.core-electronics.com.au/u/Blayden)\
**Post date:** [30 November 2023 03:11 UTC](https://forum.core-electronics.com.au/t/detect-speed-with-a-raspberry-pi-camera-and-opencv/11784/29 "2023-11-30T03:11:43Z")

</div>

Hey Michael,

sounds like you are capturing quite a significant speed there! Its possible that you may have it set up a bit close to where the vehicles are moving past, try and back the camera up a bit to see if that helps capture the object a bit better.

Cheers,  
Blayden

---

<div class="post-metadata">

**Author:** ![Tomasz263501](https://avatars.discourse-cdn.com/v4/letter/t/b9e5f3/32.png) [@Tomasz263501](https://forum.core-electronics.com.au/u/Tomasz263501)\
**Post date:** [1 January 2024 21:38 UTC](https://forum.core-electronics.com.au/t/detect-speed-with-a-raspberry-pi-camera-and-opencv/11784/30 "2024-01-01T21:38:07Z")

</div>

Hello,  
i have tried and failed to get this to work. I have deployed Buster but it seems to upgrade to Bullseye. This lead me onto this page

> **[How to install OpenCV 4.5 & QT5 on Raspberry Pi & NVIDIA Jetson Nano...](https://www.engineersgarage.com/opencv4-5-installation-raspberry-pi-raspbian-bullseye/)**
>
> How to install OpenCV 4 on Raspberry Pi 32-bit Raspbian Bullseye for computer vision projects.

this took a very long time, installs and i can import cv2 in python but i dont know how to access the webpage, not sure there is one.  
I am not proficient in Linux but i need to get this working.  
I have the same camera as in the video with the same lens and it is on a Pi4b.

Please help.

---

<div class="post-metadata">

**Author:** ![Michael](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/michael/32/3545_2.png) [@Michael](https://forum.core-electronics.com.au/u/Michael)\
**Post date:** [2 January 2024 01:06 UTC](https://forum.core-electronics.com.au/t/detect-speed-with-a-raspberry-pi-camera-and-opencv/11784/31 "2024-01-02T01:06:47Z")

</div>

just to confirm @Tomasz263501 - have you followed our guide specifically for installing an old version of RPi OS?

> [@How to Flash the Old 'Buster' Raspberry Pi OS to a Micro-SD](https://forum.core-electronics.com.au/t/how-to-flash-the-old-buster-raspberry-pi-os-to-a-micro-sd/15076):
>
> Tim just shared a new tutorial: ["How to Flash the Old ‘Buster’ Raspberry Pi OS to a Micro-SD "](http://core-electronics.com.au/tutorials/flash-buster-os-pi.html) [image] This will be a quick article showing the process to flash the legacy Raspberry Pi OS ‘Buster’ Debian 10 (or any previous OS iteration)&nbsp;to a Micro-SD card. With any exciting new Operating System (OS) release, there are always small&nbsp;teething … [Read more](http://core-electronics.com.au/tutorials/flash-buster-os-pi.html)

Are you sure that you aren’t inadvertently running an `full-upgrade` at any point?

---

<div class="post-metadata">

**Author:** ![Tomasz263501](https://avatars.discourse-cdn.com/v4/letter/t/b9e5f3/32.png) [@Tomasz263501](https://forum.core-electronics.com.au/u/Tomasz263501)\
**Post date:** [2 January 2024 09:59 UTC](https://forum.core-electronics.com.au/t/detect-speed-with-a-raspberry-pi-camera-and-opencv/11784/32 "2024-01-02T09:59:43Z")

</div>

i have realised my error, i have run your install steps but only get a ‘default’ webpage using the install procedure i posted for OpenCV and the speed camera you have done.

```python
   webserver.py
           written by Claude Pageau

This is a stand alone web server.

Please Note
You will need at least one entry in a folder
before the web server will display content.
IMPORTANT: Use browser refresh to update files list
then select a list hyperlink.
Default config.py webserver settings are

    WEB_PAGE_REFRESH_ON = True
    WEB_PAGE_REFRESH_SEC = "900"
    WEB_PAGE_BLANK_ON = False

If a folder is selected on the right pane listing
the folder contents will appear in existing browser tab.
Select the <BACK link on Right panel listing to
navigate back to previous folder. <BACK will not
be displayed when in web server root folder.
Use browser refresh button to update web page and
display most recent data.

This web server can display other types of content.
Web pages with javascript, css Etc will run.
If a folder has an index.html it will take over
the browser tab.
This browser can only access local raspberry pi
files. It cannot access internet web pages.

see pi-timolo github wiki for more details

https://github.com/pageauc/speed-camera/wiki

```

---

<div class="post-metadata">

**Author:** ![Tomasz263501](https://avatars.discourse-cdn.com/v4/letter/t/b9e5f3/32.png) [@Tomasz263501](https://forum.core-electronics.com.au/u/Tomasz263501)\
**Post date:** [2 January 2024 10:40 UTC](https://forum.core-electronics.com.au/t/detect-speed-with-a-raspberry-pi-camera-and-opencv/11784/33 "2024-01-02T10:40:33Z")

</div>

hello,  
thank for the instructions, i have flashed the sd card with buster and run the install procedure how ever i still get the webpage with the text message as shown (webserver.txt)

---

<div class="post-metadata">

**Author:** ![Michael](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/michael/32/3545_2.png) [@Michael](https://forum.core-electronics.com.au/u/Michael)\
**Post date:** [3 January 2024 05:50 UTC](https://forum.core-electronics.com.au/t/detect-speed-with-a-raspberry-pi-camera-and-opencv/11784/34 "2024-01-03T05:50:01Z")

</div>

That’s progress @Tomasz263501!

It seems to me that there is no file being created to analyse. Have you started _both_ services? the webserver _and_ the `speed_camera.py` options detailed here at 4:27

[![](https://img.youtube.com/vi/n2WT3Qb0SIU/maxresdefault.jpg "Measure Speed With Raspberry Pi + OpenCV + Python") ](https://www.youtube.com/watch?v=n2WT3Qb0SIU&t=267)

We’re deep in the weeds and at a limit of our expertise here - perhaps it’s appropriate to raise a Github Issue on the [original repo](https://github.com/pageauc/speed-camera/issues) so the project creator can weigh in.

---

<div class="post-metadata">

**Author:** ![Tomasz263501](https://avatars.discourse-cdn.com/v4/letter/t/b9e5f3/32.png) [@Tomasz263501](https://forum.core-electronics.com.au/u/Tomasz263501)\
**Post date:** [3 January 2024 07:23 UTC](https://forum.core-electronics.com.au/t/detect-speed-with-a-raspberry-pi-camera-and-opencv/11784/35 "2024-01-03T07:23:58Z")

</div>

Yes.  
The Pi i have has arm17 architecture and from what i have read it doesn’t support libcamerra

---

<div class="post-metadata">

**Author:** ![Jack](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/jack/32/9287_2.png) [@Jack](https://forum.core-electronics.com.au/u/Jack)\
**Post date:** [4 January 2024 00:26 UTC](https://forum.core-electronics.com.au/t/detect-speed-with-a-raspberry-pi-camera-and-opencv/11784/36 "2024-01-04T00:26:25Z")

</div>

Which Pi are you using out of interest?

---

<div class="post-metadata">

**Author:** ![Tomasz263501](https://avatars.discourse-cdn.com/v4/letter/t/b9e5f3/32.png) [@Tomasz263501](https://forum.core-electronics.com.au/u/Tomasz263501)\
**Post date:** [4 January 2024 07:27 UTC](https://forum.core-electronics.com.au/t/detect-speed-with-a-raspberry-pi-camera-and-opencv/11784/37 "2024-01-04T07:27:17Z")

</div>

Hello,  
I know what the problem is, I was gifted a pi but I investigated the amount of RAM it has and it only has 2GB. This is the problem, thank you for your time on this and when my 4GB version turns up I will test again.

Ton

---

<div class="post-metadata">

**Author:** ![Michael](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/michael/32/3545_2.png) [@Michael](https://forum.core-electronics.com.au/u/Michael)\
**Post date:** [9 January 2024 01:44 UTC](https://forum.core-electronics.com.au/t/detect-speed-with-a-raspberry-pi-camera-and-opencv/11784/38 "2024-01-09T01:44:27Z")

</div>

great troubleshooting there - that’s one to add as a sanity check for other users.

If anybody else would like to query their ram capacity, you can use the `free` and/or `top` commands

---

<div class="post-metadata">

**Author:** ![Paul268707](https://avatars.discourse-cdn.com/v4/letter/p/c68b51/32.png) [@Paul268707](https://forum.core-electronics.com.au/u/Paul268707)\
**Post date:** [1 April 2024 15:44 UTC](https://forum.core-electronics.com.au/t/detect-speed-with-a-raspberry-pi-camera-and-opencv/11784/39 "2024-04-01T15:44:23Z")

</div>

Great guide and software. I’m after little help with my install.  
It’s working well in general and detecting speeds with reasonable accuracy.  
My issue is that the system seems to miss cars on occasion and its detection seems to top out at about 55mph. We’re on a 40mpg road and looking to use this to gather evidence to support some changes to the road safety profile. I’m aware we can see cars doing anything up to 105mph from the last official monitoring.

I’m guessing the system is not generating enough data points to detect or the frame rate is too low.

I using a Pi4 2Gb with a PiNoir2 camera.

The config only detects when the Auto\_motion\_crop is on and with an Event\_Count of 3 or 4.  
I’ve pushed the legacy frame rate to 60 but no idea if this is even in effect.

Any sugestions to up detection and increase the upper detection speed threshold?

TIA

---

<div class="post-metadata">

**Author:** ![Liam](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/liam/32/3562_2.png) [@Liam](https://forum.core-electronics.com.au/u/Liam)\
**Post date:** [3 April 2024 04:37 UTC](https://forum.core-electronics.com.au/t/detect-speed-with-a-raspberry-pi-camera-and-opencv/11784/40 "2024-04-03T04:37:51Z")

</div>

Hi Paul,

Welcome to the forum!!

> [@Paul268707](#):
>
> My issue is that the system seems to miss cars on occasion and its detection seems to top out at about 55mph.

Is it possible that the colour of the cars are blending into the background of your video feed?

I’d check out this issue on increasing the speed cap: [Vehicles at higher speeds being missed. · Issue #164 · pageauc/speed-camera · GitHub](https://github.com/pageauc/speed-camera/issues/164)

Let us know how you go!  
Liam

[Previous page](https://forum.core-electronics.com.au/t/detect-speed-with-a-raspberry-pi-camera-and-opencv/11784.md?page=1)

[Next page](https://forum.core-electronics.com.au/t/detect-speed-with-a-raspberry-pi-camera-and-opencv/11784.md?page=3)
