【发布时间】:2019-11-29 15:59:39
【问题描述】:
我有一个车轮的图像,我想用 OpenCV 检测映射到这个车轮(或车轮的内圆)的椭圆(用于车辆/车轮的姿态估计)。
[![在此处输入图片描述][1]][1]
有人知道怎么做吗?
[![在此处输入图片描述][2]][2]
生成的图像应该看起来像这样(或者有点像这样 - 我需要检索一些通过省略号的点)。请注意,结果应该是椭圆,而不是圆形,因为如果从侧面看,轮子可能会透视/变形。
到目前为止,我尝试了 Contour(并识别最大的轮廓区域)、canny 和颜色阈值,我能够在我的大多数测试图像上识别出车轮的内椭圆(成功!)。这个“内椭圆”是最大轮廓的一部分,但它也包含我不需要的其他点。
看图: [![在此处输入图片描述][3]][3]
最后一个问题是,如何推导出这个内圆/椭圆的几个点(并去除其他垃圾)以便我可以计算椭圆参数?
任何帮助将不胜感激。
非常感谢!
编辑:
到目前为止,这是我的代码:
import sys
import numpy as np
import skimage.io
import skimage.filters
import matplotlib.pyplot as plt
import cv2
from skimage import data, color, img_as_ubyte
from skimage.feature import canny
from skimage.transform import hough_ellipse
from skimage.draw import ellipse_perimeter
# get filename and sigma value from command line
filename0 = 'back_wheel.png'
filename1 = "backwheel1.png"
filename2 = "backwheel2.png"
filename3 = "backwheel3.png"
filename4 = "frontwheel1.png"
filename5 = "frontwheel2.png"
def getWheel0(filename):
image_rgb_orig = cv2.imread(filename)
image_rgb = image_rgb_orig.copy()
print('Original Dimensions : ',image_rgb.shape)
width = 350
height = (int)(width * image_rgb.shape[0]/image_rgb.shape[1])
dim = (width, height)
image_rgb = cv2.resize(image_rgb, dim, interpolation=cv2.INTER_AREA)
image_gray = cv2.cvtColor(image_rgb, cv2.COLOR_BGR2GRAY)
equ = cv2.equalizeHist(image_gray)
#edges = cv2.Canny(image_gray, 150, 200)
norm_image = cv2.normalize(equ, None, alpha=0, beta=1, norm_type=cv2.NORM_MINMAX)
#--- First obtain the threshold using the greyscale image ---
ret,th = cv2.threshold(norm_image, 50, 100, cv2.THRESH_TOZERO_INV)
#--- Find all the contours in the binary image ---
contours,hierarchy = cv2.findContours(th,2,1)
#contours, hierarchy = cv2.findContours(th, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_TC89_L1)
cnt = contours
big_contour = []
max = 0
for i in cnt:
area = cv2.contourArea(i) #--- find the contour having biggest area ---
if(area > max):
max = area
big_contour = i
result = cv2.drawContours(image_rgb, big_contour, -1, (0,255,0), 3)
fig2, (ax1, ax2, ax3) = plt.subplots(ncols=3, nrows=1, figsize=(8, 4), sharex=True,
sharey=True)
ax1.set_title('Original picture')
ax1.imshow(image_rgb_orig)
ax2.set_title('Threshhold')
ax2.imshow(th)
ax3.set_title('Contour')
ax3.imshow(result)
plt.show()
getWheel0(filename0)
getWheel0(filename1)
getWheel0(filename2)
getWheel0(filename3)
getWheel0(filename4)
getWheel0(filename5)
运行它 “蟒蛇轮胎.py”
【问题讨论】:
-
你指的是哪个椭圆?黄色的打扰了?
-
我想知道穿过轮胎的椭圆。它大多接近圆形,但从侧面看,它会是一个椭圆。我之所以想知道穿过车轮的椭圆,是因为从这个椭圆中,我可以估计出车辆的姿态。
-
所以基本上是轮胎的内部部分?
-
是的。轮胎的内部就是它。
-
我会尝试基于 RANSAC 的方法。
标签: opencv