【问题标题】:object (Car) Detection and segmentation对象(汽车)检测和分割
【发布时间】:2013-11-04 14:34:32
【问题描述】:

我正在尝试从仅包含一辆汽车和简单背景(如

)的图像中分割汽车



但我从我的实现中得到的是这个




分别

但它在几乎已经分割的图像上非常容易工作,例如。


给出类似

的结果


我使用的代码是

import cv2
import numpy as np

THRESH_TYPE=cv2.THRESH_BINARY_INV

def show(name,obj):
    cv2.imshow(name,obj)
    cv2.moveWindow(name, 100, 100) 
    cv2.waitKey(0)
    cv2.destroyAllWindows()

def process_end(new):
    drawing = np.zeros(o.shape,np.uint8)     # Image to draw the contours
    contours,hierarchy =cv2.findContours(new,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)#find connected borders
    for cnt in contours:
        color = np.random.randint(0,255,(3)).tolist()  # Select a random color
        cv2.drawContours(drawing,[cnt],0,color,2)
    print "processing done"
    return drawing

def process(name,path):
    global o
    print "Started!!! processing "+name
    ratio=1#change according to image size
    o=cv2.imread(path+name)#open image
    print type(o)
    show("original",o)
    w,h=o.shape[1]/ratio,o.shape[0]/ratio#resize ratio for width and height
    new=cv2.resize(o,(w,h))#resize image
    #show("Resized",new)
    new=cv2.cvtColor(new,cv2.COLOR_RGB2GRAY)#grey scale image
    show("grey",new)
    cv2.imwrite("grey.jpg",new)
    new1 = cv2.GaussianBlur(new,(5,5),0)#gaussians Blurs Image
    show("blurred1",new1)
    cv2.imwrite("gblur_"+name,new1)#save image
    new2 = cv2.medianBlur(new,7)#Median Blurs Image
    show("blurred2",new1)
    cv2.imwrite("mblur_"+name,new2)#save image
    #new=cv2.equalizeHist(new,)#do image histogram equalisation to better the contrast
    #show("hist equal otsu",new)
    ##cv2.imwrite("otsu_"+name,new)#save image

    a,new=cv2.threshold(new,0,255,THRESH_TYPE | cv2.THRESH_OTSU)#OTSU thresholding
    show("otsu",new)
    cv2.imwrite("otsu_"+name,new)#save image
    return new,name



new,name=process("car9.jpg","C:\\Users\\XOR\\Desktop\\file\\")#Change the Name and path accordingly
new=cv2.Canny(new, 100,200)#canny edge detection technique
show("canny",new)
cv2.imwrite("canny_"+name,new)#save image
new=process_end(new)
show("blobed",new)
cv2.imwrite("blob_"+name,new)#save image
new=cv2.Sobel(new,-1,1,0,3,BORDER_WRAP)
show("sobel",new)
cv2.imwrite("sobel_"+name,new)#save image

我也尝试过分水岭算法(在 matlab 上),但它也无济于事。 我正在寻找一种方法来分割前两个图像,其结果与第三个图像相似。

【问题讨论】:

  • 能否请您查看我的个人资料并给我发电子邮件。我解决了您的另一个问题,但是您昨天在我发布解决方案时将其删除了! (子串问题)
  • @michael 我找不到你的电子邮件...你不能把它发在这里吗?
  • michael.b.paulson@gmail.com
  • @michael 我已将问题邮寄给您

标签: matlab opencv image-processing edge-detection image-segmentation


【解决方案1】:

首先,DetectionSegmentation是两个不同的问题。首先决定你想做哪一个。

如果您的问题是“从单个图像检测汽车”,则无法通过分割来解决。您可以将图像分割成多个部分,并使用另一种方法(采用最大的分割区域)您可以在图像中找到汽车,但我确信它不适用于所有图像。这就是分水岭算法不起作用的原因。分割算法只是分割图像并没有给你特定的对象/区域。例如,如果您查看显示的图像,它被分割成区域,但您无法知道哪个区域是哪个。

,

如果您想检测图像中的汽车,您需要将此问题视为对象检测问题。这个link 将为您提供有关汽车检测问题的一些信息。它有两篇关于它的论文和一个用于测试方法的数据库。

希望对你有帮助..

【讨论】:

  • 感谢@guneykayi。是否有任何简单的方法可以在不阅读研究论文然后学习其中提到的所有算法的情况下找到解决方案,因为现在我更专注于机器学习(因为我的项目)?
  • 生活没那么简单!如果您专注于机器学习,那么您应该阅读这些论文并学习一些算法!
  • OpenCV 为 HOG 等高级描述符提供了工具,它也提供了用于训练分类器(如 SVM)的工具...
  • @guneykayim:很好的解释。不好意思,之前没有看到你的帖子。并感谢您的链接!
  • 我知道我来晚了,今天我们有语义分割,你可以通过这个很棒的工具知道分割的对象是什么。
【解决方案2】:

对于汽车检测,我会使用带有“汽车”模型的后来的 svm 检测器:

http://docs.opencv.org/modules/objdetect/doc/latent_svm.html

【讨论】:

  • 实际上我将不得不在我的系统中使用神经网络进行汽车分类(轿车、SUV、掀背车)我正在寻找一些编码算法,而不是先训练我的系统进行对象检测,然后再进行分类,但是我会调查一下谢谢。
【解决方案3】:

我想就像@GilLevi 所说的,一旦您为检测问题学习了一组汽车的全局特征,就可以根据更具体的特征生成汽车类别的子标签:如颜色分布、形状模板、徽标等,并成为另一类语义图像分割。与专注于需要许多变量来调整的细分特定方法相比,您仍然可以从学习部分中获得很大的收益。另一个包含汽车的数据集:http://lear.inrialpes.fr/people/marszalek/data/ig02/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-18
    • 1970-01-01
    • 2016-12-21
    • 1970-01-01
    • 2017-10-21
    • 1970-01-01
    相关资源
    最近更新 更多