use opencv::core;
use winapi::shared::{
minwindef::LPVOID,
};
use super::*;
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "docs-features", doc(cfg(feature = "mat")))]
pub struct MatFrameData {
pub width: i32,
pub height: i32,
pub data: opencv::core::Mat,
_raw_data: Vec<u8>,
}
impl MatFrameData {
pub fn new(width: i32, height: i32, data: core::Mat, raw_data: Vec<u8>) -> Self {
Self{
width, height, data, _raw_data: raw_data
}
}
}
impl Capture {
pub fn get_mat_frame(&self) -> anyhow::Result<MatFrameData, CaptureError> {
let raw = self.get_raw_frame()?;
let mat_data = unsafe {
core::Mat::new_rows_cols_with_data(
raw.height as i32, raw.width as i32, core::CV_8UC4,
raw.data.as_ptr() as LPVOID, core::Mat_AUTO_STEP
).map_err(|err| CaptureError::OpencvError(err.to_string()))?
};
Ok(MatFrameData::new( raw.width as i32, raw.height as i32, mat_data, raw.data ))
}
pub fn wait_mat_frame(&self) -> anyhow::Result<MatFrameData, CaptureError> {
loop {
match self.get_mat_frame() {
Ok(mat) => return Ok(mat),
Err(e) => {
if e == CaptureError::NoTexture {
continue;
}
return Err(e);
},
}
}
}
}