I am trying to use a camera to help localize my robot in my garden. I want to be able to identify trees as they are the most prominent features.
I am having great difficulty extracting the trees from the background. they seem to have the same colur as the surroundings so I cannot use that so i have been trying to identify the edges.
I have looked at each of RGB and HSV and none seperatly seem to show the edges better than grayscale.
I have used a bilateral filter as it is supposed to blur but maintain the edges and I have used a sobel filter to highlight the edges as it seems to make a better job on this than Cany.
Here is a link to the original test photo. link text
I only take the middle third of the picture to reduce the size and because that part has the treetrunks.
Here is my code:
import cv2
import numpy as np
thresh = 0
sobel_8u = 0
gray = 0
img = 0
kernel = 0
def changeThreshhold(x):
global thresh,sobel_8u,gray,img
ret,thresh = cv2.threshold(sobel_8u,x,255,cv2.THRESH_BINARY )
img = np.vstack((gray,sobel_8u,thresh))
treeName = 'C:\Users\Alan\Desktop\Trees\tree4.jpg'
imgC = cv2.imread(treeName,cv2.CV_LOAD_IMAGE_COLOR)
h,w,c = np.shape(imgC)
partImgC = imgC[h/2:2*h/3,:,:]
gry = cv2.cvtColor(partImgC,cv2.COLOR_BGR2GRAY)
gray = cv2.equalizeHist(gry)
blur = cv2.bilateralFilter(gray,21,75,75)
sobelx64f = cv2.Sobel(blur,cv2.CV_64F,1,0,ksize=3)
abs_sobel64f = np.absolute(sobelx64f)
sobel_8u = np.uint8(abs_sobel64f)
changeThreshhold(65)
cv2.namedWindow('image',cv2.cv.CV_WINDOW_NORMAL)
cv2.createTrackbar('threshhold','image',65,255,changeThreshhold)
while(1):
cv2.imshow('image',img)
k = cv2.waitKey(1) & 0xFF
if k == 27:
break
cv2.destroyAllWindows()
<\code><\pre>
The results are here:link text
They do not look so bad but when I try to use HoughLines to extract the lines and hence the trees I get a huge amount of rubbish.
Can anybody show me a better way.
Thanks Alan