twistedfall / opencv-rust

Rust bindings for OpenCV 3 & 4

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

from_slice_rows_cols deprecated?

sjbeskur opened this issue · comments

commented

the following method on Mat seems to have been deprecated in the latest update:
from_slice_rows_cols

The suggested workarounds are unclear? Any guidance would be appreciated.

        let img: [u16; 81] = [
            10, 10, 10,  10, 10, 10, 10, 10, 10, //
            10, 10, 10,  10, 10, 10, 10, 10, 10, //
            10, 10, 200, 110, 10, 10, 10, 10, 10, //
            10, 10, 110, 245, 10, 10, 10, 10, 10, //
            10, 10, 10, 245, 10, 10, 10, 10, 10, //
            10, 10, 10, 200, 10, 10, 10, 10, 10, //
            10, 10, 10, 10, 10, 10, 10, 10, 10, //
            10, 10, 10, 10, 10, 10, 10, 10, 10, //
            10, 10, 10, 10, 10, 10, 10, 10, 10, //
        ];
        let image_mat = opencv::core::Mat::from_slice_rows_cols(&img, 9,9).unwrap();  // no worky :(
        assert_eq!(image_mat.depth(), opencv::core::CV_16U);
        assert_eq!(image_mat.dims(), 2);
        assert_eq!(image_mat.channels(), 1);
    } 

I think I forgot to mention this in the changelog, sorry! Yes, it's now been replaced by Mat::new_rows_cols_with_data with slightly different semantics:

  • different order of the arguments and types (better follows OpenCV)
  • returns a BoxedRef so a Mat that references the slice without copying it, if you need a copy call .try_clone()? or .clone()
commented

Thanks, I'll give it a try.

I hope it worked!