team-4480
27-05-2016, 20:31
Hi,
On our Stronghold robot, we had a camera on a servo for looking around the field. The problem was that the camera was too low on the robot (Thanks, low bar...) and our shooter cims were blocking a good portion of the view. So thinking of things we could actually use the camera for, I came up with the idea o a basic boulder detection using openCV to see if our boulder made it into our intake. Here is the image of what the boulder looks like inside of our intake. (http://imgur.com/EFSf1I2)
Yes, I know I could just use a sensor like a distance sensor to see if there is a boulder there, but that is not a very fun and doesn't make use of our useless camera. Also, I made it a goal to become more proficient with vision programming and this seemed like good practice.
To go about doing this, I first tried the obvious "filter for the HSV", but that was too inconsistent and was wildly dependant on lighting since the boulders are quite shiny. Next, I tried edges, but that didn't work so well. I also tried HoughCircles which worked somewhat when there was a boulder present but went absolutely crazy when there wasn't one (http://imgur.com/a/tbYc3).
Here is the code I am currently using:
import cv2 as cv
import matplotlib.pyplot as plt
import numpy as np
vid = cv.VideoCapture("boulder.mov")
while True:
_, frame = vid.read()
img = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
edges = cv.Canny(img, 250, 350)
circles = cv.HoughCircles(edges,cv.HOUGH_GRADIENT,1,30,
param1=2,param2=30,minRadius=200,maxRadius=500)
try: #Just in case there isn't a circle
circles = np.uint16(np.around(circles))
for i in circles[0,:]:
cv.circle(img,(i[0],i[1]),i[2],(0,255,0),2)
cv.circle(img,(i[0],i[1]),2,(0,0,255),3)
except:
pass
cv.imshow('image', img)
k = cv.waitKey(5) & 0xFF
if k == 27:
break
vid.release()
cv.destroyAllWindows()
Because of the lack of a wide FOV from the camera, you cannot see the entire boulder at any time. I am just looking for suggestions on what to try in OpenCV. Any help would be greatly appreciated! Thanks!
On our Stronghold robot, we had a camera on a servo for looking around the field. The problem was that the camera was too low on the robot (Thanks, low bar...) and our shooter cims were blocking a good portion of the view. So thinking of things we could actually use the camera for, I came up with the idea o a basic boulder detection using openCV to see if our boulder made it into our intake. Here is the image of what the boulder looks like inside of our intake. (http://imgur.com/EFSf1I2)
Yes, I know I could just use a sensor like a distance sensor to see if there is a boulder there, but that is not a very fun and doesn't make use of our useless camera. Also, I made it a goal to become more proficient with vision programming and this seemed like good practice.
To go about doing this, I first tried the obvious "filter for the HSV", but that was too inconsistent and was wildly dependant on lighting since the boulders are quite shiny. Next, I tried edges, but that didn't work so well. I also tried HoughCircles which worked somewhat when there was a boulder present but went absolutely crazy when there wasn't one (http://imgur.com/a/tbYc3).
Here is the code I am currently using:
import cv2 as cv
import matplotlib.pyplot as plt
import numpy as np
vid = cv.VideoCapture("boulder.mov")
while True:
_, frame = vid.read()
img = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
edges = cv.Canny(img, 250, 350)
circles = cv.HoughCircles(edges,cv.HOUGH_GRADIENT,1,30,
param1=2,param2=30,minRadius=200,maxRadius=500)
try: #Just in case there isn't a circle
circles = np.uint16(np.around(circles))
for i in circles[0,:]:
cv.circle(img,(i[0],i[1]),i[2],(0,255,0),2)
cv.circle(img,(i[0],i[1]),2,(0,0,255),3)
except:
pass
cv.imshow('image', img)
k = cv.waitKey(5) & 0xFF
if k == 27:
break
vid.release()
cv.destroyAllWindows()
Because of the lack of a wide FOV from the camera, you cannot see the entire boulder at any time. I am just looking for suggestions on what to try in OpenCV. Any help would be greatly appreciated! Thanks!