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">
<entry file="file://$PROJECT_DIR$/gate_navi.py">
<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" />
<folding>
<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">
<entry file="file://$PROJECT_DIR$/ball_tracking.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="234">
<caret line="20" column="26" lean-forward="true" selection-start-line="20" selection-start-column="26" selection-end-line="20" selection-end-column="26" />
<state relative-caret-position="264">
<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>
<element signature="e#127#156#0" expanded="true" />
</folding>
@@ -205,7 +205,7 @@
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/gate_navi.py">
<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" />
<folding>
<element signature="e#0#10#0" expanded="true" />
@@ -215,8 +215,8 @@
</entry>
<entry file="file://$PROJECT_DIR$/ball_tracking.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="234">
<caret line="20" column="26" lean-forward="true" selection-start-line="20" selection-start-column="26" selection-end-line="20" selection-end-column="26" />
<state relative-caret-position="264">
<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>
<element signature="e#127#156#0" expanded="true" />
</folding>

View File

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