- Implemented main test script to verify system components and functionality. - Added individual test scripts for camera exposure settings, API changes, camera recovery, maximum FPS, MQTT events, logging, and timezone functionality. - Created service file for system management and automatic startup. - Included detailed logging and error handling in test scripts for better diagnostics. - Ensured compatibility with existing camera SDK and API endpoints.
5.4 KiB
5.4 KiB
Camera Video Recorder
A Python script for recording videos from GigE cameras using the provided SDK with custom exposure and gain settings.
Features
- List all available cameras - Automatically detects and displays all connected cameras
- Custom camera settings - Set exposure time to 1ms and gain to 3.5x (or custom values)
- Video recording - Record videos in AVI format with timestamp filenames
- Live preview - Test camera functionality with live preview mode
- Interactive menu - User-friendly menu system for all operations
- Automatic cleanup - Proper resource management and cleanup
Requirements
- Python 3.x
- OpenCV (
cv2) - NumPy
- Camera SDK (mvsdk) - included in
python demodirectory - GigE camera connected to the system
Installation
- Ensure your GigE camera is connected and properly configured
- Make sure the
python demodirectory withmvsdk.pyis present - Install required Python packages:
pip install opencv-python numpy
Usage
Basic Usage
Run the script:
python camera_video_recorder.py
The script will:
- Display a welcome message and feature overview
- List all available cameras
- Let you select a camera (if multiple are available)
- Allow you to set custom exposure and gain values
- Present an interactive menu with options
Menu Options
- Start Recording - Begin video recording with timestamp filename
- List Camera Info - Display detailed camera information
- Test Camera (Live Preview) - View live camera feed without recording
- Exit - Clean up and exit the program
Default Settings
- Exposure Time: 1.0ms (1000 microseconds)
- Gain: 3.5x
- Video Format: AVI with XVID codec
- Frame Rate: 30 FPS
- Output Directory:
videos/(created automatically)
Recording Controls
- Start Recording: Select option 1 from the menu
- Stop Recording: Press 'q' in the preview window
- Video Files: Saved as
videos/camera_recording_YYYYMMDD_HHMMSS.avi
File Structure
camera_video_recorder.py # Main script
python demo/
mvsdk.py # Camera SDK wrapper
(other demo files)
videos/ # Output directory (created automatically)
camera_recording_*.avi # Recorded video files
Script Features
CameraVideoRecorder Class
list_cameras()- Enumerate and display available camerasinitialize_camera()- Set up camera with custom exposure and gainstart_recording()- Initialize video writer and begin recordingstop_recording()- Stop recording and save video filerecord_loop()- Main recording loop with live previewcleanup()- Proper resource cleanup
Key Functions
- Camera Detection: Automatically finds all connected GigE cameras
- Settings Validation: Checks and clamps exposure/gain values to camera limits
- Frame Processing: Handles both monochrome and color cameras
- Windows Compatibility: Handles frame flipping for Windows systems
- Error Handling: Comprehensive error handling and user feedback
Example Output
Camera Video Recorder
====================
This script allows you to:
- List all available cameras
- Record videos with custom exposure (1ms) and gain (3.5x) settings
- Save videos with timestamps
- Stop recording anytime with 'q' key
Found 1 camera(s):
0: GigE Camera Model (GigE) - SN: 12345678
Using camera: GigE Camera Model
Camera Settings:
Enter exposure time in ms (default 1.0): 1.0
Enter gain value (default 3.5): 3.5
Initializing camera with:
- Exposure: 1.0ms
- Gain: 3.5x
Camera type: Color
Set exposure time: 1000.0μs
Set analog gain: 3.50x (range: 1.00 - 16.00)
Camera started successfully
==================================================
Camera Video Recorder Menu
==================================================
1. Start Recording
2. List Camera Info
3. Test Camera (Live Preview)
4. Exit
Select option (1-4): 1
Started recording to: videos/camera_recording_20241223_143022.avi
Frame size: (1920, 1080), FPS: 30.0
Press 'q' to stop recording...
Recording... Press 'q' in the preview window to stop
Recording stopped!
Saved: videos/camera_recording_20241223_143022.avi
Frames recorded: 450
Duration: 15.2 seconds
Average FPS: 29.6
Troubleshooting
Common Issues
-
"No cameras found!"
- Check camera connection
- Verify camera power
- Ensure network configuration for GigE cameras
-
"SDK initialization failed"
- Verify
python demo/mvsdk.pyexists - Check camera drivers are installed
- Verify
-
"Camera initialization failed"
- Camera may be in use by another application
- Try disconnecting and reconnecting the camera
-
Recording issues
- Ensure sufficient disk space
- Check write permissions in the output directory
Performance Tips
- Close other applications using the camera
- Ensure adequate system resources (CPU, RAM)
- Use SSD storage for better write performance
- Adjust frame rate if experiencing dropped frames
Customization
You can modify the script to:
- Change video codec (currently XVID)
- Adjust target frame rate
- Modify output filename format
- Add additional camera settings
- Change preview window size
Notes
- Videos are saved in the
videos/directory with timestamp filenames - The script handles both monochrome and color cameras automatically
- Frame flipping is handled automatically for Windows systems
- All resources are properly cleaned up on exit