Go to Post We are here to support each other. - Mike Martus [more]
Home
Go Back   Chief Delphi > Technical > Programming > Python
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 14-01-2017, 19:58
amstrudy amstrudy is offline
Registered User
AKA: Anja Sheppard
FRC #0900 (Zebracorns)
Team Role: Programmer
 
Join Date: Oct 2015
Rookie Year: 2014
Location: Chapel Hill, NC
Posts: 16
amstrudy is a splendid one to beholdamstrudy is a splendid one to beholdamstrudy is a splendid one to beholdamstrudy is a splendid one to beholdamstrudy is a splendid one to beholdamstrudy is a splendid one to beholdamstrudy is a splendid one to behold
Simple Gear Detection

Here is Team 900's very simple gear detection based off of color and area.



Code:
# basic gear detection from HSV
# 1/14/17
# Team 900 Zebracorns
# Author: Anja S

import cv2
import numpy as np

cap = cv2.VideoCapture(1)

kernel = np.ones((5,5),np.uint8)

while(1):

	# Take each frame
	_, frame = cap.read()

	hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)

	# Threshold the HSV image
	lower = np.array([20, 55, 124])
	upper = np.array([48, 255, 247])

	mask = cv2.inRange(hsv, lower, upper)

	opening = cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernel)
	closing = cv2.morphologyEx(opening, cv2.MORPH_CLOSE, kernel)

	# Contours
	contours = cv2.findContours(closing,cv2.cv.CV_RETR_TREE,cv2.cv.CV_CHAIN_APPROX_SIMPLE)[0]

	# Remove contours that don't fit area and HSV constraints

	gear_contour = []

	for c in contours:

		moments = cv2.moments(c)
		area = cv2.contourArea(c)

		if area < 3000: continue

		perim = cv2.arcLength(c, True)
		approx = cv2.approxPolyDP(c, 0.00005*perim, True)

		if len(approx) > 20:
			gear_contour.append(approx)

		for x in range(0, len(gear_contour)):

			minX = 10000
			minY = 10000
			maxX = 0
			maxY = 0
			cx = (minX + maxX)//2
			cy = (minY + maxY)//2

			# draw box around gear contour

			for y in range(0, len(gear_contour[x])):

				if gear_contour[x][y][0][0] < minX:
					minX = gear_contour[x][y][0][0]
				if gear_contour[x][y][0][1] < minY:
					minY = gear_contour[x][y][0][1]
				if gear_contour[x][y][0][0] > maxX:
					maxX = gear_contour[x][y][0][0]
				if gear_contour[x][y][0][1] > maxY:
					maxY = gear_contour[x][y][0][1]
			if gear_contour:

				cv2.drawContours(frame, gear_contour, -1, (255, 0, 0),3)
				cv2.rectangle(frame,(minX, minY),(maxX, maxY),(255,255,0),3)


	cv2.imshow('frame',frame)

	k = cv2.waitKey(5) & 0xFF
	if k == 27:
		break

cv2.destroyAllWindows()
Reply With Quote
  #2   Spotlight this post!  
Unread 14-01-2017, 20:14
Ari423's Avatar
Ari423 Ari423 is offline
LabVIEW aficionado and robot addict
AKA: The guy with the yellow hat
FRC #5987 (Galaxia)
Team Role: Mentor
 
Join Date: Mar 2015
Rookie Year: 2012
Location: Haifa, Israel
Posts: 658
Ari423 has much to be proud ofAri423 has much to be proud ofAri423 has much to be proud ofAri423 has much to be proud ofAri423 has much to be proud ofAri423 has much to be proud ofAri423 has much to be proud ofAri423 has much to be proud ofAri423 has much to be proud of
Re: Simple Gear Detection

I always love to see what you guys do with vision processing. Just wondering since it relies on area about how far away can the gear be before it's no longer big enough to be recognized? Also how close?
__________________
2017-present: Mentor FRC 5987
2017-present: CSA for FIRST in Israel
2012-2016: Member FRC 423
2013: Programmer
2014: Head Programmer, Wiring
2015: Head Programmer, Wiring
2016: Captain, Head Programmer, Wiring, Manipulator, Chassis, CAD, Business, Outreach (basically everything)


Reply With Quote
  #3   Spotlight this post!  
Unread 15-01-2017, 11:52
DonRotolo's Avatar
DonRotolo DonRotolo is offline
Back to humble
FRC #0832
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Atlanta GA
Posts: 7,019
DonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond repute
Re: Simple Gear Detection

Very nice, but can you expound on why one would wish to detect a gear?
__________________

I am N2IRZ - What's your callsign?
Reply With Quote
  #4   Spotlight this post!  
Unread 15-01-2017, 21:29
dirtbikerxz's Avatar
dirtbikerxz dirtbikerxz is offline
Captain | Driver | CAD | Junior
AKA: Rohit Gondi
FRC #3991 (KnightVision)
Team Role: Driver
 
Join Date: Nov 2014
Rookie Year: 2015
Location: Baton Rouge, LA
Posts: 493
dirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud ofdirtbikerxz has much to be proud of
Re: Simple Gear Detection

Quote:
Originally Posted by DonRotolo View Post
Very nice, but can you expound on why one would wish to detect a gear?
For catching gears that the human players throw across the field of course.
__________________

Team 3991: Driver since freshman (2015-), Captain since sophomore (2016-), CADer
"The human condition is not perfect. We are not perfect specimens, any of us. We're not robots." - Michael Ovitz
My posts may or may not reflect the views of my team, they are my opinions, and mine alone.
Reply With Quote
  #5   Spotlight this post!  
Unread 16-01-2017, 09:22
Billfred's Avatar
Billfred Billfred is online now
...and you can't! teach! that!
FRC #5402 (Iron Kings); no team (AndyMark)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: The Land of the Kokomese, IN
Posts: 8,563
Billfred has a reputation beyond reputeBillfred has a reputation beyond reputeBillfred has a reputation beyond reputeBillfred has a reputation beyond reputeBillfred has a reputation beyond reputeBillfred has a reputation beyond reputeBillfred has a reputation beyond reputeBillfred has a reputation beyond reputeBillfred has a reputation beyond reputeBillfred has a reputation beyond reputeBillfred has a reputation beyond repute
Re: Simple Gear Detection

Quote:
Originally Posted by DonRotolo View Post
Very nice, but can you expound on why one would wish to detect a gear?
So you can cheesecake an autonomous routine onto your partner to shimmy their preload gear out of their possession, and onto the floor for your 2-to-3-gear auto?
__________________
William "Billfred" Leverette - Gamecock/Jessica Boucher victim/Marketing & Sales Specialist at AndyMark

2004-2006: FRC 1293 (D5 Robotics) - Student, Mentor, Coach
2007-2009: FRC 1618 (Capital Robotics) - Mentor, Coach
2009-2013: FRC 2815 (Los Pollos Locos) - Mentor, Coach - Palmetto '09, Peachtree '11, Palmetto '11, Palmetto '12
2010: FRC 1398 (Keenan Robo-Raiders) - Mentor - Palmetto '10
2014-2016: FRC 4901 (Garnet Squadron) - Co-Founder and Head Bot Coach - Orlando '14, SCRIW '16
2017-: FRC 5402 (Iron Kings) - Mentor

94 events (more than will fit in a ChiefDelphi signature), 14 seasons, over 61,000 miles, and still on a mission from Bob.

Rule #1: Do not die. Rule #2: Be respectful. Rule #3: Be safe. Rule #4: Follow the handbook.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 11:25.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi