IrProCapture is a macOS application for capturing, analyzing, and recording thermal imaging data from InfiRay thermal cameras. This document provides an overview of the system architecture to help developers understand how the components fit together and where to look when adding new features.
The application follows a Model-View-Controller (MVC) pattern:
- Model: The
Cameraclass serves as the main model, managing capture, processing, and state - View: SwiftUI views in the
Viewsdirectory display the thermal data and controls - Controller: The
IrProCaptureApp.swiftinitializes the application and sets up the UI structure
Camera.swift is the central component that:
- Manages the thermal camera state and configuration
- Processes temperature data
- Handles image colorization and visualization
- Manages recording and capture functionality
- Tracks temperature history data over time
The Camera class implements:
ObservableObjectfor SwiftUI integrationCaptureDelegatefor handling camera capture events
The capture stack consists of several specialized components within the Camera/Components directory:
-
Capture (
Capture.swift)- Manages the AVCaptureSession for the USB thermal camera
- Configures the camera device and capture settings
- Delivers raw frame data to the Camera model
-
ImageCapturer (
ImageCapturer.swift)- Handles the detailed configuration of camera input
- Manages device discovery and setup
-
TemperatureProcessor (
TemperatureProcessor.swift)- Converts raw sensor data to temperature values
- Handles frame averaging for noise reduction
- Computes temperature statistics (min, max, average)
- Generates histogram data for visualization
-
ImageProcessor (
ImageProcessor.swift)- Transforms temperature data into visualized thermal images
- Applies color mapping based on selected color scheme
- Overlays temperature readings at specific points
- Handles image orientation and transformations
-
VideoRecorder (
VideoRecorder.swift)- Records thermal visualization to video files
- Manages encoding settings and file output
The visualization system offers rich customization options:
-
ColorMaps (
ColorMaps.swift)- Defines various color palettes for thermal visualization
- Includes standard schemes like Jet, Inferno, Rainbow, etc.
- Allows for user preference persistence
-
Rotations (
Rotations.swift)- Manages image orientation options
- Handles transformations for different viewing angles
The application uses SwiftUI for its user interface, with components organized in the Views directory:
-
ContentView (
ContentView.swift)- Main view container that organizes the layout
- Displays the thermal image and associated visualizations
- Handles error state presentation
-
CaptureToolbar (
Views/CaptureToolbar.swift)- Provides buttons for camera control (start/stop)
- Handles image capture and video recording
- Offers image rotation controls
- Contains logic for file save dialogs
-
TemperatureHistogramChart (
Views/TemperatureHistogramChart.swift)- Displays a histogram of temperature distribution
- Visualizes temperature ranges in the current frame
-
ColorMapDisplay (
Views/ColorMapDisplay.swift)- Shows the current color map as a temperature gradient
- Displays min/max temperature values
-
TemperatureHistoryChart (
Views/TemperatureHistoryChart.swift)- Shows a time-series chart of temperature data over the last minute
- Tracks min, max, average, and center temperatures
- Updates approximately once per second
- Provides trend visualization for temperature changes
-
App Structure (
IrProCaptureApp.swift)- Sets up the application window and menu commands
- Configures the command menu for color maps, orientation, and capture functions
The data flows through the system as follows:
- The thermal camera produces raw frame data
Capturereceives the frame and passes it toCameravia delegate methodsCamerausesTemperatureProcessorto extract temperature values and statistics- The processed data is used to generate a colorized image via the
ImageProcessor - The resulting image and statistics are published to update the UI
- Temperature history is updated approximately once per second for trend visualization
- If recording, each processed frame is sent to
VideoRecorderfor encoding
- Define a new color map array in
ColorMaps.swift - Add it to the
colorMapsarray - The UI will automatically include it in the ColorMap menu
- Update the camera detection in
Capture.swiftandImageCapturer.swift - Modify the
TemperatureProcessorto handle the camera's specific data format
- Extend the image processing in
ImageProcessor.swift - Incorporate new processing in the
capture(_:didOutput:)method inCamera.swift
- Create a new SwiftUI view in the
Viewsdirectory - Integrate it into
ContentView.swiftor another appropriate parent view - Add new commands to
IrProCaptureApp.swiftfor menu-based features
The application uses a custom IrProError enum for error conditions, primarily related to camera initialization and capture. Error handling is implemented in the UI layer to show appropriate error messages to the user.
- The application uses Apple's Accelerate framework for efficient processing of temperature data
- Frame averaging can be enabled to reduce noise at the cost of responsiveness
- Video recording is optimized to minimize frame drops during capture
- Temperature history tracking is limited to once per second to minimize performance impact
The application relies on several Apple frameworks:
- AVFoundation for camera capture
- CoreImage for image processing
- Accelerate for optimized vector operations
- SwiftUI and Charts for the user interface