twistedfall / opencv-rust

Rust bindings for OpenCV 3 & 4
MIT License
1.98k stars 160 forks source link

opencv-rust can not rotate a image rightly #622

Open zzy444626905 opened 2 weeks ago

zzy444626905 commented 2 weeks ago

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:

  1. Operating system
  2. The way you installed OpenCV: package, official binary distribution, manual compilation, etc.
  3. OpenCV version
    0.93.1
  4. 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)

7. Attach the full output of the following command from your project directory:
   ```shell script
   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)
}
b0ggyb33 commented 1 week ago

I have tried your code and it seems to work fine. What exactly is your issue?