add const data() method to Mat
MODIFY
gen_rust.py
gen_rust.py
@@ -174,6 +174,7 @@ func_rename = { # todo check if any "new" is required
"cv_Mat_step_const": "mat_step",
"cv_Mat_set_size_MatSize": "-", # doesn't allow writing
"cv_Mat_set_step_MatStep": "-", # same as above
+ "cv_Mat_data": "+_mut",
"cv_Mat_push_back__const_void_X": "-", # internal method
"cv_merge_const_Mat_size_t_Mat": "-", # duplicate of cv_merge_VectorOfMat_Mat, but with pointers
"cv_Matx_TOp_Matx_TOp_Matx_TOp": "copy",

MODIFY
src/hub/manual/core/mat.rs
src/hub/manual/core/mat.rs
@@ -290,14 +290,24 @@ impl Mat {
}).into_result()
}
+ pub fn data(&self) -> Result<&u8> {
+ let me = self.as_raw_Mat();
+ cpp!(unsafe [me as "const cv::Mat*"] -> sys::cv_return_value_const_unsigned_char_X as "cv_return_value_const_unsigned_char_X" {
+ try {
+ return { Error::Code::StsOk, NULL, me->data };
+ } CVRS_CATCH(cv_return_value_const_unsigned_char_X)
+ }).into_result()
+ .and_then(|x| unsafe { x.as_ref() }.ok_or_else(|| Error::new(core::StsNullPtr, format!("Function returned Null pointer"))))
+ }
+
pub fn data_typed<T: DataType>(&self) -> Result<&[T]> {
let total = self.total()?;
- self._at(0).map(|x| unsafe { slice::from_raw_parts(x, total) })
+ self.data().map(|x| unsafe { slice::from_raw_parts(x as *const _ as *const _, total) })
}
pub fn data_typed_mut<T: DataType>(&mut self) -> Result<&mut [T]> {
let total = self.total()?;
- self.data().map(|x| unsafe { slice::from_raw_parts_mut(x as *mut _ as *mut _, total) })
+ self.data_mut().map(|x| unsafe { slice::from_raw_parts_mut(x as *mut _ as *mut _, total) })
}
#[inline]

add const data() method to Mat