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

使用 OpenCV warpPerspective 時如何顯示整個圖像

How to show the whole image when using OpenCV warpPerspective(使用 OpenCV warpPerspective 時如何顯示整個圖像)
本文介紹了使用 OpenCV warpPerspective 時如何顯示整個圖像的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我這里有 2 張測試圖片.我的問題是,如何在不裁剪圖像的情況下將第一張圖像中的正方形映射到第二張圖像中的四邊形.

I have 2 test images here. My is question is, how to map the square in first image to the quadrilateral in the second image without cropping the image.

圖 1:

圖 2:

這是我當(dāng)前使用 openCV warpPerspective 函數(shù)的代碼.

Here is my current code using openCV warpPerspective function.

import cv2
import numpy as np

img1_square_corners = np.float32([[253,211], [563,211], [563,519],[253,519]])
img2_quad_corners = np.float32([[234,197], [520,169], [715,483], [81,472]])

h, mask = cv2.findHomography(img1_square_corners, img2_quad_corners)
im = cv2.imread("image1.png")
out = cv2.warpPerspective(im, h, (800,800))
cv2.imwrite("result.png", out)

結(jié)果:

如您所見,由于 warpPerspective 函數(shù)中的 dsize=(800,800) 參數(shù),我無法獲得圖像 1 的完整視圖.如果調(diào)整 dsize,正方形將無法正確映射.有沒有辦法調(diào)整輸出圖像的大小,以便我可以得到圖像 1 的全圖?

As you can see, because of dsize=(800,800) parameter in the warpPerspective function, I can't get full view of image 1. If I adjust the dsize, the square won't map properly. Is there any way to resize the output image so that I can get whole picture of image 1?

推薦答案

是的,但您應(yīng)該意識到輸出圖像可能非常大.我很快編寫了以下 Python 代碼,但即使是 3000 x 3000 的圖像也無法適應(yīng)輸出,由于轉(zhuǎn)換,它太大了.雖然,這是我的代碼,但我希望它對你有用.

Yes, but you should realise that the output image might be very large. I quickly wrote the following Python code, but even a 3000 x 3000 image could not fit the output, it is just way too big due to the transformation. Although, here is my code, I hope it will be of use to you.

import cv2
import numpy as np
import cv           #the old cv interface

img1_square_corners = np.float32([[253,211], [563,211], [563,519],[253,519]])
img2_quad_corners = np.float32([[234,197], [520,169], [715,483], [81,472]])

h, mask = cv2.findHomography(img1_square_corners, img2_quad_corners)
im = cv2.imread("image1.png")

這里創(chuàng)建一個輸出圖像,我以 (3000, 3000) 為例.

Create an output image here, I used (3000, 3000) as an example.

out_2 = cv.fromarray(np.zeros((3000,3000,3),np.uint8))

通過使用舊的 cv 接口,我直接寫入輸出,因此不會被裁剪.我使用 cv2 接口嘗試了這個,但由于某種原因它不起作用......也許有人可以對此有所了解?

By using the old cv interface, I wrote directly to the output, and so it does not get cropped. I tried this using the cv2 interface, but for some reason it did not work... Maybe someone can shed some light on that?

cv.WarpPerspective(cv.fromarray(im), out_2, cv.fromarray(h))
cv.ShowImage("test", out_2)
cv.SaveImage("result.png", out_2)
cv2.waitKey()

無論如何,這會給出一個非常大的圖像,其中包含您的原始圖像 1,變形.如果您指定輸出圖像足夠大,整個圖像將可見.(這可能確實很大!)

Anyway, this gives a very large image, that contains your original image 1, warped. The entire image will be visible if you specify the output image to be large enough. (Which might be very large indeed!)

我希望這段代碼可以幫助到你.

I hope that this code may help you.

這篇關(guān)于使用 OpenCV warpPerspective 時如何顯示整個圖像的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 久久久.com| 一区观看 | 国产高清视频在线观看 | 欧美成人精品一区二区男人看 | 久久久久久中文字幕 | 久草资源网站 | 欧美电影网 | 日韩影院一区 | 性视频一区 | 国产成人短视频在线观看 | 国产视频一区二区 | 91一区二区三区 | 精品三级在线观看 | 成人蜜桃av | 中文字幕一二三 | 99久久夜色精品国产亚洲96 | 欧美aaaaa| 精品国产青草久久久久福利 | 国产精品一区二区在线 | 国产精品99久久久久久动医院 | 国产成人久久精品一区二区三区 | 欧美日韩高清在线一区 | 精品二区视频 | 久久美女视频 | 亚洲国产精品网站 | 亚洲一区二区精品视频 | 精品国产久 | 国产精品久久福利 | 日本精品视频在线 | 国产成人精品一区二区在线 | 中文字幕亚洲区一区二 | 宅男伊人| 国产精品美女一区二区三区 | 荷兰欧美一级毛片 | 99伊人| 亚洲天堂成人在线视频 | 午夜大片 | 欧美国产一区二区三区 | 国产天堂| 九九精品网 | 成人久久18免费网站 |