-
-
Notifications
You must be signed in to change notification settings - Fork 144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#Suggestion# How about simplify the API #332
Comments
Thanks for the suggestion! If I understand correctly you'd like to improve the usability of passing structures like (10, 20).into() where a Is it something that would improve your experience? |
Yeah, thanks a lot. As I am just a freshman to the rust as well as the opencv, I just try to understand the overall logic of cv. I will leave my immature ideas here if needed. |
You can check out this nice article that should help you get started: https://blog.devgenius.io/rust-and-opencv-bb0467bf35ff Let's leave this issue open until the fixes are pushed. |
In my cases , I use a lib.rs to simplify my main code like this, I learned the python opencv bindings and then code it with rust.
so ,just like the shape function, I DIY it with the Mat to get all the info from a img. |
Well, if it's about |
Is there any reference to the calc_hist fn? I looked up the Doc.rs and searched on the web, didn't find some worth infomation about my error, the code looks like this.
And the error shows:
It seems the docs on the Doc.rs it not enough for me to get the answers and to show the histograms. Any help? Thanks a lot. |
You should check the original OpenCV docs here: https://docs.opencv.org/4.x/d6/dc7/group__imgproc__hist.html#ga4b2b5fd75503ff9e6844cc4dcdaed35d |
It seems the problem comes below, but I tried to compare the diff between the C++ version and Doc.rs, still can't find the mistake.
Error:
|
It's quite difficult to help here without the context. It would help if you could write a working example in Python or C++ and then I can help convert it to Rust |
In Python as below:
Something like this, I can't convert it using rust-bindings. |
Is there any solution to the situation above? Or just something wrong with my steps? |
The Python example shown above works correctly on the same image that you're trying to run Rust on, right? |
Yeah, the python code can run correctly, and can show the hist graph. |
This produces the same result as the python code on my machine: use opencv::{prelude::*, core, types, imgproc, imgcodecs};
fn main() {
let img = imgcodecs::imread("1.jpg", imgcodecs::IMREAD_GRAYSCALE).unwrap();
let mut images = types::VectorOfMat::new();
images.push(img);
let mut hist = Mat::default();
imgproc::calc_hist(
&images,
&vec![0].into(),
&core::no_array(),
&mut hist,
&vec![256].into(),
&vec![0., 256.].into(),
false,
).unwrap();
dbg!(&hist.data_typed::<f32>());
} |
I got the right result as well adding code below .
Is this means the input of the calc_hist should be a Vector ranther than a Mat? |
Yes, in fact, in Python code that's exactly what you're passing to the
Not really unfortunately, I've never had to use this particular function myself. |
I am using the opencv rust bindings these days, which I want try to switch the program into rustlang. Well, it seem the API need a lot prelude work before I using the right function. Such as if I need "imwrite", I need to create a parms of ImwriteFlags first. Also, as I want to draw a rectangle, I need to create the line color params and Rect params first. How about just reshape it as a tuple or list instead? I wish the API is as easily used as Python API, that would be much easier for most of us.
The text was updated successfully, but these errors were encountered: