Updated code in ball_tracking.py for tennis ball -- not sure if it's the code from the other laptop though?

This commit is contained in:
MatthewTaylor24
2018-02-25 16:34:30 -08:00
parent 4aabad55b0
commit e9597be876
2 changed files with 15 additions and 10 deletions

View File

@@ -14,7 +14,7 @@
<file leaf-file-name="gate_navi.py" pinned="false" current-in-tab="false"> <file leaf-file-name="gate_navi.py" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/gate_navi.py"> <entry file="file://$PROJECT_DIR$/gate_navi.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="306"> <state relative-caret-position="162">
<caret line="22" column="5" lean-forward="true" selection-start-line="22" selection-start-column="5" selection-end-line="22" selection-end-column="5" /> <caret line="22" column="5" lean-forward="true" selection-start-line="22" selection-start-column="5" selection-end-line="22" selection-end-column="5" />
<folding> <folding>
<element signature="e#0#10#0" expanded="true" /> <element signature="e#0#10#0" expanded="true" />
@@ -26,8 +26,8 @@
<file leaf-file-name="ball_tracking.py" pinned="false" current-in-tab="true"> <file leaf-file-name="ball_tracking.py" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/ball_tracking.py"> <entry file="file://$PROJECT_DIR$/ball_tracking.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="234"> <state relative-caret-position="264">
<caret line="20" column="26" lean-forward="true" selection-start-line="20" selection-start-column="26" selection-end-line="20" selection-end-column="26" /> <caret line="20" column="51" lean-forward="true" selection-start-line="20" selection-start-column="51" selection-end-line="20" selection-end-column="51" />
<folding> <folding>
<element signature="e#127#156#0" expanded="true" /> <element signature="e#127#156#0" expanded="true" />
</folding> </folding>
@@ -205,7 +205,7 @@
<component name="editorHistoryManager"> <component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/gate_navi.py"> <entry file="file://$PROJECT_DIR$/gate_navi.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="306"> <state relative-caret-position="162">
<caret line="22" column="5" lean-forward="true" selection-start-line="22" selection-start-column="5" selection-end-line="22" selection-end-column="5" /> <caret line="22" column="5" lean-forward="true" selection-start-line="22" selection-start-column="5" selection-end-line="22" selection-end-column="5" />
<folding> <folding>
<element signature="e#0#10#0" expanded="true" /> <element signature="e#0#10#0" expanded="true" />
@@ -215,8 +215,8 @@
</entry> </entry>
<entry file="file://$PROJECT_DIR$/ball_tracking.py"> <entry file="file://$PROJECT_DIR$/ball_tracking.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="234"> <state relative-caret-position="264">
<caret line="20" column="26" lean-forward="true" selection-start-line="20" selection-start-column="26" selection-end-line="20" selection-end-column="26" /> <caret line="20" column="51" lean-forward="true" selection-start-line="20" selection-start-column="51" selection-end-line="20" selection-end-column="51" />
<folding> <folding>
<element signature="e#127#156#0" expanded="true" /> <element signature="e#127#156#0" expanded="true" />
</folding> </folding>

View File

@@ -18,14 +18,16 @@ args = vars(ap.parse_args())
# define the lower and upper boundaries of the "green" # define the lower and upper boundaries of the "green"
# ball in the HSV color space, then initialize the # ball in the HSV color space, then initialize the
# list of tracked points # list of tracked points
greenLower = (50, 112, 50) greenLower = np.array((40, 100, 50), dtype="uint8")
greenUpper = (144, 255, 145) greenUpper = np.array((64, 255, 255), dtype="uint8")
# lower_yellow = np.array([30, 255, 135], dtype=np.uint8)
# upper_yellow = np.array([40, 255, 185], dtype=np.uint8)
pts = deque(maxlen=args["buffer"]) pts = deque(maxlen=args["buffer"])
# if a video path was not supplied, grab the reference # if a video path was not supplied, grab the reference
# to the webcam # to the webcam
if not args.get("video", False): if not args.get("video", False):
camera = cv2.VideoCapture(1) camera = cv2.VideoCapture(0)
# otherwise, grab a reference to the video file # otherwise, grab a reference to the video file
else: else:
@@ -51,6 +53,7 @@ while True:
# a series of dilations and erosions to remove any small # a series of dilations and erosions to remove any small
# blobs left in the mask # blobs left in the mask
mask = cv2.inRange(hsv, greenLower, greenUpper) mask = cv2.inRange(hsv, greenLower, greenUpper)
# mask = cv2.inRange(hsv, lower_yellow, upper_yellow)
mask = cv2.erode(mask, None, iterations=2) mask = cv2.erode(mask, None, iterations=2)
mask = cv2.dilate(mask, None, iterations=2) mask = cv2.dilate(mask, None, iterations=2)
@@ -69,8 +72,10 @@ while True:
M = cv2.moments(c) M = cv2.moments(c)
center = (int(M["m10"] / M["m00"]), int(M["m01"] / M["m00"])) center = (int(M["m10"] / M["m00"]), int(M["m01"] / M["m00"]))
area = M['m00']
# only proceed if the radius meets a minimum size # only proceed if the radius meets a minimum size
if radius > 1: if area > 100:
# draw the circle and centroid on the frame, # draw the circle and centroid on the frame,
# then update the list of tracked points # then update the list of tracked points
cv2.circle(frame, (int(x), int(y)), int(radius), (0, 255, 255), 2) cv2.circle(frame, (int(x), int(y)), int(radius), (0, 255, 255), 2)