Detect fence-lines from aerial imagery?
Hi all,
We're investigating if it's possible to detect fencelines from aerial imagery (NAIP 0.6m GSD). Our basic approach is to 1) use edge detection methods to generate a set of candidate line features and 2) use ML to assign a probability that each line is a fenceline or not. This inquiry is only regarding the first step.
I've begun playing with OpenCV edge detection routines in combination with HoughLinesP() to see if this is a reasonable approach. I've got some preliminary results that I think could be dramatically improved, and I'm looking for some community insight.
Here's an example of the imagery we're working with:
My workflow so far: 1. convert imagery to grayscale 2. Use Canny Edge Detection 3. Perform a gaussian blur to improve line connectivity 4. Use Hough Line Transform to extract line features.
My code:
import numpy as np
import cv2
import os
#set working dir
os.chdir('c:\\tmp\opencv')
#import image
img = cv2.imread('test1.jpg',1)
height, width = img.shape[:2]
#convert to grayscale
proc_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
#canny edge detection
proc_img = cv2.Canny(proc_img,100,400,apertureSize = 3)
#perform gaussian blur to provide better line connectivity
proc_img = cv2.GaussianBlur(proc_img,(3,3),0)
minLineLength = 25
maxLineGap = 1
lines = cv2.HoughLinesP(proc_img,1,np.pi/180,10,minLineLength,maxLineGap)
for line in lines:
coords = line[0]
cv2.line(img, (coords[0],coords[1]),(coords[2],coords[3]),[255,0,0], 1)
WINDOW_NAME = 'test'
cv2.namedWindow(WINDOW_NAME, cv2.WINDOW_AUTOSIZE)
cv2.startWindowThread()
cv2.imshow(WINDOW_NAME,img)
cv2.waitKey(1)
#cv2.destroyAllWindows()
I've been playing around primarily with minLineLength, maxLineGap, and threshold variables for HoughLinesP, but have not gotten particularly good results (see below).
I'm looking for some insights and ideas to improve on this to see if this approach and concept are worth pursuing. Thoughts?
I would probably go for a segmentation approach, trained for detecting fence like pixels, through a CNN, which works quite well these days.
Thanks. That was likely going to be my next approach if this didn't work out.