-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from illini-robomaster/dev
Vision v0.1.0 Release
- Loading branch information
Showing
28 changed files
with
4,880 additions
and
451 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: formatting_check | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: ["3.8", "3.9", "3.10"] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install pycodestyle | ||
pip install pydocstyle | ||
- name: Analysing the code with pycodestyle and pydocstyle | ||
run: | | ||
pycodestyle --max-line-length=100 --exclude="Camera/mvsdk.py" ./ | ||
pydocstyle --match='(?!test_)(?!mvsdk).*\.py' ./ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
"""Aggregate all distance estimators into one module.""" | ||
|
||
from .pnp_solver import pnp_estimator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
"""Simple distance solver using PnP.""" | ||
import numpy as np | ||
import cv2 | ||
import Utils | ||
|
||
|
||
class pnp_estimator: | ||
"""Distance estimator using PnP.""" | ||
|
||
def __init__(self, cfg): | ||
"""Initialize the PnP solver. | ||
Args: | ||
cfg (object): python config node object | ||
""" | ||
self.cfg = cfg | ||
self.K = Utils.get_intrinsic_matrix(self.cfg) | ||
|
||
# 3D armor board coordinates centered at armor board center | ||
# The unit is in mm (millimeter) | ||
self.armor_3d_pts = np.array([ | ||
[-65, -125 / 4, 0], # left top | ||
[-65, 125 / 4, 0], | ||
[65, -125 / 4, 0], | ||
[65, 125 / 4, 0] | ||
]).reshape((4, 3, 1)) | ||
|
||
def estimate_distance(self, armor, img_rgb): | ||
"""Estimate the distance to the armor. | ||
Args: | ||
armor (armor): selected armor object | ||
img_rgb (np.array): RGB image of the frame | ||
Returns: | ||
(y_dist, z_dist): distance along y-axis (pitch) and z-axis (distance from camera) | ||
""" | ||
obj_2d_pts = np.array([ | ||
armor.left_light.top.astype(int), | ||
armor.left_light.btm.astype(int), | ||
armor.right_light.top.astype(int), | ||
armor.right_light.btm.astype(int), | ||
]).reshape((4, 2, 1)) | ||
|
||
retval, rvec, tvec = cv2.solvePnP(self.armor_3d_pts.astype(float), | ||
obj_2d_pts.astype(float), | ||
self.K, | ||
distCoeffs=None) | ||
|
||
# rot_mat, _ = cv2.Rodrigues(rvec) | ||
abs_dist = np.sqrt(np.sum(tvec**2)) | ||
|
||
# return -tvec[1], tvec[2] | ||
return 0, abs_dist / 1000.0 |
Oops, something went wrong.