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

OpenCV中基于已知相機方向的透視變形

Perspective Warping in OpenCV based on know camera orientation(OpenCV中基于已知相機方向的透視變形)
本文介紹了OpenCV中基于已知相機方向的透視變形的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習吧!

問題描述

我正在開展一個項目,該項目試圖根據(jù)相機的已知方向從圖像中消除透視失真.我的想法是,我可以根據(jù)相機的已知 X、Y 和 Z 方向創(chuàng)建一個旋轉(zhuǎn)矩陣.然后我可以通過 WarpPerspective 方法將這些矩陣應(yīng)用于圖像.

I am working on a project which attempts to remove the perspective distortion from an image based on the known orientation of the camera. My thinking is that I can create a rotational matrix based on the known X, Y, and Z orientations of the camera. I can then apply those matrices to the image via the WarpPerspective method.

在我的腳本(用 Python 編寫)中,我創(chuàng)建了三個旋轉(zhuǎn)矩陣,每個矩陣都基于一個方向角.我已經(jīng)到了一個我被困在兩個問題上的地步.首先,當我將每個單獨的矩陣加載到 WarpPerspective 方法中時,它似乎無法正常工作.每當我在一個軸上扭曲圖像時,它似乎都會顯著過度扭曲圖像.僅當我將方位角限制在 1 度或以下時,才能識別圖像的內(nèi)容.

In my script (written in Python) I have created three rotational matrices, each based on an orientation angle. I have gotten to a point where I am stuck on two issues. First, when I load each individual matrix into the WarpPerspective method, it doesn't seem to be working correctly. Whenever I warp an image on one axis it appears to significantly overwarp the image. The contents of the image are only recognizable if I limit the orientation angle to around 1 degree or less.

其次,如何將三個旋轉(zhuǎn)矩陣組合成一個矩陣以加載到 WarpPerspective 方法中.我可以將 3x3 旋轉(zhuǎn)矩陣導(dǎo)入該方法,還是必須創(chuàng)建一個 4x4 投影矩陣.下面是我正在處理的代碼.

Secondly, how do I combine the three rotational matrices into a single matrix to be loaded into the WarpPerspective method. Can I import a 3x3 rotational matrix into that method, or do I have to create a 4x4 projective matrix. Below is the code that I am working on.

感謝您的幫助.

CR

from numpy import *
import cv

#Sets angle of camera and converts to radians
x =  -14 * (pi/180)
y = 20 * (pi/180)
z =  15 * (pi/180)

#Creates the Rotational Matrices
rX = array([[1, 0, 0], [0, cos(x), -sin(x)], [0, sin(x), cos(x)]])
rY = array([[cos(y), 0, -sin(y)], [0, 1, 0], [sin(y), 0, cos(y)]])
rZ = array([[cos(z), sin(z), 0], [-sin(z), cos(z), 0], [0, 0, 1]])

#Converts to CVMat format
X = cv.fromarray(rX)
Y = cv.fromarray(rY)
Z = cv.fromarray(rZ)

#Imports image file and creates destination filespace
im = cv.LoadImage("reference_image.jpg")
dst = cv.CreateImage(cv.GetSize(im), cv.IPL_DEPTH_8U, 3)

#Warps Image
cv.WarpPerspective(im, dst, X)

#Display
cv.NamedWindow("distorted")
cv.ShowImage("distorted", im)
cv.NamedWindow("corrected")
cv.ShowImage("corrected", dst)
cv.WaitKey(0)
cv.DestroyWindow("distorted")
cv.DestroyWindow("corrected")

推薦答案

你做錯了幾件事.首先,您不能在沒有相機模型的情況下在 x 或 y 軸上旋轉(zhuǎn).想象一下具有令人難以置信的寬視野的相機.您可以將它非常靠近一個物體并看到整個物體,但是如果該物體旋轉(zhuǎn)它的邊緣似乎會很快飛向您,并帶有強烈的透視失真.另一方面,小視野(想想望遠鏡)幾乎沒有透視失真.一個不錯的起點是將您的圖像平面設(shè)置為至少與相機的寬度一樣遠,并將您的對象放在圖像平面上.這就是我在這個例子中所做的(c++ openCV)

You are doing several things wrong. First, you can't rotate on the x or y axis without a camera model. Imagine a camera with an incredibly wide field of view. You could hold it really close to an object and see the entire thing but if that object rotated its edges would seem to fly towards you very quickly with a strong perspective distortion. On the other hand a small field of view (think telescope) has very little perspective distortion. A nice place to start is setting your image plane at least as far from the camera as it is wide and putting your object right on the image plane. That is what I did in this example (c++ openCV)

步驟是

  1. 構(gòu)造一個旋轉(zhuǎn)矩陣
  2. 在原點居中圖像
  3. 旋轉(zhuǎn)圖片
  4. 將圖像沿 z 軸向下移動
  5. 乘以相機矩陣
  6. 扭曲視角

<小時>

//1
float x =  -14 * (M_PI/180);
float y =  20 * (M_PI/180);
float z =  15 * (M_PI/180);

cv::Matx31f rot_vec(x,y,z);
cv::Matx33f rot_mat;
cv::Rodrigues(rot_vec, rot_mat); //converts to a rotation matrix

cv::Matx33f translation1(1,0,-image.cols/2,
                        0,1,-image.rows/2,
                        0,0,1);
rot_mat(0,2) = 0;
rot_mat(1,2) = 0;
rot_mat(2,2) = 1;

//2 and 3
cv::Matx33f trans = rot_mat*translation1;
//4
trans(2,2) += image.rows;
cv::Matx33f camera_mat(image.rows,0,image.rows/2,
                       0,image.rows,image.rows/2,
                       0,0,1);
//5
cv::Matx33f transform = camera_mat*trans;
//6
cv::Mat final;
cv::warpPerspective(image, final, cv::Mat(transform),image.size());

這段代碼給了我這個輸出

This code gave me this output

在我發(fā)布此消息之前,我沒有看到佛朗哥的回答.他是完全正確的,使用 FindHomography 可以為您節(jié)省所有這些步驟.我仍然希望這很有用.

I did not see Franco's answer until I posted this. He is completely correct, using FindHomography would save you all these steps. Still I hope this is useful.

這篇關(guān)于OpenCV中基于已知相機方向的透視變形的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區(qū)域周圍繪制一個矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個矩形邊界框中應(yīng)用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據(jù)文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 日韩电影a | cao视频 | 午夜视频网站 | www.v888av.com| 2021狠狠干 | 美女视频h | 午夜免费看 | 国产一区二区视频免费在线观看 | 久久国产传媒 | 99久久免费精品视频 | 亚洲一区久久 | 国产精品久久久久久52avav | 久操伊人 | 日本小视频网站 | 国产在线视频99 | 日韩精品一区二区三区四区视频 | av网站推荐| www.国产精品 | 日韩欧美综合 | 国产精品日女人 | 亚洲男人天堂网 | 一区二区三区四区日韩 | 免费一区二区 | 一区二区三区中文字幕 | 九九综合九九 | 毛片一级电影 | 精品av天堂毛片久久久借种 | 污片在线免费观看 | 亚洲精品国产一区 | 亚洲国产成人精品久久久国产成人一区 | www.久久影视 | 国产亚洲一区二区三区在线观看 | 一级免费毛片 | 久久久亚洲一区 | 日韩一区二区三区视频 | 欧美精品成人影院 | www.亚洲视频 | 久久久久久影院 | chengrenzaixian| 在线资源视频 | 福利社午夜影院 |