Skip to content
This repository has been archived by the owner on Jun 19, 2020. It is now read-only.

Commit

Permalink
fixed sending empty arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Feb 28, 2020
1 parent 33534b0 commit 31f97ec
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 35 deletions.
4 changes: 2 additions & 2 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# when using static ip for robot
#config.networktables_server_ip = '10.26.1.11'

config.video_source_number = 1
config.long_video_source_number = 0
config.video_source_number = 0
config.long_video_source_number = 1
config.networktables_table = 'SmartDashboard'

config.gstreamer_bitrate = '3500000'
Expand Down
22 changes: 12 additions & 10 deletions processing/port_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,18 @@ def process(img, camera, frame_cnt, color_profile):

FRAME_WIDTH = camera.FRAME_WIDTH
FRAME_HEIGHT = camera.FRAME_HEIGHT

hue = color_profile.hsv_hue
sat = color_profile.hsv_sat
val = color_profile.hsv_val

tracking_data = []
original_img = img

img = cv2.GaussianBlur(img, (13, 13), 0)
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
hsv_mask = cvfilters.hsv_threshold(img, color_profile)
img = cv2.bitwise_and(img, img, hsv_mask)
img = cv2.erode(img, None, iterations=2)
img = cv2.dilate(img, None, iterations=2)
hsv = cv2.cvtColor(img, cv2.COLOR_RGB2HSV)
mask = cv2.inRange(hsv, (hue.min, sat.min, val.min), (hue.max, sat.max, val.max))
img = cvfilters.apply_mask(img, mask)
# img = cv2.erode(img, None, iterations=2)
# img = cv2.dilate(img, None, iterations=2)
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# if debug:
Expand All @@ -68,14 +70,14 @@ def process(img, camera, frame_cnt, color_profile):
center_mass_x = x + w / 2
center_mass_y = y + h / 2
#
if shape_util.dimensions_match(contour, 6,2, WIDTH_TO_HEIGHT_RATIO):
if shape_util.dimensions_match(contour, 6,1, WIDTH_TO_HEIGHT_RATIO):
# print 'x:%s, y:%s angle:%s ' % ( center_mass_x, center_mass_y, angle )
distance = shape_util.distance_in_inches(w)
distance = shape_util.ge:(w)
angle = shape_util.get_angle(camera, center_mass_x, center_mass_y)
font = cv2.FONT_HERSHEY_DUPLEX

# set tracking_data
data = dict(shape='BAY',
data = dict(shape='PORT',
width=w,
height=h,
dist=distance,
Expand Down
9 changes: 7 additions & 2 deletions processing/shape_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ def dimensions_match(contour, vertices, range, desired_ratio):
temp = w
w = h
h = temp
MIN_RATIO = desired_ratio * 0.5
MAX_RATIO = desired_ratio * 1.50
MIN_RATIO = desired_ratio * 0.80
MAX_RATIO = desired_ratio * 1.2
#MIN_RATIO = desired_ratio * 0.6
#MAX_RATIO = desired_ratio * 1.4

ar = w / float(h)
# print(ar)
Expand Down Expand Up @@ -54,3 +56,6 @@ def get_distance(width_pixel, width_actual, focal_length):

def distance_in_inches(width_pixel):
return 762 * (width_pixel ** -0.8)

def distance_in_inches_long(width_pixel):
return 34618 * (width_pixel ** -1.06)
22 changes: 11 additions & 11 deletions profiles/color_profile_BALL.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@
"camera_mode": "BALL",
"rgb": {
"r": {
"min": "107",
"max": "152"
"min": "82",
"max": "124"
},
"b": {
"min": "21",
"max": "78"
"min": 0,
"max": "60"
},
"g": {
"min": "118",
"max": 156
"min": "60",
"max": "152"
}
},
"hsv": {
"h": {
"min": 0,
"max": 37
"max": 41
},
"s": {
"min": 155,
"max": 210
"min": 103,
"max": 197
},
"v": {
"min": 108,
"max": 152
"min": "34",
"max": 148
}
},
"hsl": {
Expand Down
10 changes: 5 additions & 5 deletions profiles/color_profile_BAY.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
},
"hsv": {
"h": {
"min": "28",
"max": "199"
"min": "59",
"max": "83"
},
"s": {
"min": "80",
"max": "255"
"min": 42,
"max": 255
},
"v": {
"min": "165",
"min": 137,
"max": 255
}
},
Expand Down
45 changes: 45 additions & 0 deletions profiles/color_profile_HEXAGON.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"camera_mode": "HEXAGON",
"rgb": {
"r": {
"min": 0,
"max": 255
},
"b": {
"min": 0,
"max": 255
},
"g": {
"min": 0,
"max": 255
}
},
"hsv": {
"h": {
"min": "52",
"max": "77"
},
"s": {
"min": "46",
"max": "172"
},
"v": {
"min": "49",
"max": "243"
}
},
"hsl": {
"h": {
"min": 0,
"max": 255
},
"s": {
"min": 0,
"max": 255
},
"l": {
"min": 0,
"max": 255
}
}
}
1 change: 0 additions & 1 deletion web/tornado_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def start():
color_profiles=color_profile_map
)

# ImagePushStreamHandler.start(application=app)

# Start the app
logger.info("Listening on http://localhost:%s/", config.tornado_server_port)
Expand Down
12 changes: 8 additions & 4 deletions web/www/tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function draw(targets) {
var octx = offscreenCanvas.getContext("2d");
octx.fillStyle = "#0095DD";
targets.forEach(function(target){
console.log(target.shape);
if(target.shape == 'BALL'){
octx.beginPath();
octx.arc(target.xpos, target.ypos, target.radius, 0, Math.PI*2);
Expand All @@ -44,15 +45,18 @@ function draw(targets) {
octx.fillRect(target.xpos,target.ypos, target.width, target.width * 11/7);
}
if(target.shape =='PORT'){
x = target.xpos;
y = target.ypos;
size = target.width;
var x = target.xpos;
var y = target.ypos;
var size = target.width;

octx.strokeStyle = "#0095DD";
octx.beginPath();
octx.moveTo(x + size * Math.cos(0), y + size * Math.sin(0));
for (var side; side < 7; side++) {
for (var side = 0; side < 7; side++) {
octx.lineTo(x + size * Math.cos(side * 2 * Math.PI / 6), y + size * Math.sin(side * 2 * Math.PI / 6));
}
octx.fill();
octx.closePath();
}
})
ctx.clearRect(0, 0, canvas.width, canvas.height);
Expand Down

0 comments on commit 31f97ec

Please sign in to comment.