| Crates.io | inkswatch_colorscan |
| lib.rs | inkswatch_colorscan |
| version | 0.1.1 |
| created_at | 2025-12-02 21:16:47.054846+00 |
| updated_at | 2025-12-03 20:07:12.351804+00 |
| description | Fountain pen ink swatch color analysis from photographs |
| homepage | |
| repository | https://github.com/ChrisGVE/InkSwatchColorScan |
| max_upload_size | |
| id | 1962653 |
| size | 492,488 |
A Rust crate for analyzing fountain pen ink colors from digital photographs with calibrated color measurement.
Add to your Cargo.toml:
[dependencies]
inkswatch_colorscan = "0.1"
use inkswatch_colorscan::{analyze_swatch, ColorResult};
use std::path::Path;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let result = analyze_swatch(Path::new("fountain_pen_swatch.jpg"))?;
println!("Hex: {}", result.hex); // #3B5998
println!("Munsell: {}", result.munsell); // 7.5PB 4/8
println!("Color name: {}", result.color_name); // dark purplish blue
println!("Base color: {}", result.base_color); // blue
println!("Lab: L*={:.1}, a*={:.1}, b*={:.1}",
result.lab.l, result.lab.a, result.lab.b); // L*=40.2, a*=5.1, b*=-32.4
println!("Confidence: {:.1}%", result.confidence * 100.0);
Ok(())
}
use inkswatch_colorscan::{analyze_swatch_debug_with_config, PipelineConfig};
use std::path::Path;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Load configuration from JSON
let config = PipelineConfig::from_json_file(Path::new("config.json"))?;
// Analyze with debug output (intermediate images)
let (result, debug) = analyze_swatch_debug_with_config(
Path::new("swatch.heic"),
&config
)?;
// Access debug images: debug.original_image, debug.corrected_image,
// debug.swatch_fragment, debug.swatch_mask
Ok(())
}
# Analyze a single image
cargo run --example cli photo.jpg
# Analyze with JSON output
cargo run --example cli swatch.heic --json
# Batch processing with configuration file
cargo run --example cli_batch config.json
# Batch with CSV output
cargo run --example cli_batch config.json --csv results.csv
Batch Configuration (config.json):
{
"input_path": "/path/to/photos/",
"output_path": "/path/to/output/images/",
"file_pattern": "*.heic",
"white_balance": { "enabled": true },
"swatch_detection": { "luminance_threshold": 0.85 }
}
Note: The CLI tools are development and testing utilities only:
For production applications, see the Deployment section below.
OpenCV: Required for computer vision operations
# macOS
brew install opencv
# Ubuntu/Debian
sudo apt install libopencv-dev
# Windows
# See opencv-rust documentation
libheif (Optional): Required for HEIC/HEIF image support (iPhone photos)
# macOS
brew install libheif
# Ubuntu/Debian
sudo apt install libheif-dev
# Windows
# See libheif documentation
Note: Without libheif, the crate still supports 20+ other formats including JPEG, PNG, TIFF, and WebP.
The project automatically detects OpenCV through pkg-config. No additional environment variables are typically needed.
The following system components are required for building:
OpenCV 4.x - Computer vision library
pkg-config --exists opencv4libheif (Optional) - HEIC/HEIF image format support
pkg-config --exists libheifpkg-config - Build configuration discovery
pkg-config --cflags --libs opencv4C++ Compiler - For OpenCV Rust bindings
macOS (Homebrew)
brew install opencv pkg-config libheif
# OpenCV 4.12.0 confirmed working
# libheif 1.19+ for HEIC support
Build Verification
# Test OpenCV detection
pkg-config --exists opencv4 && echo "OpenCV found"
pkg-config --modversion opencv4 # Should show 4.x.x
# Test compilation
cargo check # Should compile opencv crate successfully
If compilation fails with OpenCV errors:
pkg-config --exists opencv4pkg-config --libs opencv4 | grep coreThe opencv Rust crate (v0.95.1) uses buildtime-bindgen and should automatically:
For best results:
The library provides detailed error information:
match analyze_swatch(path) {
Ok(result) => println!("Color: {}", result.hex),
Err(error) => {
eprintln!("Analysis failed: {}", error);
// User-friendly error messages
if error.is_recoverable() {
eprintln!("Try: {}", error.user_message());
}
}
}
When using inkswatch_colorscan as a library dependency in your application, you have several OpenCV deployment options:
1. Dynamic Linking (Development/Testing)
2. Static Linking (Standalone Applications)
[dependencies]
opencv = { version = "0.95", features = ["static"] }
3. Bundled Libraries (Desktop Applications)
4. vcpkg Integration (Reproducible Builds)
vcpkg install opencv4
export VCPKG_ROOT=/path/to/vcpkg
cargo build
Recommendation: Document OpenCV as a system dependency and let consuming applications choose their deployment strategy based on their distribution requirements.
Current Version: 0.1.0 (Early Development)
This crate is functional but still under active development. The API may change between versions.
This project is in early development. Contributions welcome!
Licensed under either of:
at your option.
This crate uses the following dependencies: