Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cv_compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ pub mod cvtcolor {
let h = if delta == 0.0 {
0.0
} else if max == r {
60.0 * (((g - b) / delta) % 6.0)
60.0 * (((g - b) / delta).rem_euclid(6.0))
} else if max == g {
60.0 * ((b - r) / delta + 2.0)
} else {
Expand Down
20 changes: 20 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,26 @@ mod edge_case_tests {
}
}

#[cfg(test)]
mod cv_compat_tests {
use crate::cv_compat::{cvt_color, ColorConversionCode};
use ndarray::Array3;

#[test]
fn test_rgb_to_hsv_wraps_negative_red_sector_hues() {
let src =
Array3::from_shape_vec((1, 1, 3), vec![255, 0, 128]).expect("shape should be valid");

let hsv = cvt_color(&src.view(), ColorConversionCode::ColorRgb2Hsv).unwrap();

// This color sits in the red sector with g < b, so hue should wrap near 330 degrees.
// OpenCV stores hue in [0, 179], so we expect approximately 165 instead of clamping to 0.
assert!(hsv[[0, 0, 0]] >= 160);
assert_eq!(hsv[[0, 0, 1]], 255);
assert_eq!(hsv[[0, 0, 2]], 255);
}
}

// OpenCV specific tests
#[cfg(test)]
mod opencv_tests {
Expand Down
Loading