第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

在一組cv :: Point上執(zhí)行cv :: warpPerspective以進(jìn)行偽偏移

在一組cv :: Point上執(zhí)行cv :: warpPerspective以進(jìn)行偽偏移

C++
慕尼黑8549860 2019-09-19 15:08:30
我正在嘗試對一組點(diǎn)進(jìn)行透視變換以實(shí)現(xiàn)偏斜效果:http://nuigroup.com/?ACT=28&fid=27&aid=1892_H6eNAaign4Mrnn30Au8d我正在使用下面的圖像進(jìn)行測試,綠色矩形顯示感興趣的區(qū)域。我在想,如果有可能實(shí)現(xiàn),我希望使用的簡單組合的效果cv::getPerspectiveTransform和cv::warpPerspective。我正在分享我到目前為止所寫的源代碼,但它不起作用。這是結(jié)果圖像因此,有一個(gè)vector<cv::Point>是定義感興趣的區(qū)域,但點(diǎn)不存儲在任何特定的順序載體內(nèi),這件事情我不能在檢測過程中發(fā)生改變。無論如何,稍后,向量中的點(diǎn)用于定義a RotatedRect,而這又用于組裝cv::Point2f src_vertices[4];,所需的變量之一cv::getPerspectiveTransform()。我對頂點(diǎn)及其組織方式的理解可能是其中一個(gè)問題。我還認(rèn)為使用a RotatedRect不是存儲ROI原始點(diǎn)的最佳方法,因?yàn)樽鴺?biāo)會稍微改變以適應(yīng)旋轉(zhuǎn)的矩形,這并不是很酷。#include <cv.h>#include <highgui.h>#include <iostream>using namespace std;using namespace cv;int main(int argc, char* argv[]){    cv::Mat src = cv::imread(argv[1], 1);    // After some magical procedure, these are points detect that represent     // the corners of the paper in the picture:     // [408, 69] [72, 2186] [1584, 2426] [1912, 291]    vector<Point> not_a_rect_shape;    not_a_rect_shape.push_back(Point(408, 69));    not_a_rect_shape.push_back(Point(72, 2186));    not_a_rect_shape.push_back(Point(1584, 2426));    not_a_rect_shape.push_back(Point(1912, 291));    // For debugging purposes, draw green lines connecting those points     // and save it on disk    const Point* point = &not_a_rect_shape[0];    int n = (int)not_a_rect_shape.size();    Mat draw = src.clone();    polylines(draw, &point, &n, 1, true, Scalar(0, 255, 0), 3, CV_AA);    imwrite("draw.jpg", draw);    // Assemble a rotated rectangle out of that info    RotatedRect box = minAreaRect(cv::Mat(not_a_rect_shape));    std::cout << "Rotated box set to (" << box.boundingRect().x << "," << box.boundingRect().y << ") " << box.size.width << "x" << box.size.height << std::endl;    }有人可以幫我解決這個(gè)問題嗎?
查看完整描述

3 回答

?
慕尼黑5688855

TA貢獻(xiàn)1848條經(jīng)驗(yàn) 獲得超2個(gè)贊

問題是在向量內(nèi)聲明點(diǎn)的順序,然后在定義上還有另一個(gè)與此相關(guān)的問題dst_vertices。


該點(diǎn)的順序關(guān)系到getPerspectiveTransform(),必須按以下順序指定:


1st-------2nd

 |         |

 |         |

 |         |

3rd-------4th

因此,原產(chǎn)地需要重新訂購:


vector<Point> not_a_rect_shape;

not_a_rect_shape.push_back(Point(408, 69));

not_a_rect_shape.push_back(Point(1912, 291));

not_a_rect_shape.push_back(Point(72, 2186));

not_a_rect_shape.push_back(Point(1584, 2426));

和目的地:


Point2f dst_vertices[4];

dst_vertices[0] = Point(0, 0);

dst_vertices[1] = Point(box.boundingRect().width-1, 0); // Bug was: had mistakenly switched these 2 parameters

dst_vertices[2] = Point(0, box.boundingRect().height-1);

dst_vertices[3] = Point(box.boundingRect().width-1, box.boundingRect().height-1);

在此之后,需要進(jìn)行一些裁剪,因?yàn)樯傻膱D像不僅僅是綠色矩形內(nèi)的區(qū)域,我認(rèn)為它將是:


我不知道這是不是OpenCV的錯(cuò)誤,或者我錯(cuò)過了什么,但主要問題已經(jīng)解決了。


查看完整回答
反對 回復(fù) 2019-09-19
?
qq_遁去的一_1

TA貢獻(xiàn)1725條經(jīng)驗(yàn) 獲得超8個(gè)贊

使用四邊形時(shí),OpenCV并不是你的朋友。RotatedRect會給你不正確的結(jié)果。此外,你需要一個(gè)透視投影,而不是像這里提到的其他仿射投影。


基本上必須做的是:


遍歷所有多邊形段并連接幾乎相同的多邊形段。

對它們進(jìn)行排序,使您擁有4個(gè)最大的線段。

相交這些線,你有4個(gè)最可能的角點(diǎn)。

在從角點(diǎn)和已知對象的縱橫比收集的透視圖上變換矩陣。

我實(shí)現(xiàn)了一個(gè)Quadrangle處理輪廓到四邊形轉(zhuǎn)換的類,并且還將在正確的視角上對其進(jìn)行轉(zhuǎn)換。



查看完整回答
反對 回復(fù) 2019-09-19
  • 3 回答
  • 0 關(guān)注
  • 1039 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號