Run yapf on all python files in the repo
Signed-off-by: Ravago Jones <ravagojones@gmail.com>
Change-Id: I221e04c3f517fab8535b22551553799e0fee7a80
diff --git a/y2020/control_loops/python/accelerator.py b/y2020/control_loops/python/accelerator.py
index bb6871c..54ec9d3 100644
--- a/y2020/control_loops/python/accelerator.py
+++ b/y2020/control_loops/python/accelerator.py
@@ -20,20 +20,19 @@
# Gear ratio to the final wheel.
G = (30.0 / 40.0) * numpy.power(G_per_wheel, 3.0)
# Overall flywheel inertia.
-J = J_wheel * (
- 1.0 + numpy.power(G_per_wheel, -2.0) + numpy.power(G_per_wheel, -4.0) + numpy.power(G_per_wheel, -6.0))
+J = J_wheel * (1.0 + numpy.power(G_per_wheel, -2.0) +
+ numpy.power(G_per_wheel, -4.0) + numpy.power(G_per_wheel, -6.0))
# The position and velocity are measured for the final wheel.
-kAccelerator = flywheel.FlywheelParams(
- name='Accelerator',
- motor=control_loop.Falcon(),
- G=G,
- J=J * 1.3,
- q_pos=0.01,
- q_vel=40.0,
- q_voltage=1.0,
- r_pos=0.03,
- controller_poles=[.89])
+kAccelerator = flywheel.FlywheelParams(name='Accelerator',
+ motor=control_loop.Falcon(),
+ G=G,
+ J=J * 1.3,
+ q_pos=0.01,
+ q_vel=40.0,
+ q_voltage=1.0,
+ r_pos=0.03,
+ controller_poles=[.89])
def main(argv):
diff --git a/y2020/control_loops/python/control_panel.py b/y2020/control_loops/python/control_panel.py
index 7a5bdf9..6bda841 100644
--- a/y2020/control_loops/python/control_panel.py
+++ b/y2020/control_loops/python/control_panel.py
@@ -17,17 +17,16 @@
except gflags.DuplicateFlagError:
pass
-kControlPanel = angular_system.AngularSystemParams(
- name='ControlPanel',
- motor=control_loop.BAG(),
- G=1.0,
- J=0.000009,
- q_pos=0.20,
- q_vel=5.0,
- kalman_q_pos=0.12,
- kalman_q_vel=2.0,
- kalman_q_voltage=4.0,
- kalman_r_position=0.05)
+kControlPanel = angular_system.AngularSystemParams(name='ControlPanel',
+ motor=control_loop.BAG(),
+ G=1.0,
+ J=0.000009,
+ q_pos=0.20,
+ q_vel=5.0,
+ kalman_q_pos=0.12,
+ kalman_q_vel=2.0,
+ kalman_q_voltage=4.0,
+ kalman_r_position=0.05)
def main(argv):
@@ -42,7 +41,9 @@
'Expected .h file name and .cc file name for the control_panel and integral control_panel.'
)
else:
- namespaces = ['y2020', 'control_loops', 'superstructure', 'control_panel']
+ namespaces = [
+ 'y2020', 'control_loops', 'superstructure', 'control_panel'
+ ]
angular_system.WriteAngularSystem(kControlPanel, argv[1:3], argv[3:5],
namespaces)
diff --git a/y2020/control_loops/python/finisher.py b/y2020/control_loops/python/finisher.py
index 8c33cc3..7e703fc 100644
--- a/y2020/control_loops/python/finisher.py
+++ b/y2020/control_loops/python/finisher.py
@@ -22,14 +22,17 @@
J = 0.00507464
J = 0.0035
+
def AddResistance(motor, resistance):
motor.resistance += resistance
return motor
+
def ScaleKv(motor, scale):
motor.Kv *= scale
return motor
+
# The position and velocity are measured for the final wheel.
kFinisher = flywheel.FlywheelParams(
name='Finisher',
diff --git a/y2020/control_loops/python/flywheel.py b/y2020/control_loops/python/flywheel.py
index 6f41a17..9153bc6 100755
--- a/y2020/control_loops/python/flywheel.py
+++ b/y2020/control_loops/python/flywheel.py
@@ -7,6 +7,7 @@
class FlywheelParams(object):
+
def __init__(self,
name,
motor,
@@ -31,6 +32,7 @@
class VelocityFlywheel(control_loop.HybridControlLoop):
+
def __init__(self, params, name="Flywheel"):
super(VelocityFlywheel, self).__init__(name=name)
self.params = params
@@ -76,6 +78,7 @@
class Flywheel(VelocityFlywheel):
+
def __init__(self, params, name="Flywheel"):
super(Flywheel, self).__init__(params, name=name)
@@ -112,6 +115,7 @@
class IntegralFlywheel(Flywheel):
+
def __init__(self, params, name="IntegralFlywheel"):
super(IntegralFlywheel, self).__init__(params, name=name)
@@ -125,7 +129,6 @@
self.B_continuous = numpy.matrix(numpy.zeros((3, 1)))
self.B_continuous[0:2, 0] = self.B_continuous_unaugmented
-
# states
# [position, velocity, voltage_error]
self.C_unaugmented = self.C
@@ -146,24 +149,26 @@
q_vel = self.params.q_vel
q_voltage = self.params.q_voltage
self.Q_continuous = numpy.matrix([[(q_pos**2.0), 0.0, 0.0],
- [0.0, (q_vel**2.0), 0.0],
- [0.0, 0.0, (q_voltage**2.0)]])
+ [0.0, (q_vel**2.0), 0.0],
+ [0.0, 0.0, (q_voltage**2.0)]])
r_pos = self.params.r_pos
self.R_continuous = numpy.matrix([[(r_pos**2.0)]])
- _, _, self.Q, self.R = controls.kalmd(
- A_continuous=self.A_continuous,
- B_continuous=self.B_continuous,
- Q_continuous=self.Q_continuous,
- R_continuous=self.R_continuous,
- dt=self.dt)
+ _, _, self.Q, self.R = controls.kalmd(A_continuous=self.A_continuous,
+ B_continuous=self.B_continuous,
+ Q_continuous=self.Q_continuous,
+ R_continuous=self.R_continuous,
+ dt=self.dt)
glog.debug('Q_discrete %s' % (str(self.Q)))
glog.debug('R_discrete %s' % (str(self.R)))
- self.KalmanGain, self.P_steady_state = controls.kalman(
- A=self.A, B=self.B, C=self.C, Q=self.Q, R=self.R)
+ self.KalmanGain, self.P_steady_state = controls.kalman(A=self.A,
+ B=self.B,
+ C=self.C,
+ Q=self.Q,
+ R=self.R)
self.L = self.A * self.KalmanGain
self.K_unaugmented = self.K
@@ -283,34 +288,32 @@
for index, param in enumerate(params):
flywheels.append(Flywheel(param, name=param.name + str(index)))
integral_flywheels.append(
- IntegralFlywheel(
- param, name='Integral' + param.name + str(index)))
+ IntegralFlywheel(param,
+ name='Integral' + param.name + str(index)))
else:
name = params.name
flywheels.append(Flywheel(params, params.name))
integral_flywheels.append(
IntegralFlywheel(params, name='Integral' + params.name))
- loop_writer = control_loop.ControlLoopWriter(
- name, flywheels, namespaces=namespace)
+ loop_writer = control_loop.ControlLoopWriter(name,
+ flywheels,
+ namespaces=namespace)
loop_writer.AddConstant(
- control_loop.Constant('kOutputRatio', '%f',
- flywheels[0].G))
+ control_loop.Constant('kOutputRatio', '%f', flywheels[0].G))
loop_writer.AddConstant(
control_loop.Constant('kFreeSpeed', '%f',
flywheels[0].motor.free_speed))
loop_writer.AddConstant(
- control_loop.Constant(
- 'kBemf',
- '%f',
- flywheels[0].motor.Kv * flywheels[0].G,
- comment="// Radians/sec / volt"))
+ control_loop.Constant('kBemf',
+ '%f',
+ flywheels[0].motor.Kv * flywheels[0].G,
+ comment="// Radians/sec / volt"))
loop_writer.AddConstant(
- control_loop.Constant(
- 'kResistance',
- '%f',
- flywheels[0].motor.resistance,
- comment="// Ohms"))
+ control_loop.Constant('kResistance',
+ '%f',
+ flywheels[0].motor.resistance,
+ comment="// Ohms"))
loop_writer.Write(plant_files[0], plant_files[1])
integral_loop_writer = control_loop.ControlLoopWriter(
diff --git a/y2020/control_loops/python/hood.py b/y2020/control_loops/python/hood.py
index eacb7fd..8125f8b 100644
--- a/y2020/control_loops/python/hood.py
+++ b/y2020/control_loops/python/hood.py
@@ -29,17 +29,17 @@
radians_per_turn_of_motor = 12.0 / 60.0 * radians_per_turn
-kHood = angular_system.AngularSystemParams(
- name='Hood',
- motor=control_loop.BAG(),
- G=radians_per_turn_of_motor / (2.0 * numpy.pi),
- J=0.1,
- q_pos=0.15,
- q_vel=10.0,
- kalman_q_pos=0.12,
- kalman_q_vel=10.0,
- kalman_q_voltage=30.0,
- kalman_r_position=0.02)
+kHood = angular_system.AngularSystemParams(name='Hood',
+ motor=control_loop.BAG(),
+ G=radians_per_turn_of_motor /
+ (2.0 * numpy.pi),
+ J=0.1,
+ q_pos=0.15,
+ q_vel=10.0,
+ kalman_q_pos=0.12,
+ kalman_q_vel=10.0,
+ kalman_q_voltage=30.0,
+ kalman_r_position=0.02)
def main(argv):
diff --git a/y2020/control_loops/python/intake.py b/y2020/control_loops/python/intake.py
index 1035070..87896dd 100644
--- a/y2020/control_loops/python/intake.py
+++ b/y2020/control_loops/python/intake.py
@@ -17,17 +17,17 @@
except gflags.DuplicateFlagError:
pass
-kIntake = angular_system.AngularSystemParams(
- name='Intake',
- motor=control_loop.BAG(),
- G=(12.0 / 24.0) * (1.0 / 5.0) * (1.0 / 5.0) * (16.0 / 32.0),
- J=8 * 0.139 * 0.139,
- q_pos=0.40,
- q_vel=20.0,
- kalman_q_pos=0.12,
- kalman_q_vel=2.0,
- kalman_q_voltage=4.0,
- kalman_r_position=0.05)
+kIntake = angular_system.AngularSystemParams(name='Intake',
+ motor=control_loop.BAG(),
+ G=(12.0 / 24.0) * (1.0 / 5.0) *
+ (1.0 / 5.0) * (16.0 / 32.0),
+ J=8 * 0.139 * 0.139,
+ q_pos=0.40,
+ q_vel=20.0,
+ kalman_q_pos=0.12,
+ kalman_q_vel=2.0,
+ kalman_q_voltage=4.0,
+ kalman_r_position=0.05)
def main(argv):
diff --git a/y2020/control_loops/python/polydrivetrain.py b/y2020/control_loops/python/polydrivetrain.py
index dad06b0..dbd5268 100644
--- a/y2020/control_loops/python/polydrivetrain.py
+++ b/y2020/control_loops/python/polydrivetrain.py
@@ -12,20 +12,22 @@
FLAGS = gflags.FLAGS
try:
- gflags.DEFINE_bool('plot', False, 'If true, plot the loop response.')
+ gflags.DEFINE_bool('plot', False, 'If true, plot the loop response.')
except gflags.DuplicateFlagError:
- pass
+ pass
+
def main(argv):
- if FLAGS.plot:
- polydrivetrain.PlotPolyDrivetrainMotions(drivetrain.kDrivetrain)
- elif len(argv) != 7:
- glog.fatal('Expected .h file name and .cc file name')
- else:
- polydrivetrain.WritePolyDrivetrain(argv[1:3], argv[3:5], argv[5:7], 'y2020',
- drivetrain.kDrivetrain)
+ if FLAGS.plot:
+ polydrivetrain.PlotPolyDrivetrainMotions(drivetrain.kDrivetrain)
+ elif len(argv) != 7:
+ glog.fatal('Expected .h file name and .cc file name')
+ else:
+ polydrivetrain.WritePolyDrivetrain(argv[1:3], argv[3:5], argv[5:7],
+ 'y2020', drivetrain.kDrivetrain)
+
if __name__ == '__main__':
- argv = FLAGS(sys.argv)
- glog.init()
- sys.exit(main(argv))
+ argv = FLAGS(sys.argv)
+ glog.init()
+ sys.exit(main(argv))
diff --git a/y2020/control_loops/python/turret.py b/y2020/control_loops/python/turret.py
index 6f15057..5f77f84 100644
--- a/y2020/control_loops/python/turret.py
+++ b/y2020/control_loops/python/turret.py
@@ -18,17 +18,18 @@
except gflags.DuplicateFlagError:
pass
-kTurret = angular_system.AngularSystemParams(
- name='Turret',
- motor=control_loop.MiniCIM(),
- G=(26.0 / 150.0) * (14.0 / 60.0) * (20.0 / 60.0),
- J=0.20,
- q_pos=0.30,
- q_vel=4.5,
- kalman_q_pos=0.12,
- kalman_q_vel=10.0,
- kalman_q_voltage=20.0,
- kalman_r_position=0.05)
+kTurret = angular_system.AngularSystemParams(name='Turret',
+ motor=control_loop.MiniCIM(),
+ G=(26.0 / 150.0) * (14.0 / 60.0) *
+ (20.0 / 60.0),
+ J=0.20,
+ q_pos=0.30,
+ q_vel=4.5,
+ kalman_q_pos=0.12,
+ kalman_q_vel=10.0,
+ kalman_q_voltage=20.0,
+ kalman_r_position=0.05)
+
def main(argv):
if FLAGS.plot:
@@ -38,13 +39,11 @@
# Write the generated constants out to a file.
if len(argv) != 5:
- glog.fatal(
- 'Expected .h file name and .cc file name for the turret.'
- )
+ glog.fatal('Expected .h file name and .cc file name for the turret.')
else:
namespaces = ['y2020', 'control_loops', 'superstructure', 'turret']
- angular_system.WriteAngularSystem([kTurret],
- argv[1:3], argv[3:5], namespaces)
+ angular_system.WriteAngularSystem([kTurret], argv[1:3], argv[3:5],
+ namespaces)
if __name__ == '__main__':
diff --git a/y2020/vision/galactic_search_config.py b/y2020/vision/galactic_search_config.py
index 90988e3..870e039 100755
--- a/y2020/vision/galactic_search_config.py
+++ b/y2020/vision/galactic_search_config.py
@@ -20,7 +20,7 @@
import os
import sys
-_num_rects = 3 # can be 3 or 2, can be specified in commang line arg
+_num_rects = 3 # can be 3 or 2, can be specified in commang line arg
_path = Path(Letter.kA, Alliance.kRed, [Rect(None, None, None, None)])
@@ -29,20 +29,24 @@
_fig, _img_ax = plt.subplots()
-_txt = _img_ax.text(0, 0, "", size = 10, backgroundcolor = "white")
+_txt = _img_ax.text(0, 0, "", size=10, backgroundcolor="white")
_confirm = Button(plt.axes([0.7, 0.05, 0.1, 0.075]), "Confirm")
_cancel = Button(plt.axes([0.81, 0.05, 0.1, 0.075]), "Cancel")
_submit = Button(plt.axes([0.4, 0.05, 0.1, 0.1]), "Submit")
+
def draw_txt(txt):
- txt.set_text("Click on top left point and bottom right point for rect #%u" % (_rect_index + 1))
+ txt.set_text(
+ "Click on top left point and bottom right point for rect #%u" %
+ (_rect_index + 1))
txt.set_color(_path.alliance.value)
def on_confirm(event):
global _rect_index
- if _path.rects[_rect_index].x1 != None and _path.rects[_rect_index].x2 != None:
+ if _path.rects[_rect_index].x1 != None and _path.rects[
+ _rect_index].x2 != None:
_confirm.ax.set_visible(False)
_cancel.ax.set_visible(False)
_rect_index += 1
@@ -54,6 +58,7 @@
_path.rects.append(Rect(None, None, None, None))
plt.show()
+
def on_cancel(event):
global _rect_index
if _rect_index < _num_rects:
@@ -66,6 +71,7 @@
_path.rects[_rect_index].y2 = None
plt.show()
+
def on_submit(event):
plt.close("all")
dict = None
@@ -74,9 +80,12 @@
dict[_path.letter.name] = {}
if _path.alliance.name not in dict[_path.letter.name]:
dict[_path.letter.name][_path.alliance.name] = []
- dict[_path.letter.name][_path.alliance.name] = [rect.to_list() for rect in _path.rects]
+ dict[_path.letter.name][_path.alliance.name] = [
+ rect.to_list() for rect in _path.rects
+ ]
with open(RECTS_JSON_PATH, 'w') as rects_json:
- json.dump(dict, rects_json, indent = 2)
+ json.dump(dict, rects_json, indent=2)
+
# Clears rect on screen
def clear_rect():
@@ -85,6 +94,7 @@
else:
_img_ax.patches[-1].remove()
+
def on_click(event):
# This gets called for each click of the rectangle corners,
# but also gets called when the user clicks on the Submit button.
@@ -94,9 +104,11 @@
# the bounds of the axis
if _rect_index < _num_rects and event.xdata != None and event.ydata != None:
if _path.rects[_rect_index].x1 == None:
- _path.rects[_rect_index].x1, _path.rects[_rect_index].y1 = int(event.xdata), int(event.ydata)
+ _path.rects[_rect_index].x1, _path.rects[_rect_index].y1 = int(
+ event.xdata), int(event.ydata)
elif _path.rects[_rect_index].x2 == None:
- _path.rects[_rect_index].x2, _path.rects[_rect_index].y2 = int(event.xdata), int(event.ydata)
+ _path.rects[_rect_index].x2, _path.rects[_rect_index].y2 = int(
+ event.xdata), int(event.ydata)
if _path.rects[_rect_index].x2 < _path.rects[_rect_index].x1:
tmp = _path.rects[_rect_index].x1
_path.rects[_rect_index].x1 = _path.rects[_rect_index].x2
@@ -106,20 +118,27 @@
_path.rects[_rect_index].y1 = _path.rects[_rect_index].y2
_path.rects[_rect_index].y2 = tmp
- _img_ax.add_patch(patches.Rectangle((_path.rects[_rect_index].x1, _path.rects[_rect_index].y1),
- _path.rects[_rect_index].x2 - _path.rects[_rect_index].x1,
- _path.rects[_rect_index].y2 - _path.rects[_rect_index].y1,
- edgecolor = 'r', linewidth = 1, facecolor="none"))
+ _img_ax.add_patch(
+ patches.Rectangle(
+ (_path.rects[_rect_index].x1, _path.rects[_rect_index].y1),
+ _path.rects[_rect_index].x2 - _path.rects[_rect_index].x1,
+ _path.rects[_rect_index].y2 - _path.rects[_rect_index].y1,
+ edgecolor='r',
+ linewidth=1,
+ facecolor="none"))
_confirm.ax.set_visible(True)
_cancel.ax.set_visible(True)
plt.show()
else:
- glog.info("Either submitted or user pressed out of the bounds of the axis")
+ glog.info(
+ "Either submitted or user pressed out of the bounds of the axis")
+
def setup_button(button, on_clicked):
button.on_clicked(on_clicked)
button.ax.set_visible(False)
+
def setup_ui():
_img_ax.imshow(capture_img())
release_stream()
@@ -131,11 +150,12 @@
draw_txt(_txt)
plt.show()
+
def view_rects():
rects_dict = load_json()
- if (_path.letter.name in rects_dict and
- _path.alliance.name in rects_dict[_path.letter.name]):
+ if (_path.letter.name in rects_dict
+ and _path.alliance.name in rects_dict[_path.letter.name]):
_confirm.ax.set_visible(False)
_cancel.ax.set_visible(False)
_submit.ax.set_visible(False)
@@ -143,20 +163,26 @@
for rect_list in rects_dict[_path.letter.name][_path.alliance.name]:
rect = Rect.from_list(rect_list)
- _img_ax.add_patch(patches.Rectangle((rect.x1, rect.y1),
- rect.x2 - rect.x1, rect.y2 - rect.y1,
- edgecolor = 'r', linewidth = 1, facecolor="none"))
+ _img_ax.add_patch(
+ patches.Rectangle((rect.x1, rect.y1),
+ rect.x2 - rect.x1,
+ rect.y2 - rect.y1,
+ edgecolor='r',
+ linewidth=1,
+ facecolor="none"))
plt.show()
else:
glog.error("Could not find path %s %s in rects.json",
- _path.alliance.value, _path.letter.value)
+ _path.alliance.value, _path.letter.value)
+
def main(argv):
global _num_rects
glog.setLevel("INFO")
- opts = getopt.getopt(argv[1 : ], "a:l:n:",
- ["alliance = ", "letter = ", "_num_rects = ", "view"])[0]
+ opts = getopt.getopt(
+ argv[1:], "a:l:n:",
+ ["alliance = ", "letter = ", "_num_rects = ", "view"])[0]
view = False
for opt, arg in opts:
if opt in ["-a", "--alliance"]:
diff --git a/y2020/vision/galactic_search_path.py b/y2020/vision/galactic_search_path.py
index 00b572a..11ec73d 100755
--- a/y2020/vision/galactic_search_path.py
+++ b/y2020/vision/galactic_search_path.py
@@ -8,6 +8,7 @@
import numpy as np
import os
+
class Rect:
# x1 and y1 are top left corner, x2 and y2 are bottom right
@@ -41,11 +42,14 @@
@staticmethod
def from_value(value):
- return (Alliance.kRed if value == Alliance.kRed.value else Alliance.kBlue)
+ return (Alliance.kRed
+ if value == Alliance.kRed.value else Alliance.kBlue)
@staticmethod
def from_name(name):
- return (Alliance.kRed if name == Alliance.kRed.name else Alliance.kBlue)
+ return (Alliance.kRed
+ if name == Alliance.kRed.name else Alliance.kBlue)
+
class Letter(Enum):
kA = 'A'
@@ -59,6 +63,7 @@
def from_name(name):
return (Letter.kA if name == Letter.kA.name else Letter.kB)
+
class Path:
def __init__(self, letter, alliance, rects):
@@ -72,15 +77,18 @@
def to_dict(self):
return {"alliance": self.alliance.name, "letter": self.letter.name}
+
RECTS_JSON_PATH = "rects.json"
AOS_SEND_PATH = "bazel-bin/aos/aos_send"
+
def setup_if_pi():
if os.path.isdir("/home/pi/bin"):
AOS_SEND_PATH = "/home/pi/bin/aos_send.stripped"
os.system("./starter_cmd stop camera_reader")
+
setup_if_pi()
# The minimum percentage of yellow for a region of a image to
@@ -89,12 +97,14 @@
_paths = []
+
def load_json():
rects_dict = None
with open(RECTS_JSON_PATH, 'r') as rects_json:
rects_dict = json.load(rects_json)
return rects_dict
+
def _run_detection_loop():
global img_fig, rects_dict
@@ -104,7 +114,9 @@
rects = []
for rect_list in rects_dict[letter][alliance]:
rects.append(Rect.from_list(rect_list))
- _paths.append(Path(Letter.from_name(letter), Alliance.from_name(alliance), rects))
+ _paths.append(
+ Path(Letter.from_name(letter), Alliance.from_name(alliance),
+ rects))
plt.ion()
img_fig = plt.figure()
@@ -113,6 +125,7 @@
while running:
_detect_path()
+
def _detect_path():
img = capture_img()
img_fig.figimage(img)
@@ -138,7 +151,8 @@
current_path = path
num_current_paths += 1
else:
- glog.error("Error: len of pcts (%u) != len of rects: (%u)", len(pcts), len(rects))
+ glog.error("Error: len of pcts (%u) != len of rects: (%u)",
+ len(pcts), len(rects))
if num_current_paths != 1:
if num_current_paths == 0:
@@ -147,24 +161,27 @@
glog.warn("Expected 1 path but detected %u", num_current_paths)
return
-
path_dict = current_path.to_dict()
glog.info("Path is %s", path_dict)
os.system(AOS_SEND_PATH +
- " /pi2/camera y2020.vision.GalacticSearchPath '" + json.dumps(path_dict) + "'")
+ " /pi2/camera y2020.vision.GalacticSearchPath '" +
+ json.dumps(path_dict) + "'")
+
KERNEL = np.ones((5, 5), np.uint8)
+
def _create_mask(img):
hsv = cv.cvtColor(img, cv.COLOR_BGR2HSV)
- lower_yellow = np.array([23, 100, 75], dtype = np.uint8)
- higher_yellow = np.array([40, 255, 255], dtype = np.uint8)
+ lower_yellow = np.array([23, 100, 75], dtype=np.uint8)
+ higher_yellow = np.array([40, 255, 255], dtype=np.uint8)
mask = cv.inRange(hsv, lower_yellow, higher_yellow)
- mask = cv.erode(mask, KERNEL, iterations = 1)
- mask = cv.dilate(mask, KERNEL, iterations = 3)
+ mask = cv.erode(mask, KERNEL, iterations=1)
+ mask = cv.dilate(mask, KERNEL, iterations=3)
return mask
+
# This function finds the percentage of yellow pixels in the rectangles
# given that are regions of the given image. This allows us to determine
# whether there is a ball in those rectangles
@@ -172,25 +189,30 @@
pcts = np.zeros(len(rects))
for i in range(len(rects)):
rect = rects[i]
- slice = mask[rect.y1 : rect.y2, rect.x1 : rect.x2]
+ slice = mask[rect.y1:rect.y2, rect.x1:rect.x2]
yellow_px = np.count_nonzero(slice)
pcts[i] = yellow_px / (slice.shape[0] * slice.shape[1])
return pcts
+
_video_stream = cv.VideoCapture(0)
+
def capture_img():
global _video_stream
return _video_stream.read()[1]
+
def release_stream():
global _video_stream
_video_stream.release()
+
def main():
_run_detection_loop()
release_stream()
+
if __name__ == "__main__":
main()
diff --git a/y2020/vision/sift/demo_sift_training.py b/y2020/vision/sift/demo_sift_training.py
index 67874c9..4e9c306 100644
--- a/y2020/vision/sift/demo_sift_training.py
+++ b/y2020/vision/sift/demo_sift_training.py
@@ -8,87 +8,89 @@
import frc971.vision.sift.TrainingData as TrainingData
import frc971.vision.sift.Feature as Feature
+
def main():
- image4_cleaned_path = sys.argv[1]
- output_path = sys.argv[2]
+ image4_cleaned_path = sys.argv[1]
+ output_path = sys.argv[2]
- image4_cleaned = cv2.imread(image4_cleaned_path)
+ image4_cleaned = cv2.imread(image4_cleaned_path)
- image = cv2.cvtColor(image4_cleaned, cv2.COLOR_BGR2GRAY)
- image = cv2.resize(image, (640, 480))
- sift = cv2.SIFT_create()
- keypoints, descriptors = sift.detectAndCompute(image, None)
+ image = cv2.cvtColor(image4_cleaned, cv2.COLOR_BGR2GRAY)
+ image = cv2.resize(image, (640, 480))
+ sift = cv2.SIFT_create()
+ keypoints, descriptors = sift.detectAndCompute(image, None)
- fbb = flatbuffers.Builder(0)
+ fbb = flatbuffers.Builder(0)
- features_vector = []
+ features_vector = []
- for keypoint, descriptor in zip(keypoints, descriptors):
- Feature.FeatureStartDescriptorVector(fbb, len(descriptor))
- for n in reversed(descriptor):
- assert n == round(n)
- fbb.PrependUint8(int(round(n)))
- descriptor_vector = fbb.EndVector()
+ for keypoint, descriptor in zip(keypoints, descriptors):
+ Feature.FeatureStartDescriptorVector(fbb, len(descriptor))
+ for n in reversed(descriptor):
+ assert n == round(n)
+ fbb.PrependUint8(int(round(n)))
+ descriptor_vector = fbb.EndVector()
- Feature.FeatureStart(fbb)
+ Feature.FeatureStart(fbb)
- Feature.FeatureAddDescriptor(fbb, descriptor_vector)
- Feature.FeatureAddX(fbb, keypoint.pt[0])
- Feature.FeatureAddY(fbb, keypoint.pt[1])
- Feature.FeatureAddSize(fbb, keypoint.size)
- Feature.FeatureAddAngle(fbb, keypoint.angle)
- Feature.FeatureAddResponse(fbb, keypoint.response)
- Feature.FeatureAddOctave(fbb, keypoint.octave)
+ Feature.FeatureAddDescriptor(fbb, descriptor_vector)
+ Feature.FeatureAddX(fbb, keypoint.pt[0])
+ Feature.FeatureAddY(fbb, keypoint.pt[1])
+ Feature.FeatureAddSize(fbb, keypoint.size)
+ Feature.FeatureAddAngle(fbb, keypoint.angle)
+ Feature.FeatureAddResponse(fbb, keypoint.response)
+ Feature.FeatureAddOctave(fbb, keypoint.octave)
- features_vector.append(Feature.FeatureEnd(fbb))
+ features_vector.append(Feature.FeatureEnd(fbb))
- TrainingImage.TrainingImageStartFeaturesVector(fbb, len(features_vector))
- for feature in reversed(features_vector):
- fbb.PrependUOffsetTRelative(feature)
- features_vector_table = fbb.EndVector()
+ TrainingImage.TrainingImageStartFeaturesVector(fbb, len(features_vector))
+ for feature in reversed(features_vector):
+ fbb.PrependUOffsetTRelative(feature)
+ features_vector_table = fbb.EndVector()
- TrainingImage.TrainingImageStart(fbb)
- TrainingImage.TrainingImageAddFeatures(fbb, features_vector_table)
- # TODO(Brian): Fill out the transformation matrices.
- training_image_offset = TrainingImage.TrainingImageEnd(fbb)
+ TrainingImage.TrainingImageStart(fbb)
+ TrainingImage.TrainingImageAddFeatures(fbb, features_vector_table)
+ # TODO(Brian): Fill out the transformation matrices.
+ training_image_offset = TrainingImage.TrainingImageEnd(fbb)
- TrainingData.TrainingDataStartImagesVector(fbb, 1)
- fbb.PrependUOffsetTRelative(training_image_offset)
- images_offset = fbb.EndVector()
+ TrainingData.TrainingDataStartImagesVector(fbb, 1)
+ fbb.PrependUOffsetTRelative(training_image_offset)
+ images_offset = fbb.EndVector()
- TrainingData.TrainingDataStart(fbb)
- TrainingData.TrainingDataAddImages(fbb, images_offset)
- fbb.Finish(TrainingData.TrainingDataEnd(fbb))
+ TrainingData.TrainingDataStart(fbb)
+ TrainingData.TrainingDataAddImages(fbb, images_offset)
+ fbb.Finish(TrainingData.TrainingDataEnd(fbb))
- bfbs = fbb.Output()
+ bfbs = fbb.Output()
- output_prefix = [
- b'#ifndef Y2020_VISION_SIFT_DEMO_SIFT_H_',
- b'#define Y2020_VISION_SIFT_DEMO_SIFT_H_',
- b'#include <string_view>',
- b'namespace frc971 {',
- b'namespace vision {',
- b'inline std::string_view DemoSiftData() {',
- ]
- output_suffix = [
- b' return std::string_view(kData, sizeof(kData));',
- b'}',
- b'} // namespace vision',
- b'} // namespace frc971',
- b'#endif // Y2020_VISION_SIFT_DEMO_SIFT_H_',
- ]
+ output_prefix = [
+ b'#ifndef Y2020_VISION_SIFT_DEMO_SIFT_H_',
+ b'#define Y2020_VISION_SIFT_DEMO_SIFT_H_',
+ b'#include <string_view>',
+ b'namespace frc971 {',
+ b'namespace vision {',
+ b'inline std::string_view DemoSiftData() {',
+ ]
+ output_suffix = [
+ b' return std::string_view(kData, sizeof(kData));',
+ b'}',
+ b'} // namespace vision',
+ b'} // namespace frc971',
+ b'#endif // Y2020_VISION_SIFT_DEMO_SIFT_H_',
+ ]
- with open(output_path, 'wb') as output:
- for line in output_prefix:
- output.write(line)
- output.write(b'\n')
- output.write(b'alignas(64) static constexpr char kData[] = "')
- for byte in fbb.Output():
- output.write(b'\\x' + (b'%x' % byte).zfill(2))
- output.write(b'";\n')
- for line in output_suffix:
- output.write(line)
- output.write(b'\n')
+ with open(output_path, 'wb') as output:
+ for line in output_prefix:
+ output.write(line)
+ output.write(b'\n')
+ output.write(b'alignas(64) static constexpr char kData[] = "')
+ for byte in fbb.Output():
+ output.write(b'\\x' + (b'%x' % byte).zfill(2))
+ output.write(b'";\n')
+ for line in output_suffix:
+ output.write(line)
+ output.write(b'\n')
+
if __name__ == '__main__':
- main()
+ main()
diff --git a/y2020/vision/sift/fast_gaussian_runner.py b/y2020/vision/sift/fast_gaussian_runner.py
index d812f3f..9767300 100755
--- a/y2020/vision/sift/fast_gaussian_runner.py
+++ b/y2020/vision/sift/fast_gaussian_runner.py
@@ -8,190 +8,211 @@
from bazel_tools.tools.python.runfiles import runfiles
+
def main(params):
- r = runfiles.Create()
- generator = r.Rlocation('org_frc971/y2020/vision/sift/fast_gaussian_generator')
+ r = runfiles.Create()
+ generator = r.Rlocation(
+ 'org_frc971/y2020/vision/sift/fast_gaussian_generator')
- ruledir = sys.argv[2]
- target_cpu = sys.argv[3]
+ ruledir = sys.argv[2]
+ target_cpu = sys.argv[3]
- target = {
- 'aarch64': 'arm-64-linux-no_asserts',
- 'armv7': 'arm-32-linux-no_asserts',
- 'k8': 'x86-64-linux-no_asserts',
- }[target_cpu]
+ target = {
+ 'aarch64': 'arm-64-linux-no_asserts',
+ 'armv7': 'arm-32-linux-no_asserts',
+ 'k8': 'x86-64-linux-no_asserts',
+ }[target_cpu]
- commands = []
+ commands = []
- amd64_debian_sysroot = r.Rlocation('amd64_debian_sysroot/usr/lib/x86_64-linux-gnu/libc.so.6').rsplit('/', 4)[0]
- env = os.environ.copy()
- env['LD_LIBRARY_PATH'] = ':'.join([
- # TODO(brian): Figure this out again. It is a bit aggressive.
- #amd64_debian_sysroot + '/lib/x86_64-linux-gnu',
- #amd64_debian_sysroot + '/lib',
- #amd64_debian_sysroot + '/usr/lib/x86_64-linux-gnu',
- #amd64_debian_sysroot + '/usr/lib',
- ])
+ amd64_debian_sysroot = r.Rlocation(
+ 'amd64_debian_sysroot/usr/lib/x86_64-linux-gnu/libc.so.6').rsplit(
+ '/', 4)[0]
+ env = os.environ.copy()
+ env['LD_LIBRARY_PATH'] = ':'.join([
+ # TODO(brian): Figure this out again. It is a bit aggressive.
+ #amd64_debian_sysroot + '/lib/x86_64-linux-gnu',
+ #amd64_debian_sysroot + '/lib',
+ #amd64_debian_sysroot + '/usr/lib/x86_64-linux-gnu',
+ #amd64_debian_sysroot + '/usr/lib',
+ ])
- all_header = [
- '#ifndef Y2020_VISION_SIFT_FAST_GAUSSIAN_ALL_H_',
- '#define Y2020_VISION_SIFT_FAST_GAUSSIAN_ALL_H_',
- '#include "HalideBuffer.h"',
- ]
+ all_header = [
+ '#ifndef Y2020_VISION_SIFT_FAST_GAUSSIAN_ALL_H_',
+ '#define Y2020_VISION_SIFT_FAST_GAUSSIAN_ALL_H_',
+ '#include "HalideBuffer.h"',
+ ]
- for cols, rows in params['sizes']:
- for sigma, sigma_name, filter_width in params['sigmas']:
- name = "fast_gaussian_%dx%d_%s" % (cols, rows, sigma_name)
+ for cols, rows in params['sizes']:
+ for sigma, sigma_name, filter_width in params['sigmas']:
+ name = "fast_gaussian_%dx%d_%s" % (cols, rows, sigma_name)
- commands.append([
- generator,
- '-g', 'gaussian_generator',
- '-o', ruledir,
- '-f', name,
- '-e', 'o,h,html',
- 'target=%s-no_runtime' % target,
- 'cols=%s' % cols,
- 'rows=%s' % rows,
- 'sigma=%s' % sigma,
- 'filter_width=%s' % filter_width,
- ])
- all_header += [
- '#include "y2020/vision/sift/%s.h"' % name,
- ]
+ commands.append([
+ generator,
+ '-g',
+ 'gaussian_generator',
+ '-o',
+ ruledir,
+ '-f',
+ name,
+ '-e',
+ 'o,h,html',
+ 'target=%s-no_runtime' % target,
+ 'cols=%s' % cols,
+ 'rows=%s' % rows,
+ 'sigma=%s' % sigma,
+ 'filter_width=%s' % filter_width,
+ ])
+ all_header += [
+ '#include "y2020/vision/sift/%s.h"' % name,
+ ]
- name = "fast_gaussian_subtract_%dx%d_%s" % (cols, rows, sigma_name)
+ name = "fast_gaussian_subtract_%dx%d_%s" % (cols, rows, sigma_name)
- commands.append([
- generator,
- '-g', 'gaussian_and_subtract_generator',
- '-o', ruledir,
- '-f', name,
- '-e', 'o,h,html',
- 'target=%s-no_runtime' % target,
- 'cols=%s' % cols,
- 'rows=%s' % rows,
- 'sigma=%s' % sigma,
- 'filter_width=%s' % filter_width,
- ])
- all_header += [
- '#include "y2020/vision/sift/%s.h"' % name,
- ]
+ commands.append([
+ generator,
+ '-g',
+ 'gaussian_and_subtract_generator',
+ '-o',
+ ruledir,
+ '-f',
+ name,
+ '-e',
+ 'o,h,html',
+ 'target=%s-no_runtime' % target,
+ 'cols=%s' % cols,
+ 'rows=%s' % rows,
+ 'sigma=%s' % sigma,
+ 'filter_width=%s' % filter_width,
+ ])
+ all_header += [
+ '#include "y2020/vision/sift/%s.h"' % name,
+ ]
- name = 'fast_subtract_%dx%d' % (cols, rows)
+ name = 'fast_subtract_%dx%d' % (cols, rows)
+ commands.append([
+ generator,
+ '-g',
+ 'subtract_generator',
+ '-o',
+ ruledir,
+ '-f',
+ name,
+ '-e',
+ 'o,h,html',
+ 'target=%s-no_runtime' % target,
+ 'cols=%s' % cols,
+ 'rows=%s' % rows,
+ ])
+ all_header += [
+ '#include "y2020/vision/sift/%s.h"' % name,
+ ]
commands.append([
generator,
- '-g', 'subtract_generator',
- '-o', ruledir,
- '-f', name,
- '-e', 'o,h,html',
- 'target=%s-no_runtime' % target,
- 'cols=%s' % cols,
- 'rows=%s' % rows,
+ '-r',
+ 'fast_gaussian_runtime',
+ '-o',
+ ruledir,
+ '-e',
+ 'o',
+ 'target=%s' % target,
])
+
all_header += [
- '#include "y2020/vision/sift/%s.h"' % name,
+ 'namespace frc971 {',
+ 'namespace vision {',
+ '// 0 is success. 1 is non-implemented size. Negative is a Halide error.',
+ 'inline int DoGeneratedFastGaussian(',
+ ' Halide::Runtime::Buffer<const int16_t, 2> input,',
+ ' Halide::Runtime::Buffer<int16_t, 2> output,',
+ ' double sigma) {',
]
- commands.append([
- generator,
- '-r', 'fast_gaussian_runtime',
- '-o', ruledir,
- '-e', 'o',
- 'target=%s' % target,
- ])
- all_header += [
- 'namespace frc971 {',
- 'namespace vision {',
- '// 0 is success. 1 is non-implemented size. Negative is a Halide error.',
- 'inline int DoGeneratedFastGaussian(',
- ' Halide::Runtime::Buffer<const int16_t, 2> input,',
- ' Halide::Runtime::Buffer<int16_t, 2> output,',
- ' double sigma) {',
- ]
+ for sigma, sigma_name, filter_width in params['sigmas']:
+ for cols, rows in params['sizes']:
+ name = "fast_gaussian_%dx%d_%s" % (cols, rows, sigma_name)
+ all_header += [
+ ' if (input.dim(0).extent() == %s' % cols,
+ ' && input.dim(1).extent() == %s' % rows,
+ ' && sigma == %s) {' % sigma,
+ ' return %s(input, output);' % name,
+ ' }',
+ ]
- for sigma, sigma_name, filter_width in params['sigmas']:
- for cols, rows in params['sizes']:
- name = "fast_gaussian_%dx%d_%s" % (cols, rows, sigma_name)
- all_header += [
- ' if (input.dim(0).extent() == %s' % cols,
- ' && input.dim(1).extent() == %s' % rows,
- ' && sigma == %s) {' % sigma,
- ' return %s(input, output);' % name,
- ' }',
- ]
-
- all_header += [
- ' return 1;',
- '}',
- 'inline int DoGeneratedFastGaussianAndSubtract(',
- ' Halide::Runtime::Buffer<const int16_t, 2> input,',
- ' Halide::Runtime::Buffer<int16_t, 2> blurred,',
- ' Halide::Runtime::Buffer<int16_t, 2> difference,',
- ' double sigma) {',
- ]
-
- for sigma, sigma_name, filter_width in params['sigmas']:
- for cols, rows in params['sizes']:
- name = "fast_gaussian_subtract_%dx%d_%s" % (cols, rows, sigma_name)
- all_header += [
- ' if (input.dim(0).extent() == %s' % cols,
- ' && input.dim(1).extent() == %s' % rows,
- ' && sigma == %s) {' % sigma,
- ' return %s(input, blurred, difference);' % name,
- ' }',
- ]
-
- all_header += [
- ' return 1;',
- '}',
- 'inline int DoGeneratedFastSubtract('
- ' Halide::Runtime::Buffer<const int16_t, 2> input_a,',
- ' Halide::Runtime::Buffer<const int16_t, 2> input_b,',
- ' Halide::Runtime::Buffer<int16_t, 2> output) {',
- ]
- for cols, rows in params['sizes']:
- name = 'fast_subtract_%dx%d' % (cols, rows)
all_header += [
- ' if (input_a.dim(0).extent() == %s' % cols,
- ' && input_a.dim(1).extent() == %s) {' % rows,
- ' return %s(input_a, input_b, output);' % name,
- ' }',
+ ' return 1;',
+ '}',
+ 'inline int DoGeneratedFastGaussianAndSubtract(',
+ ' Halide::Runtime::Buffer<const int16_t, 2> input,',
+ ' Halide::Runtime::Buffer<int16_t, 2> blurred,',
+ ' Halide::Runtime::Buffer<int16_t, 2> difference,',
+ ' double sigma) {',
]
- all_header += [
- ' return 1;',
- '}',
- '} // namespace vision',
- '} // namespace frc971',
- '#endif // Y2020_VISION_SIFT_FAST_GAUSSIAN_ALL_H_',
- ]
- with open(os.path.join(ruledir, 'fast_gaussian_all.h'), 'w') as f:
- f.writelines([line + '\n' for line in all_header])
+ for sigma, sigma_name, filter_width in params['sigmas']:
+ for cols, rows in params['sizes']:
+ name = "fast_gaussian_subtract_%dx%d_%s" % (cols, rows, sigma_name)
+ all_header += [
+ ' if (input.dim(0).extent() == %s' % cols,
+ ' && input.dim(1).extent() == %s' % rows,
+ ' && sigma == %s) {' % sigma,
+ ' return %s(input, blurred, difference);' % name,
+ ' }',
+ ]
- commands_lock = threading.Lock()
- success = [True]
+ all_header += [
+ ' return 1;',
+ '}',
+ 'inline int DoGeneratedFastSubtract('
+ ' Halide::Runtime::Buffer<const int16_t, 2> input_a,',
+ ' Halide::Runtime::Buffer<const int16_t, 2> input_b,',
+ ' Halide::Runtime::Buffer<int16_t, 2> output) {',
+ ]
+ for cols, rows in params['sizes']:
+ name = 'fast_subtract_%dx%d' % (cols, rows)
+ all_header += [
+ ' if (input_a.dim(0).extent() == %s' % cols,
+ ' && input_a.dim(1).extent() == %s) {' % rows,
+ ' return %s(input_a, input_b, output);' % name,
+ ' }',
+ ]
+ all_header += [
+ ' return 1;',
+ '}',
+ '} // namespace vision',
+ '} // namespace frc971',
+ '#endif // Y2020_VISION_SIFT_FAST_GAUSSIAN_ALL_H_',
+ ]
- def run_commands():
- while True:
- with commands_lock:
- if not commands:
- return
- if not success[0]:
- return
- command = commands.pop()
- try:
- subprocess.check_call(command, env=env)
- except:
- with commands_lock:
- success[0] = False
- raise
- threads = [threading.Thread(target=run_commands) for _ in range(4)]
- for thread in threads:
- thread.start()
- for thread in threads:
- thread.join()
- if not success[0]:
- sys.exit(1)
+ with open(os.path.join(ruledir, 'fast_gaussian_all.h'), 'w') as f:
+ f.writelines([line + '\n' for line in all_header])
+
+ commands_lock = threading.Lock()
+ success = [True]
+
+ def run_commands():
+ while True:
+ with commands_lock:
+ if not commands:
+ return
+ if not success[0]:
+ return
+ command = commands.pop()
+ try:
+ subprocess.check_call(command, env=env)
+ except:
+ with commands_lock:
+ success[0] = False
+ raise
+
+ threads = [threading.Thread(target=run_commands) for _ in range(4)]
+ for thread in threads:
+ thread.start()
+ for thread in threads:
+ thread.join()
+ if not success[0]:
+ sys.exit(1)
+
if __name__ == '__main__':
- main(json.loads(sys.argv[1]))
+ main(json.loads(sys.argv[1]))
diff --git a/y2020/vision/tools/python_code/calibrate_intrinsics.py b/y2020/vision/tools/python_code/calibrate_intrinsics.py
index fb95599..46c275c 100644
--- a/y2020/vision/tools/python_code/calibrate_intrinsics.py
+++ b/y2020/vision/tools/python_code/calibrate_intrinsics.py
@@ -10,6 +10,7 @@
# From: https://pynative.com/python-serialize-numpy-ndarray-into-json/
class NumpyArrayEncoder(json.JSONEncoder):
+
def default(self, obj):
if isinstance(obj, np.integer):
return int(obj)
@@ -24,8 +25,8 @@
def get_robot_info(hostname):
hostname_split = hostname.split("-")
if hostname_split[0] != "pi":
- print(
- "ERROR: expected hostname to start with pi! Got '%s'" % hostname)
+ print("ERROR: expected hostname to start with pi! Got '%s'" %
+ hostname)
quit()
team_number = int(hostname_split[1])
diff --git a/y2020/vision/tools/python_code/camera_definition.py b/y2020/vision/tools/python_code/camera_definition.py
index 3e3623d..50e3ea4 100644
--- a/y2020/vision/tools/python_code/camera_definition.py
+++ b/y2020/vision/tools/python_code/camera_definition.py
@@ -11,6 +11,7 @@
class CameraIntrinsics:
+
def __init__(self):
self.camera_matrix = []
self.dist_coeffs = []
@@ -19,12 +20,14 @@
class CameraExtrinsics:
+
def __init__(self):
self.R = []
self.T = []
class CameraParameters:
+
def __init__(self):
self.camera_int = CameraIntrinsics()
self.camera_ext = CameraExtrinsics()
diff --git a/y2020/vision/tools/python_code/define_training_data.py b/y2020/vision/tools/python_code/define_training_data.py
index 76e73da..0435f95 100644
--- a/y2020/vision/tools/python_code/define_training_data.py
+++ b/y2020/vision/tools/python_code/define_training_data.py
@@ -28,8 +28,10 @@
image = cv2.circle(image, (point[0], point[1]), 5, (255, 0, 0), -1)
if (len(polygon) > 1):
np_poly = np.array(polygon)
- image = cv2.polylines(
- image, [np_poly], close_polygon, color, thickness=3)
+ image = cv2.polylines(image, [np_poly],
+ close_polygon,
+ color,
+ thickness=3)
return image
@@ -249,7 +251,8 @@
try:
from bazel_tools.tools.python.runfiles import runfiles
r = runfiles.Create()
- ret_name = r.Rlocation('org_frc971/y2020/vision/tools/python_code/' + filename)
+ ret_name = r.Rlocation('org_frc971/y2020/vision/tools/python_code/' +
+ filename)
except:
pass
diff --git a/y2020/vision/tools/python_code/target_definition.py b/y2020/vision/tools/python_code/target_definition.py
index 0266997..a3aea4c 100644
--- a/y2020/vision/tools/python_code/target_definition.py
+++ b/y2020/vision/tools/python_code/target_definition.py
@@ -22,6 +22,7 @@
class TargetData:
+
def __init__(self, filename=None):
if filename:
self.image_filename = dtd.bazel_name_fix(filename)
diff --git a/y2020/vision/tools/python_code/transform_projection_test.py b/y2020/vision/tools/python_code/transform_projection_test.py
index 01fe695..166b5ec 100644
--- a/y2020/vision/tools/python_code/transform_projection_test.py
+++ b/y2020/vision/tools/python_code/transform_projection_test.py
@@ -23,10 +23,12 @@
# Create fake set of points relative to camera capture (target) frame
# at +/- 1 meter in x, 5 meter depth, and every 1 meter in y from 0 to 4m (above the camera, so negative y values)
-pts_3d_target = np.array(
- [[-1., 0., depth], [1., 0., depth], [-1., -1., depth], [1., -1., depth],
- [-1., -2., depth], [0., -2., depth], [1., -2., depth], [-1., -3., depth],
- [1., -3., depth], [-1., -4., depth], [1., -4., depth]])
+pts_3d_target = np.array([[-1., 0., depth], [1., 0., depth], [-1., -1., depth],
+ [1., -1., depth], [-1., -2.,
+ depth], [0., -2., depth],
+ [1., -2., depth], [-1., -3.,
+ depth], [1., -3., depth],
+ [-1., -4., depth], [1., -4., depth]])
# Ground truth shift of camera from (cam) to (cam2), to compute projections
R_cam_cam2_gt = np.array([[0., 0.2, 0.2]]).T
@@ -46,9 +48,10 @@
#pts_proj_3d = cam_mat.dot(pts_3d_target_shifted.T).T
#pts_proj_2d = np.divide(pts_proj_3d[:,0:2],(pts_proj_3d[:,2].reshape(-1,1)))
-pts_proj_2d_cam2, jac_2d = cv2.projectPoints(
- pts_3d_target, R_cam_cam2_gt_mat_inv, T_cam_cam2_gt_inv, cam_mat,
- dist_coeffs)
+pts_proj_2d_cam2, jac_2d = cv2.projectPoints(pts_3d_target,
+ R_cam_cam2_gt_mat_inv,
+ T_cam_cam2_gt_inv, cam_mat,
+ dist_coeffs)
# Now, solve for the pose using the original 3d points (pts_3d_T_t) and the projections from the new location
retval, R_cam2_cam_est, T_cam2_cam_est, inliers = cv2.solvePnPRansac(