panorama-scan
In this post I introduce the panorama-scan code. Once you put a decent quality camera on the car, the camera servo is perfect for creating panoramic scans. There was a slight problem with this idea. You need to be logged in to the car to start and stop code. How can we set the car to scan when a long way from your home wifi network? I opted for a script that starts up at boot-up, and auto-runs the panorama-scan if it is not associated with a network, and does nothing if it is. The idea being if it is in wifi range of my network, I don't need the panorama-scan to start by itself. So with this setup, I take my car to some scenic spot, power it up, wait for it to scan. Power down, move to the next spot. And so on.
Here is our start-up script:
Next, I had the great idea, heh, of using date-time to label our saved images. Turns out this doesn't work! For technical reasons, the pi doesn't know the correct datetime unless connected to a network. After a rethink, I now label the destination directories with integers, which I increment with each scan. And it doesn't matter if the time recorded in the panorama-log.txt is not accurate.
Note that you need to edit this script if you want to change the locations of your start-up script, panorama-scan.py code, and your destination directories. I used:
Next, we need to ensure this script runs on start-up. So edit /etc/rc.local using:
There are a few things you can tweak in the panorama-scan.py code:
Next post we try to panorama-stitch some of our images.
Let's finish this post with a picture of the park near my house:
Here is our start-up script:
#!/bin/bash # wait a while, hopefully long enough for network to start: sleep 2m # check if we can reach google DNS: nc -zw 1 8.8.8.8 53 >/dev/null 2>&1 online=$? # NB: raspberry pi time is only updated when connected to a network! dt=$(date '+%d-%m-%Y--%H:%M:%S') echo $dt >> /home/pi/panorama/panorama-log.txt if [ $online -eq 1 ]; then # if network down, then auto run our panorama-scan: echo "network down" >> /home/pi/panorama/panorama-log.txt /usr/bin/python3 /home/pi/panorama/panorama-scan.py /home/pi/panorama/panorama-images # shut down: sudo shutdown -h now else echo "network up" >> /home/pi/panorama/panorama-log.txt fiNow some comments on this script. This script runs on boot-up, but we don't know if it runs before, or after the network is up. So I put in a sleep time of 2 minutes, hopefully by that time it is clear if the car is in the presence of your home wifi or not. Then after the 2 min wait, we need to check if we can reach the network. I chose google's DNS server (8.8.8.8), on the DNS port (53). You might prefer something else, perhaps your home router's IP and port 80?
Next, I had the great idea, heh, of using date-time to label our saved images. Turns out this doesn't work! For technical reasons, the pi doesn't know the correct datetime unless connected to a network. After a rethink, I now label the destination directories with integers, which I increment with each scan. And it doesn't matter if the time recorded in the panorama-log.txt is not accurate.
Note that you need to edit this script if you want to change the locations of your start-up script, panorama-scan.py code, and your destination directories. I used:
/home/pi/panorama/start-panorama-scan.sh /home/pi/panorama/panorama-scan.py /home/pi/panorama/panorama-imagesrespectively.
Next, we need to ensure this script runs on start-up. So edit /etc/rc.local using:
sudo nano /etc/rc.localThen add this line just before the final 'exit 0' line:
sudo /home/pi/panorama/start-panorama-scan.sh &If all is well, power-up your car out of range from your home wifi, and the scan should run. With current settings, you need to wait 2 minutes, then you will hear the first beep. Wait 30 seconds and you will hear the 5 second to go warning beep, and then the scan will start. Once finished the camera will return to the 90 degree angle, and beep once more. That's it.
There are a few things you can tweak in the panorama-scan.py code:
# beep to indicated start and end of panorama-scan: beep = True # camera resolution: camera_size = (1024, 768) # horizontal/vertical image flip: hflip = True vflip = True # number of images to average over: # count = 20 count = 1 # sleep time, in seconds, between changing angle and taking a photo: SLEEP_TIME = 1 # min similarity for image to be considered valid during image averaging: IMAGE_SIMILARITY = 0.75 # panorama settings: min_angle = 0 max_angle = 180 step_angle = 5And what type of image capture:
# image capture function: get_image = get_single_image # get_image = create_average_camera_image # get_image = create_simm_average_camera_imageI guess that is it. I should also mention, I tweaked the code so it now runs without needing opencv, and runs instead using pygame (which comes pre-installed on the raspberry pi). This is so you can run the panorama-scan.py code without needing to compile opencv.
Next post we try to panorama-stitch some of our images.
Let's finish this post with a picture of the park near my house:
Comments
Post a Comment