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

使用 cv::warpAffine 偏移量目標(biāo)圖像旋轉(zhuǎn) cv::Mat

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

問題描述

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

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

輸入:

旋轉(zhuǎn):

如您所見,旋轉(zhuǎn)后的圖像存在一些問題.首先,它具有與原始大小相同的大小,即使我專門創(chuàng)建了目標(biāo) Mat 與原始大小相反的大小.結(jié)果,目標(biāo)圖像被裁剪.

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.

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

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() 正在在某個偏移量處寫入目標(biāo)(可能是將旋轉(zhuǎn)后的數(shù)據(jù)復(fù)制到圖像的中間)和這個操作會在圖像周圍留下可怕的大黑色邊框.

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().

但在此之前,我需要聲明(以供將來參考)我的懷疑是正確的,您需要在調(diào)用 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());

據(jù)我所知,此函數(shù)繪制的黑色邊框(由在偏移處寫入引起)似乎是標(biāo)準(zhǔn)行為.我已經(jīng)注意到 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() 將圖像旋轉(zhuǎn) 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>

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

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

相關(guān)文檔推薦

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++ 中旋轉(zhuǎn)圖像而不使用 OpenCV 函數(shù))
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 無法設(shè)置 SVM 參數(shù))
Convert a single color with cvtColor(使用 cvtColor 轉(zhuǎn)換單一顏色)
主站蜘蛛池模板: 99热播精品| 狠狠躁躁夜夜躁波多野结依 | 亚洲成人综合在线 | 国产精品国产精品 | 99精品欧美一区二区三区 | 超级黄色一级片 | 国产在线精品一区二区 | 久久久精品综合 | 麻豆一区一区三区四区 | 在线视频 亚洲 | 日韩精品在线观看一区二区 | 中文字幕在线观看精品 | 日韩欧美一区二区三区免费观看 | 国产一区不卡 | 欧美精品在欧美一区二区少妇 | 日韩精品一 | 第一色在线 | 91精品国产综合久久久久蜜臀 | 欧美一级黄色片在线观看 | 久久久av中文字幕 | wwww.xxxx免费 | 9999国产精品欧美久久久久久 | 欧美一级特黄aaa大片在线观看 | 国产精品精品视频一区二区三区 | 99久久国产综合精品麻豆 | 亚洲精品99| 久草精品在线 | 老司机狠狠爱 | 国产成人免费 | 久久不卡 | 99re99| 在线观看免费国产 | 精品国产aⅴ | 国产高清久久久 | 久久性av | 欧美黄色一区 | 国产男女视频网站 | 蜜月aⅴ国产精品 | 91久久久久久 | 野狼在线社区2017入口 | 国产精品91久久久久久 |