Skip to content
Snippets Groups Projects
Commit 162c133f authored by Isaac Espinosa's avatar Isaac Espinosa
Browse files

Merge branch 'dev_code' into 'main'

Adding FloraGuard initial workig version, no object detection yet.

See merge request !1
parents cdb8c4d7 835f432e
No related branches found
No related tags found
3 merge requests!6raspberry -> dev_Code merge,!2Adding FloraGuard Code,!1Adding FloraGuard initial workig version, no object detection yet.
#!/usr/bin/env python3
from flask import Flask, render_template, current_app as app, redirect, url_for
import os
from datetime import datetime
from picamera2 import Picamera2
camera = Picamera2()
app = Flask(__name__)
@app.route('/')
def index():
# Attempt to find the latest image in the directory
try:
latest_image = max([f for f in os.listdir('static/images') if f.endswith(".jpg")], key=lambda x: os.path.getctime(os.path.join('static/images', x)))
except ValueError:
latest_image = None # No images found
return render_template('index.html', image_file=latest_image)
@app.route('/capture')
def capture():
camera.start()
# Generate a filename with the current date and time
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
filename = f"{timestamp}.jpg"
file_path = os.path.join(app.root_path, 'static', 'images', filename)
camera.capture_file(file_path)
camera.stop()
return redirect(url_for('index'))
if __name__ == '__main__':
app.run(host='0.0.0.0', port=80)
av==12.3.0
blinker==1.8.2
click==8.1.7
Flask==3.0.3
itsdangerous==2.2.0
Jinja2==3.1.4
MarkupSafe==2.1.5
numpy==2.0.1
picamera2==0.3.18
pidng==4.0.9
piexif==1.1.3
pillow==10.4.0
python-prctl==1.8.1
simplejpeg==1.7.4
v4l2-python3==0.3.4
Werkzeug==3.0.3
body {
font-family: Arial, sans-serif;
margin: 40px;
text-align: center;
}
a {
background-color: #4CAF50;
color: white;
padding: 14px 20px;
text-decoration: none;
display: inline-block;
}
Code/static/images/20240727_104231.jpg

72.6 KiB

<!DOCTYPE html>
<html>
<head>
<title>Pi Camera App</title>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/style.css') }}">
</head>
<body>
<h1>FloraGuard</h1>
<a href="/capture">Capture Image</a>
{% if image_file %}
<div>
<h2>Most Recent Image:</h2>
<img src="{{ url_for('static', filename='images/' + image_file) }}" alt="Most recent captured image">
</div>
{% else %}
<p>No images captured yet.</p>
{% endif %}
</body>
</html>
# PiVision_tools
Projects/tools for computer vision using Raspberry Pi SBCs
## Description
Tools for Automatic Training Data Generation using a Raspberry Pi
## FloraGuard
# WiFi Router Setup Script for Raspberry Pi Zero 2 W
FloraGuard leverages Raspberry Pi and YOLO object detection models to monitor pollinizers like bees and hummingbirds visiting flowers. This initiative aims to enhance environmental research by automating data collection and analysis of pollinator activities, which are crucial for ecological assessments and conservation efforts. The project utilizes video data provided by Rossana Maguiña, processed through advanced machine learning techniques to accurately identify and track pollinator interactions in natural habitats.
## Description
## Usage
### WiFi Router Setup Script for Raspberry Pi Zero 2 W
#### Description
The script sets up the Raspberry Pi to function as a WiFi access point using `hostapd` and `dnsmasq` for managing connections and DHCP respectively. It configures `iptables` to handle network routing and masquerading, ensuring devices connected to the Pi can access the internet through its network interface.
## Requirements
#### Requirements
- Raspberry Pi Zero 2 W
- Raspberry Pi OS Lite 64-bit (2024-07-04 release)
- Internet connection to download necessary packages
- SSH or direct access to the terminal
## Usage
#### Usage
1. **Make the script executable**:
```bash
chmod +x setup_wifi_router.sh
......@@ -23,4 +27,30 @@ chmod +x setup_wifi_router.sh
```bash
sudo ./setup_wifi_router.sh "YourSSID" "YourStrongPassword"
```
3. **Reboot**
### Flask Camera App Service
#### Description
This Flask application provides a web interface for controlling a camera connected to a Raspberry Pi. It allows users to capture and view images directly through the web interface. The application is configured to start automatically at boot using a systemd service.
#### Flask Service Setup Script
##### Description
The provided script automates the setup of the Raspberry Pi to run the Flask application as a systemd service. This setup ensures that the Flask application starts on boot and remains running.
##### Requirements
- Raspberry Pi with Raspberry Pi OS installed.
- Flask application must be installed and configured correctly in the specified directory.
- User must have `sudo` privileges to configure systemd services.
##### Usage
1. **Make the script executable**:
```bash
chmod +x setup_flask_service.sh
```
2. **Run the script with sudo** and provide your desired service name and the path to your Flask application directory:
```bash
sudo ./setup_flask_service.sh "floraguard" "/home/flora/pivision_tools/Code"
```
3. **Reboot**
\ No newline at end of file
from picamera2 import Picamera2
picam2 = Picamera2()
picam2.start_and_capture_file("test.jpg")
\ No newline at end of file
#!/bin/bash
# Check if a service name was provided
if [ -z "$1" ]; then
echo "Usage: $0 <service-name> <path-to-app>"
exit 1
fi
SERVICE_NAME=$1
APP_PATH=$2
# Create the systemd service file
echo "Creating systemd service file for $SERVICE_NAME..."
cat <<EOF | sudo tee /etc/systemd/system/$SERVICE_NAME.service > /dev/null
[Unit]
Description=Flask Application
After=network.target
[Service]
User=root
WorkingDirectory=$APP_PATH
ExecStart=/usr/bin/python3 $APP_PATH/app.py
Restart=always
[Install]
WantedBy=multi-user.target
EOF
# Reload systemd to recognize the new service
echo "Reloading systemd..."
sudo systemctl daemon-reload
# Enable the service to start at boot
echo "Enabling $SERVICE_NAME service..."
sudo systemctl enable $SERVICE_NAME
# Start the service
echo "Starting $SERVICE_NAME service..."
sudo systemctl start $SERVICE_NAME
# Display the status of the service
echo "Displaying the status of $SERVICE_NAME..."
sudo systemctl status $SERVICE_NAME
from picamera2 import Picamera2
picam2 = Picamera2()
picam2.start_and_record_video("test.mp4", duration=5)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment