久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使用 cv::warpAffine 偏移量目標圖像旋轉 cv::Mat

Rotate cv::Mat using cv::warpAffine offsets destination image(使用 cv::warpAffine 偏移量目標圖像旋轉 cv::Mat)
本文介紹了使用 cv::warpAffine 偏移量目標圖像旋轉 cv::Mat的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試使用 OpenCV 的 C++ API1296x968 圖像90 度旋轉,并且我遇到了一些問題.

I'm trying to rotate a 1296x968 image by 90 degrees using the C++ API of OpenCV and I'm facing a few problems.

輸入:

旋轉:

如您所見,旋轉后的圖像存在一些問題.首先,它具有與原始大小相同的大小,即使我專門創建了目標 Mat 與原始大小相反的大小.結果,目標圖像被裁剪.

As you can see, the rotated image has a few problems. First, it has the same size of the original, even though I specifically create the destination Mat with the inverted size of the original. As a result, the destination image gets cropped.

我懷疑這是因為我正在調用 warpAffine() 并傳遞原始 Mat 的大小而不是目標 Mat.但我這樣做是因為我遵循了這個答案,但現在我懷疑答案可能是錯誤的.所以這是我的第一個疑問/問題.

I suspect this is happening because I'm calling warpAffine() and passing the size of the original Mat instead of the size of destination Mat. But I'm doing this because I followed this answer, but now I suspect that the answer may be wrong. So this is my first doubt/problem.

第二個,是 warpAffine() 正在在某個偏移量處寫入目標(可能是將旋轉后的數據復制到圖像的中間)和這個操作會在圖像周圍留下可怕的大黑色邊框.

The second, is that warpAffine() is writing to the destination at a certain offset (probably to copy the rotated data to the middle of the image) and this operation leaves a horrible and large black border around the image.

我該如何解決這些問題?

我在下面分享源代碼:

#include <cv.h>
#include <highgui.h>
#include <iostream>

using namespace cv;
using namespace std;

void rotate(Mat& image, double angle)
{
    Point2f src_center(image.cols/2.0F, image.rows/2.0F);

    Mat rot_matrix = getRotationMatrix2D(src_center, angle, 1.0);

    Mat rotated_img(Size(image.size().height, image.size().width), image.type());

    warpAffine(image, rotated_img, rot_matrix, image.size());
    imwrite("rotated.jpg", rotated_img);
}

int main(int argc, char* argv[])
{
    Mat orig_image = imread(argv[1], 1);
    if (orig_image.empty())
    {
        cout << "!!! Couldn't load " << argv[1] << endl;
        return -1;
    }

    rotate(orig_image, 90);

    return 0;
}

推薦答案

找到了一個解決方案,它不涉及warpAffine().

I've found a solution that doesn't involve warpAffine().

但在此之前,我需要聲明(以供將來參考)我的懷疑是正確的,您需要在調用 warpAffine():

But before that, I need to state (for future references) that my suspicion was right, you needed to pass the size of the destination when calling warpAffine():

warpAffine(image, rotated_img, rot_matrix, rotated_img.size());

據我所知,此函數繪制的黑色邊框(由在偏移處寫入引起)似乎是標準行為.我已經注意到 C 接口以及在 Mac 和 Linux 上運行的 OpenCV 的 C++ 接口,使用版本 2.3.1a 和 2.3.0.

As far as I can tell, the black border (caused by writing at an offset) drawed by this function seems to be it's standard behavior. I've noticed this with the C interface and also with the C++ interface of OpenCV running on Mac and Linux, using the versions 2.3.1a and 2.3.0.

我最終使用的解決方案比所有這些扭曲簡單得多.您可以使用 cv::transpose()cv::flip() 將圖像旋轉 90 度.這是:

The solution I ended up using is much simpler than all this warp thing. You can use cv::transpose() and cv::flip() to rotate an image by 90 degrees. Here it is:

Mat src = imread(argv[1], 1);

cv::Mat dst;
cv::transpose(src, dst);
cv::flip(dst, dst, 1);

imwrite("rotated90.jpg", dst);

----I>

這篇關于使用 cv::warpAffine 偏移量目標圖像旋轉 cv::Mat的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Assertion failed (size.widthgt;0 amp;amp; size.heightgt;0)(斷言失敗(size.width0 amp;amp; size.height0))
Rotate an image in C++ without using OpenCV functions(在 C++ 中旋轉圖像而不使用 OpenCV 函數)
OpenCV: process every frame(OpenCV:處理每一幀)
Why can#39;t I open avi video in openCV?(為什么我不能在 openCV 中打開 avi 視頻?)
OpenCV unable to set up SVM Parameters(OpenCV 無法設置 SVM 參數)
Convert a single color with cvtColor(使用 cvtColor 轉換單一顏色)
主站蜘蛛池模板: 日日操夜夜操天天操 | 亚洲精品视频免费 | 日韩国产精品一区二区三区 | 奇米影视77 | 成人三级av | 日韩在线不卡 | 久久综合欧美 | 久久综合av | 午夜免费福利影院 | 中文字幕 在线观看 | 久久久www成人免费精品张筱雨 | 久久久国产精品视频 | av免费入口| 日批的视频 | 粉嫩一区二区三区国产精品 | 国产成人精品一区二区三区网站观看 | 91一区二区三区在线观看 | 精品一区二区三区在线视频 | 特级黄一级播放 | 在线播放精品视频 | 日韩精品一二三 | 夜夜摸天天操 | 国产一区久久久 | 日韩视频在线免费观看 | 黑人巨大精品欧美一区二区免费 | 国产成人精品午夜 | 久久99精品久久久久久国产越南 | 国产精品一区二区不卡 | 亚洲精品视频一区二区三区 | 国产精品一区二区三 | 国产精品二区三区在线观看 | 91精品国产91综合久久蜜臀 | 国产日韩精品视频 | 欧美一区视频在线 | 最新超碰 | 午夜精品在线 | 国产精品视频中文字幕 | 黄色免费网站在线看 | 一区二区三区免费在线观看 | av日韩在线播放 | 天堂成人国产精品一区 |