opencv-rust icon indicating copy to clipboard operation
opencv-rust copied to clipboard

opencv-rust can not rotate a image rightly

Open zzy444626905 opened this issue 1 year ago • 1 comments

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
  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)
  1. 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)
}

zzy444626905 avatar Oct 01 '24 16:10 zzy444626905

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

b0ggyb33 avatar Oct 09 '24 06:10 b0ggyb33

I'm going to close this issue because of the lack of feedback, please feel free to reopen if you have an update

twistedfall avatar Nov 10 '24 09:11 twistedfall