rename more functions, improve tests
MODIFY
tests/imgcodecs.rs
tests/imgcodecs.rs
use std::mem::transmute;
use opencv::{
- core::{self, Mat},
- core::{Size, Vec3b},
+ core::{self, Mat, Size, Vec3b, DataType},
imgcodecs,
};
@@ -11,9 +10,8 @@ const PIXEL: &[u8] = include_bytes!("../pixel.png");
#[test]
fn decode() {
{
- let mut bytes = PIXEL.to_vec();
- let src = Mat::new_rows_cols_with_data(1, PIXEL.len() as _, core::CV_8U, unsafe { transmute(bytes.as_mut_ptr()) }, core::Mat_AUTO_STEP).unwrap();
- let dest = imgcodecs::decode(&src, imgcodecs::IMREAD_COLOR).unwrap();
+ let src = Mat::from_slice::<u8>(PIXEL).unwrap();
+ let dest = imgcodecs::imdecode(&src, imgcodecs::IMREAD_COLOR).unwrap();
assert_eq!(dest.size().unwrap(), Size::new(1, 1));
assert_eq!(dest.channels().unwrap(), 3);
assert_eq!(*dest.at_2d::<Vec3b>(0, 0).unwrap(), Vec3b::from([56u8, 56, 191]));
@@ -21,9 +19,9 @@ fn decode() {
{
let mut bytes = PIXEL.to_vec();
- let src = Mat::new_rows_cols_with_data(1, PIXEL.len() as _, core::CV_8U, unsafe { transmute(bytes.as_mut_ptr()) }, core::Mat_AUTO_STEP).unwrap();
+ let src = Mat::new_rows_cols_with_data(1, PIXEL.len() as _, u8::typ(), unsafe { transmute(bytes.as_mut_ptr()) }, core::Mat_AUTO_STEP).unwrap();
let mut dest = Mat::default();
- imgcodecs::decode_to(&src, imgcodecs::IMREAD_COLOR, &mut dest).unwrap();
+ imgcodecs::imdecode_to(&src, imgcodecs::IMREAD_COLOR, &mut dest).unwrap();
assert_eq!(dest.size().unwrap(), Size::new(1, 1));
assert_eq!(dest.channels().unwrap(), 3);
assert_eq!(*dest.at_2d::<Vec3b>(0, 0).unwrap(), Vec3b::from([56u8, 56, 191]));

MODIFY
tests/mat.rs
tests/mat.rs
use std::mem::transmute;
-use opencv::core::{self, Mat, Scalar, Size, Vec2b, DataType};
-use opencv::types::VectorOfMat;
+use opencv::core::{self, Mat, Scalar, Size, Vec2b, DataType, Vec3b};
+use opencv::types::{VectorOfMat, VectorOfint};
const PIXEL: &[u8] = include_bytes!("../pixel.png");
#[test]
fn mat_for_rows_and_cols() {
- let typ = core::CV_8UC3;
+ let typ = Vec3b::typ();
let mat = unsafe { Mat::new_rows_cols(400, 300, typ) }.unwrap();
assert_eq!(mat.typ().unwrap(), typ);
assert_eq!(mat.size().unwrap(), Size::new(300, 400));
- assert_eq!(core::CV_8U, mat.depth().unwrap());
+ assert_eq!(u8::typ(), mat.depth().unwrap());
assert_eq!(3, mat.channels().unwrap());
}

rename more functions, improve tests