Code for processing Beebox development ata
Data files
Jun 17, 2025 version files 15.96 KB
-
basler_camera_v2.py
5.31 KB
-
README.md
4.20 KB
-
video_analysis.py
6.46 KB
Abstract
Pollinators, particularly bumblebees, play a vital role in global food production, yet their populations face severe declines due to environmental disturbances and habitat loss. While conservation efforts have focused on food provision, the critical need for suitable nesting habitats has been largely overlooked. We present a novel artificial nestbox, the BeeBox, designed to support bumblebee nesting and enhance research, conservation, and public engagement. Developed using additive manufacturing (AM) principles, the BeeBox underwent iterative design improvements to optimize thermal insulation, humidity control, and durability. Field tests demonstrated that our design significantly improved internal environmental stability, colony health and longevity.
The modular design facilitates in-nest behavioural studies using high-resolution video recording, providing a robust tool for understanding the impacts of environmental stressors. Additionally, the BeeBox offers scalable, cost-effective conservation applications, with the potential to supplement declining natural habitats. Observations indicate that post-occupancy cleaning by detritivores can mitigate pathogen accumulation, enhancing long-term nestbox utility.
BeeBox also serves as a platform for public engagement, with videos of bumblebee behaviour fostering awareness and emotional connections to pollinator conservation. Interactive initiatives, such as personalized nestbox distribution, further inspire community participation. By integrating scientific research, conservation strategies, and public outreach, the BeeBox represents a comprehensive approach to addressing bumblebee population declines and promoting biodiversity
https://doi.org/10.5061/dryad.j6q573nqh
Description of the data and file structure
Python scripts for capture of video/audio data from BeeBox device. STL files for research use are available directly from the authors only by contacting them at: beebox@lancaster.ac.uk.
Files and variables
File: video_analysis.py
Description: script for digital processing of movement data.
This Python script analyzes .mp4
video files to quantify movement activity within a specified Region of Interest (ROI). It segments videos into 10-minute blocks, computes pixel-level differences between consecutive frames in the ROI, and saves statistical summaries to a CSV file.
Features
- Extracts timestamps from filenames (format:
capture_YYYYMMDD_HHMMSS.mp4
) - Processes videos in 10-minute (36,000 frame) segments
- Computes movement metrics:
- Average movement (pixel sum differences)
- Standard deviation
- Standard error
- Variance
- Region of Interest (ROI) configurable
- Parallel processing using multithreading
- Saves output incrementally to CSV
Requirements
- Python 3.7+
opencv-python
numpy
pandas
tqdm
Configuration
- VIDEO_DIRECTORY: Set the path to your video files.
- ROI: Modify the
ROI
tuple(x1, x2, y1, y2)
to focus on a specific area in the video frames. - OUTPUT_CSV: Set the path for saving the results.
Output
The output CSV includes:
date_time
: Timestamp from filenamestart_time
,end_time
: Segment boundarieshour
,minute
: Start time breakdownaverage_movement
,std_deviation
,std_error
,variance
: Movement metrics per segment
File: ximea_camerarecording.py
Description: This script captures synchronized audio and video using a USB microphone and USB camera, recording them in hour-long blocks. It encodes video using NVENC H.264 (GPU-accelerated) and stores audio as WAV files. After each hour, the files are automatically moved to designated output folders.
Features
- Records 2048x2048 resolution video at 45 FPS using OpenCV and
ffmpeg
- Records 16-bit mono audio at 44.1 kHz using PyAudio
- Uses separate threads to record audio and video in parallel
- Automatically rolls files every hour
- Prevents overwriting by renaming duplicates
- Optimized for NVIDIA NVENC GPU video encoding via
ffmpeg
Requirements
- Python 3.8+
- NVIDIA GPU with NVENC support
- Required Python packages:
opencv-python
pyaudio
wave
(standard lib)subprocess
(standard lib)shutil
,threading
,os
,time
(standard lib)
Output Structure
Each hour, two files are created:
video_YYYY-MM-DD_HH-MM-SS.mp4
(invideo_final_dir
)audio_YYYY-MM-DD_HH-MM-SS.wav
(inaudio_output_dir
)
Duplicates are renamed with a suffix like _1
, _2
, etc.
File: basler_camera_v2.py
Description: This Python script records hour-long video and audio segments using:
- A Basler ACE Classic ACA2040‑90UM NIR industrial camera
- An AudioMoth USB microphone
It handles device initialization, safe streaming, GPU-accelerated encoding via ffmpeg
, and automatic file organization. Ideal for research applications requiring high-resolution, time-synchronized audio and video recording.
Features
- Uses the Pylon SDK to safely access Basler camera
- Detects AudioMoth USB microphone automatically
- Records 2048×2048 grayscale video at 60 FPS
- Records mono 44.1 kHz audio
- Streams raw frames to
ffmpeg
for real-time NVENC H.264 encoding - Handles file naming, renaming, and moving after each session
- Loop runs indefinitely with hourly recording blocks
Requirements
- Python 3.8+
- Basler Pylon SDK installed and working
- NVIDIA GPU with NVENC support
- System
ffmpeg
installation (accessible from terminal)
Output Files
Each recording block produces:
video_YYYY-MM-DD_HH-MM-SS.mp4
invideo_final_dir
audio_YYYY-MM-DD_HH-MM-SS.wav
inaudio_output_dir
Duplicates are renamed with a _1
, _2
, etc. suffix.