Can We Be Practical About Faith?

Spiritual and religious teachings often speak in great length about “faith.” In times of challenges, people like to say “have faith.” And because we humans are fascinating beings, whenever something…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




How I Created a System to Measure Parking Traffic

CODEX

The system is a Raspberry Pi that runs an object classification TensorFlow model and stores detection data in a CSV for further analysis. Read more of the project concept and statistical analysis in the other article on my profile (which I will post here later when it is complete). This article is designed as a setup guide for anyone looking to replicate the system.

To build the project, you will need the following materials. I will link to where I purchased them from, so if they’re no longer available, run a Google search to check elsewhere:

In total, you’re looking at around $185 for the system. This is considerably less expensive than the $450+ pneumatic tube systems.

Once you have everything delivered, you’ll need to install Raspbian OS onto the microSD card and do some configuration on the Pi.

Once installed, open Raspberry Pi Imager. Select OS as Raspbian Pi OS (32-bit), and choose the microSD card you just inserted into your computer.

Select Raspberry Pi OS (32-bit), then select the SD card you’ll put in your Pi.

Once you’ve done so, start the install. It should take a few minutes, depending on the transfer speed of your microSD card. Once your install is finished, you need to configure a few things to make it boot up and be visible by your machine.

Now that you’ve installed Raspbian, with the SD card still in your computer, navigate to the boot directory on the SD card, and open the file called config.txt.

At the end of the file, you’re going to want to add the following:

The end result should look like the image below. Make sure you save and exit when done.

With the SD card still in your computer, create a file in the root directory of the card by making an empty file called ssh there. However you choose to do that is by your means. Personally, I just navigated to the directory and used a command.

Resulting files after executing the above commands. As you can see, “ssh” was successfully created in the root directory of the SD card.

Edit the file called cmdline.txt. Find rootwait, and add the following, with a space before and after it:

The resulting file should look something like this once you’ve done that:

Be sure to save and exit when done.

Everything is set up now so you can access your Pi. Eject your SD card, and insert it into the microSD slot on your Pi.

Ubuntu, however, doesn’t need additional drivers to work. Plug in the adapter and reboot. Then, connect the Pi to the adapter using the ethernet cable. Find the wired network settings in Ubuntu, and under IPv4 and IPv6, change the method to “Link-Local Only”. You need to do this since your Pi is not an access point and is not providing internet to your computer. You’ll have a hard time using ssh if you do not complete this step.

For other OSes, there may be additional setup required. J5Create should give you the full setup instructions on installation, otherwise see Google on using a USB-ethernet adapter.

To test to see if your Pi is working, you can simply ping it by using the following command (in Mac/Linux, Windows might be different):

If all runs well, which it should, you should get a result that looks something like this:

My terminal returns successful pings, and I hit control+C to stop the operation. The connection to my RPi is successful.

Additionally, you should see both the downlink and uplink LEDs lit on the Pi’s ethernet port and the adapter.

If you end up getting and error that says ping: cannot resolve raspberrypi.local: Unknown host, wait a few moments and try again. The Pi probably didn’t boot up all the way. If you still have issues, use the name raspberrypi. If you are still having issues connecting to your Pi after that, you may want to restart the process over again from installing Raspbian, or just Google your issues.

If you don’t have a monitor and keyboard available for your Pi, there is an easy fix. Before you can access Raspbian, you need to ssh into the Pi by using the following command:

Accept any prompts that come up, and use the default password to login, which is raspberry. You should change this later.

Now that you’re logged in via ssh, for what’s next, you need to enable the VNC server which allows you to see and access your Pi’s desktop. To do so, use the following command to access the configuration:

Then, scroll to interface options using the up/down keys, and hit enter to select. Once you’re in the interface options, scroll to VNC and select <Yes>.

Additionally, you’ll need to go to localisation options and set your locale and timezone, as well as entering the SSID and password of your wi-fi network (so your Pi can connect to the outside world to download dependencies later on).

Select <Ok> in the next dialogue, and use the left and right arrow keys to select <Finish>. Your Pi will reboot.

Great, now you’re set up to access your Pi desktop remotely.

With that installed and set up, you can double click on the connection you just made in VNC Viewer. Hit “Continue” on any prompts that come up, then login using the same credentials as with ssh:

When you login, you’ll need to complete the configuration. It should walk you through everything you need to do step-by-step. When you’re done, your Pi is ready to be used remotely! VNC will prove to be useful especially if you need to troubleshoot the model.

Then, once you’ve installed Docker, you need to add the current user to the Docker user group (so the user can run the container without needing sudo permissions).

If this command executes successfully, it will not output anything. It may yield an error that requires you to create a user group (as the user group does not exist in the first place), which should be solved by using this command, then retrying adding pi to the user group after:

Next, you need to install the application and its dependencies through Docker. So if your docker install isn’t yet working, fix that!

The script should install everything, build the container, and run the container automatically. Go and get some food, as this will take a while — maybe around 20 minutes.

Once that’s done, test out UMT with the container running to see if it works.

It is also possible that the annotations on the sample video are simply not accurate — again, that is expected behavior. Try running the following, and point your RPi camera around with your surroundings, and hit control + C after a few moments to stop the live analysis:

You should see frames counting, similar to the last analysis. Where there is not a message displaying “no detections…”, the model is detecting objects and all is working. To check your results, you may review the photos in the output directory, or use the frame stitching tool I included in my repo. To use that, run the commands below to download:

And execute as you normally would a shell script:

This takes all the frames and stitches them together in an MP4 video titled “analyzed-frames.mp4”. The video will be quite sped up, and this can be changed by using nano and editing the “setpts” parameter in stitch.sh. If you’re not familiar with how to use nano, here’s a quick instruction for our purposes:

Then use the left and right arrows to scroll to the “setpts” parameter and change as desired. The parameter is a proportion of how long each frame is in length in the video, so smaller numbers means faster video speed. For real-time speed, try PTS*3 or PTS*4. When you’re done, simply CTRL+S to save and CTRL+X to exit nano.

Project box assembly can be very subjective, since it depends on the magnets you get, project enclosure, and the weight of your system overall. I will be keeping this more general for that reason.

To hold the project box, you need about 3–4 magnets to successfully hold the weight of the project. If you’re using a different project box, 3 may be a good starting point, but increase if you notice your box is sliding when you mount it to a magnetic and vertical surface. In my case, I only needed 3.

You’re going to need a drill for this, as you need to puncture the plastic of the project box to insert a screw (you’ll need screws that fit snugly through your magnets) into it. With Adafruit’s project box, there are already good spots to drill into. It may be different for your case, but either way, nuts come in handy to hold the screws in place from the other side. Just be sure to make the screw placement near the edges of the box, as you may end up having a difficult time fitting the other components in later.

Here’s what mine looked like:

The backside of the project box, with neodymium magnets held into place with screws, and screws are held into place with nuts on the other side.

Depending on the environment you set up your system in, you may want to make your system more discrete for the purposes of preventing any kind of tampering or theft. This is especially true with Adafruit’s project box, as the lid is clear so you can see everything.

What the system looks like camouflaged using Plasti-Dip. Yes, the lights of the system are dim but still visible, especially at night. This is especially useful when testing, as you can monitor the battery level throughout the day without needing to undo the enclosure.

The next step would be to add all the components (battery and Pi w/ camera) to the enclosure. I would highly recommend using 5–10lb velcro strips to hold the battery onto the enclosure, along with command strips to hold the Pi in place on the battery. Of course, it is completely optional to do this and you may go about it however you’d like. Keep in mind that the Pi heats up quite a bit, so the adhesive or mounting device has to be able to hold through that.

Personally, I was on a tight budget and ended up leaving everything loose, as the battery fit almost perfect when it had a wire connected, and the Pi wouldn’t go anywhere. I duct-taped the camera to the lid to hold it in place. See below for what mine looked like:

I didn’t end up needing velcro for this battery. Because of the USB cable attached to the battery, the battery fit tightly into the case and was made with an elastic-like finish that held it into place. If you’re going to do it this way, for the sake of the poor wire, make sure that the wire is bent in the same direction each time you insert the battery and doesn’t have too much tension in it when doing so. I’m sure engineers are understandably laughing at this, but it’s as functional as it needs to be for my purposes.

Now that the assembly is done and UMT is up and running, the system can finally see the light of day. You’ll need to take a laptop, ethernet adapter (if applicable), ethernet cable, and of course, the system with you to wherever you plan on testing it.

Connect to the Pi by opening VNC and connecting to the host that we set up earlier. With the Pi’s desktop open in VNC Viewer, start a terminal within the remote desktop.

With the case open and UMT-Pi connected to your laptop, start the container. You can run the init.sh shell file downloaded by install.sh to automatically start everything, provided you already installed UMT. If you haven’t yet installed UMT, your Pi will need to be connected to the internet to do so. With the Docker container started, run the following to start UMT and enable background processing:

Once you’ve started the model, wait a few moments, and then disconnect the ethernet cable from the Pi, close the enclosure, and mount it. Your system should be recording (and will also record you opening and closing the enclosure — for accurate analysis, you should exclude the first and last couple hundred frames or so. This depends on how long it takes you to setup/shutdown).

Feel free to pack your stuff up and leave for a while, but note that the -save flag used earlier is only useful with less than 2 hours of testing. Docker will kill the process after almost 2GB of images is reached since the saved images are temporarily stored in memory (this is the nature of how Docker containers work). When you’re ready to stop it, unmount it, open the enclosure, insert the ethernet cable, reconnect to the Pi in VNC, and finally hit Ctrl+Z in the terminal window (which should still be open) to stop the process. It may take a few moments for the console to respond. But once it’s done, you can run stitch.sh or manually look at the frames, provided you ran UMT with -save. Furthermore, all data will be included in the outputted CSV.

You should also test at night. I noticed the model struggles with detection in dimly lit areas and/or when automobile high-beams are present. Then again, angles can directly affect auto-exposure, which will affect the object detection. Moreover, test during the rain or build an “umbrella” for the lens area. If raindrops cover the plastic that the lens sees out of, the model will most likely struggle with detection and/or classification. The model also detects stationary vehicles, so avoid angling directly at parking lots if measuring traffic, as that may affect the data analyses.

Now that you’ve built the system and tested it, the rest of the study is yours to conduct. Personally, I would be using the classification and x/y data included in the CSV for finding direction of traffic and if something was a car or not. Be sure to charge your battery however often, and account for any missing data. It may be easier to record data over consistent time intervals if this is the case.

Have a great day! Feel free to reach out to me with any questions you may have.

Add a comment

Related posts:

Kingswood Coffee

Many many problems with these coffee beans, shipped loose in plastic tubs to be scooped out and bagged, ideal for oxidising the beans, shipped in transparent plastic bags, sunlight will damage the…

How to use Binance for Basic Trades?

Binance trading fees are some of the lowest on the market. Binance doesn’t charge users for making deposits. This is because the exchange is cryptocurrency-only. It avoids the high fees that…

Enjoy the Surprise of Putting Thoughts Together

If you can get started with your simple outline and create what intent you want your information to achieve, you can see if the meaning and copy match up.