相关疑难解决方法(0)

在C++中的OpenCV中无需裁剪即可旋转图像

我想旋转图像,但是如果没有裁剪,我无法获得旋转的图像

我原来的形象:

在此输入图像描述

现在我使用这段代码:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

// Compile with g++ code.cpp -lopencv_core -lopencv_highgui -lopencv_imgproc

int main()
{
    cv::Mat src = cv::imread("im.png", CV_LOAD_IMAGE_UNCHANGED);
    cv::Mat dst;

    cv::Point2f pc(src.cols/2., src.rows/2.);
    cv::Mat r = cv::getRotationMatrix2D(pc, -45, 1.0);

    cv::warpAffine(src, dst, r, src.size()); // what size I should use?

    cv::imwrite("rotated_im.png", dst);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

并获得以下图像:

在此输入图像描述

但我想得到这个:

在此输入图像描述

非常感谢您的帮助!

c++ opencv

52
推荐指数
6
解决办法
5万
查看次数

将Opencv矩阵旋转90度,180度,270度

我正在从网络摄像头捕捉图像,我需要以直角旋转它.我发现自己的功能:

  1. getRotationMatrix2D - 创建旋转矩阵(无论它是什么)
  2. transform - 通过旋转矩阵将一个矩阵转换为另一个矩阵

但是,除了黑色区域,我什么也得不到.这是我的代码:

   if(rotate_button.click%4>0) {
       double angle = (rotate_button.click%4)*90;  //button increments its click by 1 per click
       Mat transform_m = getRotationMatrix2D(Point(cam_frame_width/2, cam_frame_height/2), angle, 1);  //Creating rotation matrix
       Mat current_frame;
       transform(cam_frame, current_frame, transform_m);  //Transforming captured image into a new one
       cam_frame = Mat((int)current_frame.cols,(int)current_frame.rows, cam_frame_type) = Scalar(0,128,0);  //resizing captured matrix, so I can copy the resized one on it
       current_frame.copyTo(cam_frame);  //Copy resized to original
   }
Run Code Online (Sandbox Code Playgroud)

输出只是黑屏.

c++ opencv matrix image-rotation

34
推荐指数
3
解决办法
8万
查看次数

使用python在OpenCV中进行透视校正

我正在尝试对倾斜的矩形(信用卡)进行透视校正,该矩形在所有4个方向上倾斜.我可以找到它的四个角和倾斜的相应角度,但我找不到坐标的确切位置,它必须在哪里投影.我正在使用cv2.getPerspectiveTransform进行转换.

我有实际卡的宽高比(非倾斜的卡),我想要这样的坐标,以保持原始的宽高比.我尝试过使用边界矩形,但这会增加卡的大小.

任何帮助,将不胜感激.测试图像

边界矩形

python opencv perspective

15
推荐指数
3
解决办法
1万
查看次数

标签 统计

opencv ×3

c++ ×2

image-rotation ×1

matrix ×1

perspective ×1

python ×1