opencv-rust
opencv-rust copied to clipboard
opencv-rust can not rotate a image rightly
Before reporting an issue please first check the troubleshooting guide. If the issue you're encountering is not solved thereby please state the following in your bugreport:
- Operating system
- The way you installed OpenCV: package, official binary distribution, manual compilation, etc.
- OpenCV version
0.93.1
- rustc version (
rustc --version)
Default host: x86_64-pc-windows-msvc
rustup home: C:\Users\zyzhang60\.rustup
installed toolchains
--------------------
stable-x86_64-pc-windows-gnu
stable-x86_64-pc-windows-msvc (default)
installed targets for active toolchain
--------------------------------------
x86_64-pc-windows-gnu
x86_64-pc-windows-msvc
active toolchain
----------------
stable-x86_64-pc-windows-msvc (default)
rustc 1.81.0 (eeb90cda1 2024-09-04)
- Attach the full output of the following command from your project directory:
RUST_BACKTRACE=full cargo build -vv
8.my rust code :
fn rotate_image(src: &Mat, angle: f64) -> opencv::Result<Mat> {
// 获取图像的高度和宽度
let (h, w) = (src.rows(), src.cols());
// 计算图像中心
let center = Point2f::new((w / 2) as f32, (h / 2) as f32);
let mut affine_matrix = imgproc::get_rotation_matrix_2d(center, angle, 1.0)?;
// 创建新尺寸的画布
let mut rotated = Mat::default();
imgproc::warp_affine(
src,
&mut rotated,
&affine_matrix,
Size::new(w, h),
imgproc::INTER_LINEAR,
BORDER_CONSTANT,
Scalar::all(0.0),
)?;
Ok(rotated)
}
I have tried your code and it seems to work fine. What exactly is your issue?
I'm going to close this issue because of the lack of feedback, please feel free to reopen if you have an update