1
我有一個Image從相機(我的VW T5範的內部)獲得。我想知道如何準確地重現形狀。我使用lensfun和gimp糾正鏡頭變形。我想通過利用矩形特徵來量化剩餘的扭曲。我可以使用match_template
檢測矩形,但我不知道如何檢測矩形。在圖像中找到矩形,最好與滑雪圖像
最後我想標記它們並測量寬度和長度。爲了更好地顯示中心,我試圖找到這些中心,但這並不像我想象的那麼簡單,因爲一個簡單的閾值可以多次計算相同的點。我如何找到所有檢測到的矩形的中心?
這可以通過skimage完成嗎?或者我應該使用opencv?
import numpy as np
import matplotlib.pyplot as plt
from scipy import ndimage as ndi
from scipy.ndimage.filters import maximum_filter
from scipy.ndimage import center_of_mass
from skimage.color import rgb2grey
from skimage.feature import match_template
from skimage import feature, io
from skimage import img_as_float
%matplotlib inline
image = io.imread('../lensfun_cut.JPG')
imgray = rgb2grey(image)
template = imgray[1365:1390,445:470]
result = match_template(imgray, template)
#
hit = np.where(result>0.90)
fig, ax = plt.subplots(ncols=1,figsize=(8,8))
ax.imshow(result,cmap=plt.cm.spectral)
# loop over the detected regions and draw a circe around them
for i in range(len(hit[0])):
rect = plt.Circle((hit[1][i],hit[0][i]), 20,linewidth=1, edgecolor='r', facecolor='none')
ax.add_patch(rect)
有趣的解決方案。特別是刪除邊框的方法。我會試一試。你認爲像索貝爾這樣的方法可能會引入更少的噪音嗎? – Moritz
我可能不會嘗試去除圖像預處理中的噪點,但要等待輪廓等級。你的矩形具有幾乎完美的形狀,但非常小,每個預處理都有形狀惡化的危險。但是,從其他斑點選擇矩形形狀類型時,形狀將是您的選擇,我認爲您可以通過簡單地使用上面顯示的輪廓特徵來完成此操作,儘管您可能必須稍微使用一些參數。我選擇的下一個方法是檢測矩形網格並僅在網格十字的位置查找斑點。 – tfv