[英]object (Car) Detection and segmentation
我試圖從僅包含一輛車和簡單背景的圖像中分割汽車
但我從實施中得到的是這個
和
分別
但它很容易在幾乎已經分段的圖像上工作。
給出結果如
我正在使用的准則是
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上),但它也無濟於事。 我正在尋找一種方法來分割前兩個圖像,結果類似於第三個。
首先, 檢測和分割是兩個不同的問題。 首先決定你想做哪一個。
如果您的問題是“ 從單張圖像檢測汽車 ”,則無法通過細分來實現。 您可以將圖像分割成零件並使用另一種方法(采用最大的分割區域),您可以在圖像中找到汽車,但我確信它不適用於所有圖像。 這就是分水嶺算法不起作用的原因。 分割算法只是對圖像進行分割,而不會為其提供特定的對象/區域。 例如,如果您查看顯示的圖像,它會被分割成區域,但您無法知道哪個區域是哪個區域。
,
如果要檢測圖像中的汽車,則需要將此問題作為對象檢測問題來處理。 此鏈接將為您提供有關汽車檢測問題的一些信息。 它有兩篇關於它的論文和一個測試方法的數據庫。
希望能幫助到你..
對於汽車檢測,我會使用latern svm檢測器和“Car”型號:
http://docs.opencv.org/modules/objdetect/doc/latent_svm.html
我想@GilLevi說,一旦你學會了一套針對檢測問題的汽車的全局特征,就可以根據更具體的特征產生汽車類別的子標題:如顏色分布,形狀模板,徽標等,並成為另一類語義圖像分割。 您仍然可以從學習部分獲得大量收益,而不是專注於需要調整許多變量的分段特定方法。 汽車的另一個數據集: http : //lear.inrialpes.fr/people/marszalek/data/ig02/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.