I’m building a rover that goes down a driveway that is surrounded by grass. I’ve tried different methods to extract the blacktop portion including different classification engines, edge detections, etc. Seems simply using a green mask does the best for me (see image).
Here is my super newbie question (new to OpenCV)…how do i get the coordinates of where the black transitions to green in the image? I want to grab a line of pixels 50% vertically in the image and then calculate where the center of the black region is horizontally.
In other words i need to figure how far off the center of the black region my rover is to feed my PID controller…
import cv2
import numpy as np
## Read
img = cv2.imread("Photos/dw.jpg")
## convert to hsv
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
## mask of green (36,25,25) ~ (86, 255,255)
# mask = cv2.inRange(hsv, (36, 25, 25), (86, 255,255))
mask = cv2.inRange(hsv, (36, 25, 25), (70, 255,255))
## slice the green
imask = mask>0
green = np.zeros_like(img, np.uint8)
green[imask] = img[imask]
cv2.imshow('Green', green)
#cv2.imwrite("green.png", green)
cv2.waitKey(0)