python - OpenCV : Vehicle axle detection

标签 python opencv hough-transform opencv3.1

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

  • 读取图像并更改为灰度。
  • 应用中位数。
  • 应用了canny边缘检测。
  • 应用霍夫圆。

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

原文: Original Image

中位数: Median 精明: Canny

检测到的循环: enter image description here

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

代码

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

关于python - OpenCV : Vehicle axle detection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43911710/

相关文章:

opencv - 在 OpenCV 中检测半圆

python - 将可编辑字段作为 Django-Rest-Framework Serializer 的validated_data 方法传递

python - 如何保存 PIL ImageGrab() img?

python - 在 Python 中构建 URL 时如何连接路径的组件

python - 请求的模块不可用 : vtkRenderingOpenGL-cmake/OpenCVDetectVTK. cmake:6 (find_package)

c++ - Opencv C++为每个imshow打开两个窗口

opencv - 广义霍夫变换 OpenCV Python 模板

python - NoneType 对象没有属性 endwith (Tensorflow)

opencv - 在 OpenCV 中将 HSV 转换为灰度图

opencv - HoughLinesP 与 IplImage