This repository has been archived by the owner on Sep 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5362f51
commit 6ca0fc2
Showing
6 changed files
with
96 additions
and
65 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -1,80 +1,105 @@ | ||
# FRC Robot Vision API | ||
The Robot Vision API allows FRC teams to specify some key parameters about the target they are looking for, and receive the location of the target in a given image. Developed through FRC Team 5112, The Gongoliers. | ||
|
||
![2019 Vision Example](2019-vision-example.jpg) | ||
|
||
## Installation | ||
Download the jar file from the [releases page](https://github.com/kylecorry31/Robot-Vision-API/releases) add it to your project. | ||
## Getting started | ||
|
||
### FRC 2019 (alpha - official support coming after kickoff) | ||
Move the jar to a libs folder in your project. In your `build.gradle` file, add the following line to the dependencies section: | ||
### Install | ||
To use the the Library of Gongolierium with Gradle projects, you can use [JitPack](https://jitpack.io/) by adding the following lines to your `build.gradle` file: | ||
|
||
`compile fileTree(dir: 'libs', include: '*.jar')` | ||
|
||
Here is an examples [build.gradle file](https://github.com/kylecorry31/FRC-Sample-Robot-2019/blob/master/build.gradle). | ||
|
||
|
||
### FRC 2018 and older | ||
Move the jar to a libs folder in your project. Add the libs folder to your `build.properties` file like so, at the end of the file: | ||
|
||
`userLibs = libs` | ||
|
||
Then add the jar to your build path in Eclipse. | ||
|
||
```Gradle | ||
repositories { | ||
... | ||
maven { url 'https://jitpack.io' } | ||
} | ||
dependencies { | ||
... | ||
compile 'com.github.kylecorry31:Robot-Vision-API:v1.1.0' | ||
} | ||
``` | ||
|
||
|
||
## Usage | ||
### Usage (FRC 2019 Vision Example) | ||
```Java | ||
/** | ||
* Detects the 2019 vision targets. | ||
* @param image The image from the camera. | ||
* @return The list of vision target groups. | ||
*/ | ||
public List<Target> detect2019Targets(Mat image){ | ||
// Adjust these parameters for your team's needs | ||
|
||
// Target filter parameters | ||
double minBrightness = 200; | ||
double maxBrightness = 255; | ||
|
||
// Contour filter parameters | ||
Range area = new Range(0.03, 100); | ||
Range fullness = new Range(0, 100); | ||
Range aspectRatio = new Range(0.2, 4); | ||
|
||
// Camera settings | ||
FOV fov = new FOV(50, 40); // This is the approx. Microsoft LifeCam FOV | ||
Resolution resolution = new Resolution(640, 480); | ||
boolean cameraInverted = false; | ||
|
||
int imageArea = resolution.getArea(); | ||
|
||
// An HSV filter may be better for FRC target detection | ||
TargetFilter filter = new BrightnessFilter(minBrightness, maxBrightness); | ||
ContourFilter contourFilter = new StandardContourFilter(area, fullness, aspectRatio, imageArea); | ||
CameraSettings cameraSettings = new CameraSettings(cameraInverted, fov, resolution); | ||
TargetFinder targetFinder = new TargetFinder(cameraSettings, filter, contourFilter, TargetGrouping.SINGLE); | ||
|
||
// Find the targets | ||
List<Target> targets = targetFinder.findTargets(image); | ||
|
||
// Sort the targets by x coordinates | ||
targets.sort(Comparator.comparingDouble(target -> target.getBoundary().center.x)); | ||
|
||
List<Target> bays = new ArrayList<>(); | ||
// If the current target is a left and the next is a right, make it a pair | ||
for (int i = 0; i < targets.size() - 1; i++) { | ||
Target current = targets.get(i); | ||
Target next = targets.get(i + 1); | ||
|
||
// Determine if the targets are a left and right pair | ||
if (isLeftTarget(current) && isRightTarget(next)){ | ||
// Combine the targets | ||
Target bay = TargetUtils.combineTargets(current, next, cameraSettings); | ||
bays.add(bay); | ||
// Skip the next target | ||
i++; | ||
} | ||
} | ||
|
||
return bays; | ||
} | ||
|
||
// This image will come from the camera using WPILib | ||
Mat image = ...; | ||
|
||
// Fill in with your own parameters | ||
double minBrightness = 200; | ||
double maxBrightness = 255; | ||
|
||
Range area = new Range(0.03, 100); | ||
Range fullness = new Range(0, 100); | ||
Range aspectRatio = new Range(0, 100); | ||
|
||
FOV fov = new FOV(60, 60); | ||
Resolution resolution = new Resolution(640, 480); | ||
boolean cameraInverted = false; | ||
|
||
int imageArea = resolution.getArea(); | ||
|
||
|
||
|
||
// An HSV filter may be better for FRC target detection | ||
TargetFilter filter = new BrightnessFilter(minBrightness, maxBrightness); | ||
ContourFilter contourFilter = new StandardContourFilter(area, fullness, aspectRatio, imageArea); | ||
CameraSettings cameraSettings = new CameraSettings(cameraInverted, fov, resolution); | ||
TargetFinder targetFinder = new TargetFinder(cameraSettings, filter, contourFilter, TargetGrouping.SINGLE); | ||
|
||
// Get the image from the camera using WPILib | ||
List<Target> targets = targetFinder.findTargets(image); | ||
|
||
/** | ||
* Determines if a target is a left vision target. | ||
* @param target The target. | ||
* @return True if it is a left target. | ||
*/ | ||
private boolean isLeftTarget(Target target){ | ||
return target.getSkew() < 0; | ||
} | ||
|
||
// Draw the targets on the image | ||
for(Target target: targets){ | ||
// Get the bounding box of the target as a rotated rectangle | ||
RotatedRect boundary = target.getBoundary(); | ||
|
||
// Convert the rotated rect to a contour list (OpenCV stuff to draw the rectangle) | ||
Point[] points = new Point[4]; | ||
boundary.points(points); | ||
MatOfPoint contour = new MatOfPoint(points); | ||
List<MatOfPoint> contours = Arrays.asList(contour); | ||
|
||
// Draw it on the image | ||
Imgproc.drawContours(image, contours, 0, new Scalar(0, 255, 0)); | ||
Imgproc.drawMarker(image, target.getBoundary().center, new Scalar(255, 0, 0)); | ||
/** | ||
* Determines if a target is a right vision target. | ||
* @param target The target. | ||
* @return True if it is a right target. | ||
*/ | ||
private boolean isRightTarget(Target target){ | ||
return target.getSkew() > 0; | ||
} | ||
|
||
``` | ||
|
||
## Contributing | ||
Please fork this repo and submit a pull request to contribute. I will review all changes and respond if they are accepted or rejected (as well as reasons, so it will be accepted). | ||
|
||
## License | ||
This project is published under the [GPL-3.0 license](LICENSE). | ||
|
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
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