对象(汽车)检测和分割 [英] object (Car) Detection and segmentation

查看:99
本文介绍了对象(汽车)检测和分割的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从仅包含一辆汽车的图像中划分汽车,并且像

I am trying to segment cars from image that consist of only one car and an easy background like




但我从实施中获得的是这个¥b $ b


but what I get from my implementation is this






and



分别为


respectively

但它几乎已经分段的图像非常容易。

but it works very easily on almost already segmented images like.



给出结果,如


giving results like


我使用的代码是

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上)但它也无济于事。
我正在寻找一种方法来分割前两个图像,结果类似于第三个。

I have tried the watershed algorithm (on matlab) too but it also doesn't help. I'm looking for a way to segment the first two images that gives a result similar to third one.

推荐答案

首先,检测细分是两个不同的问题。首先确定你想做哪一个。

First of all, Detection and Segmentation are two different problems. First decide which one you wanna do.

如果你的问题是'从单一图像中检测汽车',你不能通过细分来做到这一点。您可以将图像分割成部分,并使用另一种方法(采用最大的分割区域),您可以在图像中找到汽车,但我确信它不适用于所有图像。这就是分水岭算法不起作用的原因。分割算法只是对图像进行分割,而不会为其提供特定的对象/区域。例如,如果您查看显示的图像,它会被细分为区域,但您无法知道哪个区域是哪个。

If your problem is 'Car Detection From Single Image', you can't do it by segmentation. You can segment image into parts and by using another approach (take the biggest segmented region) you can find the car in the image, but I'm sure it won't work for all images. That's why watershed algorithm didn't work. Segmentation algorithms just segments the image doesn't give you particular object/region in it. For example if you look at the image shown, it is segmented into regions, but you can't know which region is which.

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

If you want to detect cars in images, you need to approach this problem as object detection problem. This link will provide you some information about car detection problem. It has two papers about it and a database to test approaches.

希望它有所帮助......

Hope it helps..

这篇关于对象(汽车)检测和分割的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆