RoadTest: Raspberry Pi 3 Camera Bundle
Author: alin180493
Creation date:
Evaluation Type: Independent Products
Did you receive all parts the manufacturer stated would be included in the package?: True
What other parts do you consider comparable to this product?: null
What were the biggest problems encountered?: null
Detailed Review:
INTRODUCTION
Raspberry Pi 3B is a system on a chip (SoC) with a small form factor and powerful performance at low cost. This is the most popular credit card size computer due to the low price (around 35 pounds) and the 40 pin GPIO header that can be used to control external electronics. Another strong point is the huge community that was created around it and the amount of information available for new beginners. This incredible piece of hardware was accompanied by a camera module that can take 8 MP photos and full HD video at 30 fps.
This RoadTest will be structured as follows: Unboxing followed by a quick start guide. Then, three very good benchmark references that will give you a better understanding of how powerful this device is. After that the power consumption of the device measured and logged in different states and at different CPU loads using a stress test. Then 3 short experiments are made for different functionalities of the bundle to emphase how versatile it is. Firstly, it was tested using Octoprint, an OS specially developed for 3D printers that permits real-time visualization of the print and control interface. Secondly, simple commands that are used to take a picture, video or time-lapse followed by a short project of having an IR sensor that triggers the camera to start recording a video. The third and final experiment is an introduction of image recognition using Raspberry Pi. Finally, a short conclusion of the bundle.
UNBOXING and SPECIFICATIONS
The unboxing experience was quite ordinary, nothing too special into this chapter, just two minimalist packages into two minimalist boxes that houses both the raspberry pi 3B and raspberry pi camera. After I took them out I immediately put them into protective cases (Pi case, camera case) to keep them safe from my clumsy hands. Plus I added a 6mm small heatsink, I am sure it will make a “huge” difference in cooling the Pi.
Raspberry Pi 3 Model B
| Camera Module v2
|
GETTING STARTED
There are countless tutorials on how to get started using raspberry pi and how you can create an SD card with the operating system, so I will not waste any more storage space of the forum’s server with another tutorial and I will just leave a link to all you need to know and do to make it run. The only words of wisdom that I can give regarding the getting started with R Pi is to use a good quality SD card, at least a class 10 / UHS-I. This can influence a lot the performance if R Pi is used as a mini PC because the writing and reading speed can become a bottle neck in the fluidity of operation of the OS, plus if R Pi is used with the camera and it is used to record full HD 30 fps (see this link for more information about the bitrates and h264 encoding – the one that R Pi camera is using to encode videos). I am using this micro SD card at the moment just because I had it at hand and it is pretty decent, but I would recommend this one.
BENCHMARK – Reference articles
Initially I wanted to do a quick benchmark test between the raspberry PIs I got. B+, Zero and now 3B, but after I have search on the internet for some benchmarking software, I have found much better articles and more complete then what I had in mind. The first one represent a benchmark score comparison between all the Pis except Zero W, which was not released at the time of the article. The second one is a comparison between R Pi2 and R Pi3, I find this article useful because it represents a good comparison between the last model and its predecessor and shows how the technology evolved from one generation to another. The last, but not least is an article that is posted on this forum which is “A Comprehensive Raspberry Pi 3 Benchmark”. After I have read that articles, I realised that my initial though would produce results are not that relevant since it is a generation gap between RPi3 and RPi B+ and vs a R Pi Zero it is irrelevant since there are in different leagues of performance and prices.
POWER CONSUMPTION
For curiosity sake, I tested the power consumption and current drawn of the Raspberry pi 3 under different load conditions with and without the camera attached. The purpose of this was to check if the recommended 5 V, 2.5 A power supply is necessary, or the raspberry pi can work fine with a lower amperage one in case you do not have the recommended rated at hand. For example, I have a 5 V, 2 A power supply from my old Pi and if it is used only with the camera and no other peripherals or hardware attached to it (LEDs, Sensors, Hats etc.) I think it will be enough. The recommended supply 2.5 A it is used just to ensure that all the external hardware has enough juice to work, but the actual Pi is not consuming more then 5 W of power in full load.
The current drawn from the power supply during the stress test did not exceed 1 A, meaning that the 2 A power supply that I am using is good enough if I am going to use the RPi just with video out using HDMI and camera. For more demanding peripherals like an LCD screen, LEDs, Motors etc. the power supply needs an upgrade.
Each test setup was measured 3 times and the results were then average to obtain a more realistic graphic and mitigate some of the measurement errors. Also, just because I had a digital thermometer at hand I was recording also the temperature, obtaining the following:
EXPERIMENT A – Octoprint
The first practical application that I have done with this bundle was to use install Octoprint on it. Octoprint is an operating system that is dedicated to being used with a 3d printer. It permits to control and monitor it using a web interface from anywhere in the world. It is very simple to install (just like installing Raspian), the only extra step that needs to be done is to modify the “octopi-network.txt” by adding your network SSID and password, save it and that is about it.
To access the web interface the only thing to do is to type in the http://octopi.local/ or http://192.168.250.1/ . To access remotely form anywhere in the world you just need to port forward the IP address into the router settings.
The printer needs to be connected to the RPi with an USB cable and by using serial communication between the two it gives the access to control the printer.
Octoprint is a powerful tool to have alongside with a 3d printer just because eliminates all the cable prob
lem between the computer and printer (for example I have my printer about 10 meters away from my computer) or all the fuss with taking the SD card out put it in the computer back into the printer and back and forth.
Another major advantage of Octoprint is that it is using the RPi Camera it can display a real-time footage of the print and it can create time lapses of the print. This is perfect especially if you have the printer in another room or you are not at home.
From time to time you can simply check if everything is ok with the printer and you can avoid the mess that a failed print can produce, not to speak about the filament wasted.
For the purpose of testing Octoprint I simply create a back cover for the Pimoroni Camera Mount so the other side of the PCB is also protected (the STL file is attached below in case you have this camera mount and just want to have a protective back as well).
I was very pleased of how Octoprint was working and I am thinking to purchase another camera to attached to my old raspberry pi and set up as a permanent upgrade to the printer. Maybe it would be a good idea to use a NoIR type of camera instead just in case the printer is not always illuminated properly and the only thing that matters is to see that the print is ok without to worried about the colors that are a little disordered due to the lack of IR filter.
EXPERIMENT B – Raspian Basic Camera commands
After my test with the Octoprint I decided to test the bundle by using Raspian and simple commands to take a picture, a video or a time-lapse. The commands that I have used and many others can be found here, you can adjust all kinds of parameters like exposure, resolution, colours, add effects and many more.
Take a picture
raspistill -vf -hf -o test.jpg
Make a 10 seconds clip
raspivid -vf -hf -o test.h264 -t 10000
Make a time-lapse that takes a picture every 30 seconds for 90 minutes
raspistill -vf -hf -t 5400000 -tl 30000 -o image%03d.jpg
Commands explained
-vf - vertical flip
-hf - horizontal flip
-t 5400000 - time in miliseconds of how long it should start recording (1.5 hours)
-tl 30000 - time in milisecons of how often it should take a photo (30 seconds)
-o imag%03.jpg - output file name (imag001, imag002, imag003 etc.)
Combine the pictures taken into a time-lapse
sudo apt-get install libav-tools avconv -r 10 -i image%03d.jpg -r 10 -vcodec libx264 -vf scale=1280:720 timelapse.mp4
-r 10 Assume ten frames per second in input and output files.
-i image%03.jpg The input file specification (to match the files produced during the capture).
-vcodec libx264 Use the software x264 encoder.
-vf scale=1280:720 Scale to 720p. You can also use 1920:1080, or lower resolutions, depending on your requirements.
-timelapse.mp4 The name of the output file.
Another experiment that I wanted to make with the basic functions of the camera was to trigger the recoding of the camera if motion was detected using a PIR sensor (connected to pin 4). The code was created just with the idea that some day I could place the RPi + camera into a project box with a battery supply and place it in one of the trees (you can see them in the time-lapes) near my house and observe the animals (usually here are some squirrels and foxes around here) or to use it as a surveillance camera.
CODE:
from gpiozero import MotionSensor
from picamera import PiCamera
from datetime import datetime
camera = PiCamera()
pir = MotionSensor(4)
while True:
pir.wait_for_motion()
filename = datetime.now().strftime("%Y-%m-%d_%H.%M.%S.h264")
camera.start_recording(filename)
pir.wait_for_no_motion()
camera.stop_recording()
EXPERIMENT C – Image Recognition
The final test or experiment, however you want to call it, was to install Open CV which is an Open Source Computer Vision Library. My intention is to start learning about computer vision and artificial intelligence. Therefore, my initial thought was to pair the RPi camera with the Google AIY Voice Kit to create a complete virtual assistant with both sound and vision feedback. Unfortunately, the AIY Kit did not arrived yet because it is a pre-order. Due to the circumstances I decided that for this road test to create a basic face detection application using OpenCV 3.3.0.
The first thing to do is to install Open CV on the Raspberry Pi, I was surprised that the process of doing so took about 6 hours, but by using the following tutorials (1st this one took about 20 minutes and 2nd one took 5+ hours) I was able to make it work. There are 2 because on the internet there are multiple ways of installing OpenCV apparently, so I decided to go with 2 of them to be sure that at the end of the day I will have a library that is compatible with Python and it works as it should.
From my basic understating obtained during this roadtest of computer vision, I managed put together a code that takes a picture each time you run it and show a square around a face if it detects one. I have used this link which I found incredible useful.
The basic principle of computer vision and please correct me if I am wrong is that you need to “train” your code with a database of whatever you want to detect, so for example if you want faces like in my case, you need to include into your code a database of faces so he can compare what he sees with what he know it is a face and decide that yes there is a face in the photo.
The database consists of file that the program needs to be pointed to, the extension is .XML and it is called a “cascade”. The database that I have used is called harr cascades. There are multiple types of cascades for different parts of the body, but for simplicity and my limit knowledge about this subject, I decided to stick with the simplest and obvious one of just detecting a face. The database is not an actual photo album, but multiple pictures that were converted into numpy arrays.
The idea of the presented code is that it takes a picture, converts into a numpy array and compares it with all the numpy arrays that are found into the cascade file and if they array created is in a range of values that are found into the database then the program decides it is a face present in the photo and creates a square (colour is selected by defining the 3 RGB values) around the values that matches best the database.
Note: If you want to recreate the experiment, make sure that the path to the cascade and the file location are identical (line 22).
CODE:
import io
import picamera
import cv2
import numpy
#Create a memory stream so photos doesn't need to be saved in a file
stream = io.BytesIO()
#Get the picture (low resolution, so it should be quite fast)
with picamera.PiCamera() as camera:
camera.resolution = (1920, 1080)
camera.capture(stream, format='jpeg')
#Convert the picture into a numpy array
buff = numpy.fromstring(stream.getvalue(), dtype=numpy.uint8)
#Now creates an OpenCV image
image = cv2.imdecode(buff, 1)
#Load a cascade file for detecting faces
face_cascade = cv2.CascadeClassifier('/home/pi/haarcascade_frontalface_default.xml')
#Convert to grayscale
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
#Look for faces in the image using the loaded cascade file
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
print "Found "+str(len(faces))+" face(s)"
for (x,y,w,h) in faces:
cv2.rectangle(image,(x,y),(x+w,y+h),(0,0,255),2)
#Save the result image
cv2.imwrite('result.jpg',image)
The results were produced by taking 3 pictures of faces from the Google Images, first with only 1 face and the other 2 with groups of people. The pictures were displayed using an Ipad that was positioned in front of the camera. It was observed that the lighting condition as well as reflections are a major factor in managing to properly recognize a face. Most of the time in which the lighting conditions were not appropriate, the camera was detecting faces where they were not supposed to appear, this may also be caused by the code itself because of the large interval in which the face is confirmed or not.
After some code and lighting tweaking, I manage to get proper results, but I consider that it is still to sensitive to the lighting changes. Hope in time, after some experience to manage to make it work better and not just detecting faces, but to also recognize them.
Here are some examples that I manage to create using the code presented.
In conclusion, computer vision and Open CV are some things that require lots of hours to spend and learn the basics to realise a finished project. This project that I am thinking to do is way beyond the scope of this road test so just the surface and a basic implementation was realised during this road test just to verify that the Open CV is installed properly, and a basic example is made.
In conclusion I found this road test very enjoyable and I have found many applications in which this bundle can be used. I have learned to cherish RPi even more by find all those new ideas that can be used for. If you ask me I would by two more cameras, one for octoprint and one for my “wild life” motion detection experiment. The one that I already have I will continue to use it to develop my understandings and skills towards computer vision and AI.
Thank you again for the opportunity that you have given me to test this incredible hardware, it was truly enjoying to test it during my free time and especially when there were rainy days (UK guys, know what I am talking about...bleah…).
NOTE: The codes have a display problem on the road test page so please find them attached below in an archive, also the Fusion 360 file and STL file is attached for the camera back plate.
Top Comments
I just purchased a Pi zero W kit with a V2 camera and the focus is adjustable, the kit even came with an adjusting ring.
If your lens is not glued in place, you can purchase this tool at adafruit, or make…
Yeah I am aware of the focus adjustment. This is why I 3d printed this tool.
.
Some great real world examples. I hope to attach a camera to a Pi for 3D Print monitoring.