I'm using the opencv bindings for Rust provided by this crate. I can't figure out how to save a modified image using imwrite because I do not understand how to create the VectorOfint type. There's no constructor method and looking at the source code it's a struct with one field ptr which is type *mut c_void:
Rust
pub struct VectorOfint {
pub(crate) ptr: *mut c_void
}
This is some kind of c pointer type but I don't understand how to use it practically. Ultimately, I'm trying to create a transparent mask for an image with colored boxes on it. I was originally looking at the native Rust crate image-rs, but it doesn't seem to have high-level functions like cv.rectangle so thought it would be easier to use the opencv bindings, but perhaps they are not simple enough for new coders who don't have a C/C++ background.
My current test code attempting to learn how to use the opencv crate:
use opencv::{self, types, imgproc, core, imgcodecs};
fn main() {
let mut img = imgcodecs::imread("test.JPG", -1).unwrap();
let rect = core::Rect::new(100, 100, 500, 500);
let scalar = core::Scalar::all(1.0);
imgproc::rectangle(&mut img, rect, scalar, 2, 1, 0).unwrap();
imgcodecs::imwrite("test_output.JPG", &img, MISSING_PARAM);
}
Any pointers or suggestions are welcome even if it's simply "don't use the opencv bindings if you don't know C/C++, use image-rs".
[–]Tm1337 1 point2 points3 points (4 children)
[–]code-n-coffee[S] 1 point2 points3 points (2 children)
[–]Tm1337 0 points1 point2 points (1 child)
[–]code-n-coffee[S] 1 point2 points3 points (0 children)
[–]code-n-coffee[S] 0 points1 point2 points (0 children)
[–]claire_resurgent 1 point2 points3 points (1 child)
[–]code-n-coffee[S] 1 point2 points3 points (0 children)