OpenCV:车轴检测

OpenCV : Vehicle axle detection

我试图检测图像中的车轴。这是我遵循的步骤。

对于 canny,threshold1、threshold2 参数使用轨迹条变化,对于 Hough 圆,param1、param2、minDist 变化。通过param1和param2对检测没有影响。

原文:

中位数: 精明:

检测到的圈子:

问题 : 正如你在最后一张图片中看到的,它检测到圆圈并且它离原始轴有点远。我是否需要更改或考虑任何其他参数?

代码

import cv2
import numpy as np

def readAndResize(image,a):
    imag = cv2.imread(image,a)
    org = cv2.imread(image)
    #resixe the image
    small = cv2.resize(imag, (0,0), fx=0.3, fy=0.3)
    small2 = cv2.resize(org, (0,0), fx=0.3, fy=0.3)
    height, width = small.shape
    img = small[height - height/3:height,0:width]
    org2 = small2[height - height/3:height,0:width]
    return img, org2


img,org2 = readAndResize('5.jpg',0)
cv2.imshow('Original',org2)
gray = cv2.cvtColor(org2, cv2.COLOR_BGR2GRAY)
med = cv2.medianBlur(gray,5)
canny = cv2.Canny(med,100,50)
circles = cv2.HoughCircles(canny,cv2.HOUGH_GRADIENT,1,92,20,10,minRadius=4,maxRadius=0)
circles = np.uint16(np.around(circles))

for i in circles[0,:]:
    cv2.circle(org2,(i[0],i[1]),i[2],(0,255,0),2)
    cv2.circle(org2,(i[0],i[1]),2,(0,50,255),3)
    cv2.imshow('Median',med)
    cv2.imshow('canny',canny)
    cv2.imshow('Detected',org2)
cv2.waitKey(0)
cv2.destroyAllWindows()

抱歉,我没有使用您的代码。这里还有一些可以帮助你的东西:

import cv2
import cv2.cv as cv
import numpy as np
import sys

img = cv2.imread('5.jpg',0)
img = cv2.medianBlur(img,5)
cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)
circles = cv2.HoughCircles(img,cv.CV_HOUGH_GRADIENT,1,240,
                               param1=250,
                               param2=50,
                               minRadius=5,
                               maxRadius=200)
circles = np.uint16(np.around(circles))
for i in circles[0,:]:
    cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),2) 
    cv2.circle(cimg,(i[0],i[1]),2,(0,0,255),1)
print circles
cv2.imshow('circles',cimg)
cv2.waitKey(0)
cv2.destroyAllWindows()

玩参数240 param1 param2 minRadius maxRadius 另外我用这段代码得到了什么 Sample