以给定角度裁剪图像

时间:2015-05-26 17:17:04

标签: c++ image opencv

我有中心,倾斜角度(方向)以及要从其他图像裁剪的子图像边的度量,例如:

original image

为:

final image

我设法用正确的倾向使用:

    Mat img;
    Point center;
    float angle;
    Mat rotation = getRotationMatrix2D(center, angle, 1.0);
    warpAffine(img, img, rotation, img.size());

但是我不知道如何用给定的边切割那个区域......我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

如果您可以旋转图像,之后您只需要一个角位置(例如,右下角)以及要裁剪的图像的宽度和高度。

话虽如此,您可以设置ROI(感兴趣的区域)并使用

进行裁剪
cv::Rect RegionOfInterest(top_left_x, top_left_y, rectangle_width, rectangle_height);
cv::Mat outputImage;

outputImage = originalImage(RegionOfInterest).clone();

其中top_left_xtop_left_y是左上角坐标,rectangle_widthrectangle_height是您感兴趣的矩形的宽度和高度。

相关问题