Skip to content
This repository has been archived by the owner on Sep 9, 2019. It is now read-only.

Commit

Permalink
Auto merge of #45 - lasarobotics:dev, r=smo-key
Browse files Browse the repository at this point in the history
Release 0.8.1

- Code cleanup and refactoring, as well as readme updates
  • Loading branch information
homu committed Nov 25, 2015
2 parents e042fe6 + 30c4fa4 commit 385e580
Show file tree
Hide file tree
Showing 46 changed files with 1,202 additions and 1,337 deletions.
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
![FTC Vision](https://raw.githubusercontent.com/lasarobotics/ftcvision/dev/img/logo-github.png)
<p align="center">
<img src="https://raw.githubusercontent.com/lasarobotics/ftcvision/img/logo.png?raw=true" alt="FTC-Sees!"/>
</p>

# FTC Vision Library [![Build Status](https://travis-ci.org/lasarobotics/FTCVision.svg?branch=staging)](https://travis-ci.org/lasarobotics/FTCVision)
# FTC Vision Library [![Build Status](https://travis-ci.org/lasarobotics/FTCVision.svg?branch=master)](https://travis-ci.org/lasarobotics/FTCVision)
Computer Vision library for FTC based on OpenCV, featuring **beacon color and position detection**, as well as an easy-to-use `VisionOpMode` format and many additional detection features planned in the future.

## Installing from Scratch
Expand Down Expand Up @@ -30,13 +32,19 @@ include ':ftc-visionlib'
compile project(':ftc-visionlib')
compile project(':opencv-java')
```
- Copy in Vision opmodes (those that end in `VisionSample.java`) from the FTCVision directory into your opmode directory.
- Update Gradle configuration by pressing the green "Sync Project with Gradle Files" button in the header (this may take a minute)
- Copy in Vision opmodes (those that end in `VisionSample.java`, located in `[vision-root]/ftc-robotcontroller/src/main/java/com/qualcomm/ftcrobotcontroller/opmodes`) from the FTCVision directory into your opmode directory.
- Run and test the code! Let us know if you encounter any difficulties.
- You can now write your custom `VisionOpMode`!

## Status
This library is currently under insanely active development. We're in the **Beta** phase right now. If you have any questions or would like to help, send a note to `smo-key` (contact info on profile). Thank you!

![A test from 8 feet away](https://raw.githubusercontent.com/lasarobotics/ftcvision/dev/img/test3.png)
#### Accuracy Test
![A test from 8 feet away](https://raw.githubusercontent.com/lasarobotics/ftcvision/img/test2.png)

#### Distance Test
![A test from 8 feet away](https://raw.githubusercontent.com/lasarobotics/ftcvision/img/test1.png)

## Goals
- Locate the lit target (the thing with two buttons) within the camera viewfield
Expand Down
46 changes: 28 additions & 18 deletions ftc-cameratest/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,38 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.lasarobotics.tests.camera"
android:versionCode="301"
android:versionName="3.01">
xmlns:tools="http://schemas.android.com/tools"
package="com.lasarobotics.tests.camera"
android:versionCode="301"
android:versionName="3.01">

<application
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
tools:replace="android:theme">

<activity android:name="com.lasarobotics.tests.camera.CameraTestActivity"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:configChanges="keyboardHidden|orientation">
<activity
android:name="com.lasarobotics.tests.camera.CameraTestActivity"
android:configChanges="keyboardHidden|orientation"
android:label="@string/app_name"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

<supports-screens android:resizeable="true"
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:anyDensity="true" />
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:resizeable="true"
android:smallScreens="true" />

<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<uses-feature android:name="android.hardware.camera" android:required="false"/>
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
<uses-feature android:name="android.hardware.camera.front" android:required="false"/>
<uses-feature android:name="android.hardware.camera.front.autofocus" android:required="false"/>
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<uses-feature
android:name="android.hardware.camera.autofocus"
android:required="false" />
<uses-feature
android:name="android.hardware.camera.front"
android:required="false" />
<uses-feature
android:name="android.hardware.camera.front.autofocus"
android:required="false" />

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
import android.os.Bundle;
import android.view.WindowManager;

import org.lasarobotics.vision.android.Camera;
import org.lasarobotics.vision.android.Cameras;
import org.lasarobotics.vision.detection.ColorBlobDetector;
import org.lasarobotics.vision.detection.objects.Contour;
import org.lasarobotics.vision.ftc.resq.Beacon;
import org.lasarobotics.vision.image.Drawing;
import org.lasarobotics.vision.util.FPS;
import org.lasarobotics.vision.util.color.ColorGRAY;
import org.lasarobotics.vision.util.color.ColorHSV;
import org.lasarobotics.vision.util.color.ColorRGBA;
import org.lasarobotics.vision.test.android.Camera;
import org.lasarobotics.vision.test.android.Cameras;
import org.lasarobotics.vision.test.detection.ColorBlobDetector;
import org.lasarobotics.vision.test.detection.objects.Contour;
import org.lasarobotics.vision.test.ftc.resq.Beacon;
import org.lasarobotics.vision.test.image.Drawing;
import org.lasarobotics.vision.test.util.FPS;
import org.lasarobotics.vision.test.util.color.ColorGRAY;
import org.lasarobotics.vision.test.util.color.ColorHSV;
import org.lasarobotics.vision.test.util.color.ColorRGBA;
import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.CameraBridgeViewBase;
import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame;
Expand All @@ -24,26 +24,48 @@
import org.opencv.core.Mat;
import org.opencv.core.Point;

import java.text.DecimalFormat;
import java.util.List;

public class CameraTestActivity extends Activity implements CvCameraViewListener2 {

private static final ColorHSV colorRadius = new ColorHSV(50, 75, 127);
private static final ColorHSV lowerBoundRed = new ColorHSV((int) (305 / 360.0 * 255.0), (int) (0.200 * 255.0), (int) (0.300 * 255.0));
private static final ColorHSV upperBoundRed = new ColorHSV((int) ((360.0 + 5.0) / 360.0 * 255.0), 255, 255);
private static final ColorHSV lowerBoundBlue = new ColorHSV((int) (170.0 / 360.0 * 255.0), (int) (0.200 * 255.0), (int) (0.750 * 255.0));
private static final ColorHSV upperBoundBlue = new ColorHSV((int) (227.0 / 360.0 * 255.0), 255, 255);
private Mat mRgba; //RGBA scene image
private Mat mGray; //Grayscale scene image
private CameraBridgeViewBase mOpenCvCameraView;

private float focalLength; //Camera lens focal length

//private ObjectDetection.ObjectAnalysis objectAnalysis;
private FPS fpsCounter;
private final BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS: {
// OpenCV loaded successfully!
// Load native library AFTER OpenCV initialization

initialize();

mOpenCvCameraView.enableView();
}
break;
default: {
super.onManagerConnected(status);
}
break;
}
}
};
private ColorBlobDetector detectorRed;
private ColorBlobDetector detectorBlue;
public CameraTestActivity() {

}

private void initialize()
{
private void initialize() {
//GET CAMERA PROPERTIES
Camera cam = Cameras.PRIMARY.createCamera();
android.hardware.Camera.Parameters pam = cam.getCamera().getParameters();
Expand Down Expand Up @@ -79,28 +101,9 @@ private void initialize()
fpsCounter = new FPS();
}

private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS:
{
// OpenCV loaded successfully!
// Load native library AFTER OpenCV initialization

initialize();

mOpenCvCameraView.enableView();
} break;
default:
{
super.onManagerConnected(status);
} break;
}
}
};

/** Called when the activity is first created. */
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -113,16 +116,14 @@ public void onCreate(Bundle savedInstanceState) {
}

@Override
public void onPause()
{
public void onPause() {
super.onPause();
if (mOpenCvCameraView != null)
mOpenCvCameraView.disableView();
}

@Override
public void onResume()
{
public void onResume() {
super.onResume();
if (!OpenCVLoader.initDebug()) {
// Internal OpenCV library not found. Using OpenCV Manager for initialization
Expand All @@ -139,22 +140,12 @@ public void onDestroy() {
mOpenCvCameraView.disableView();
}

private ColorBlobDetector detectorRed;
private ColorBlobDetector detectorBlue;
private static final ColorHSV colorRadius = new ColorHSV(50, 75, 127);

private static final ColorHSV lowerBoundRed = new ColorHSV( (int)(305 / 360.0 * 255.0), (int)(0.200 * 255.0), (int)(0.300 * 255.0));
private static final ColorHSV upperBoundRed = new ColorHSV( (int)((360.0+5.0) / 360.0 * 255.0), 255 , 255);

private static final ColorHSV lowerBoundBlue = new ColorHSV((int)(170.0 / 360.0 * 255.0), (int)(0.200 * 255.0), (int)(0.750 * 255.0));
private static final ColorHSV upperBoundBlue = new ColorHSV((int)(227.0 / 360.0 * 255.0), 255 , 255);

public void onCameraViewStarted(int width, int height) {
mRgba = new Mat(height, width, CvType.CV_8UC4);
mGray = new Mat(height, width, CvType.CV_8UC1);

//Initialize all detectors here
detectorRed = new ColorBlobDetector(lowerBoundRed, upperBoundRed);
detectorRed = new ColorBlobDetector(lowerBoundRed, upperBoundRed);
detectorBlue = new ColorBlobDetector(lowerBoundBlue, upperBoundBlue);
}

Expand Down Expand Up @@ -192,17 +183,15 @@ public Mat onCameraFrame(CvCameraViewFrame inputFrame) {


//DEBUG confidence output
Drawing.drawText(mRgba, "Confidence: " + colorAnalysis.getConfidenceString() ,
Drawing.drawText(mRgba, "Confidence: " + colorAnalysis.getConfidenceString(),
new Point(0, 50), 1.0f, new ColorGRAY(255));

//Transform.enlarge(mRgba, originalSize, true);
//Transform.enlarge(mGray, originalSize, true);

Drawing.drawText(mRgba, colorAnalysis.getStateLeft().toString() + ", " + colorAnalysis.getStateRight().toString(),
new Point(0, 8), 1.0f, new ColorGRAY(255), Drawing.Anchor.BOTTOMLEFT);
}
catch (Exception e)
{
} catch (Exception e) {
Drawing.drawText(mRgba, "Analysis Error", new Point(0, 8), 1.0f, new ColorRGBA("#F44336"), Drawing.Anchor.BOTTOMLEFT);
e.printStackTrace();
}
Expand Down
6 changes: 3 additions & 3 deletions ftc-cameratest/src/main/res/layout/activity_cameratest.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:layout_height="match_parent">

<org.opencv.android.JavaCameraView
android:id="@+id/surfaceView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/surfaceView" />
android:layout_height="fill_parent" />

</LinearLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,11 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE

package com.qualcomm.ftcrobotcontroller.opmodes;

import org.lasarobotics.vision.android.Cameras;
import org.lasarobotics.vision.detection.ColorBlobDetector;
import org.lasarobotics.vision.detection.objects.Contour;
import org.lasarobotics.vision.ftc.resq.Beacon;
import org.lasarobotics.vision.image.Drawing;
import org.lasarobotics.vision.image.Transform;
import org.lasarobotics.vision.opmode.ManualVisionOpMode;
import org.lasarobotics.vision.opmode.VisionExtensions;
import org.lasarobotics.vision.opmode.VisionOpMode;
import org.lasarobotics.vision.util.color.ColorGRAY;
import org.lasarobotics.vision.util.color.ColorHSV;
import org.lasarobotics.vision.util.color.ColorRGBA;
import org.opencv.core.Mat;
import org.opencv.core.Point;
import org.lasarobotics.vision.test.android.Cameras;
import org.lasarobotics.vision.test.opmode.VisionExtensions;
import org.lasarobotics.vision.test.opmode.VisionOpMode;
import org.opencv.core.Size;

import java.util.List;

/**
* TeleOp Mode
* <p/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE

package com.qualcomm.ftcrobotcontroller.opmodes;

import org.lasarobotics.vision.android.Cameras;
import org.lasarobotics.vision.detection.ColorBlobDetector;
import org.lasarobotics.vision.detection.objects.Contour;
import org.lasarobotics.vision.ftc.resq.Beacon;
import org.lasarobotics.vision.image.Drawing;
import org.lasarobotics.vision.opmode.ManualVisionOpMode;
import org.lasarobotics.vision.util.color.ColorGRAY;
import org.lasarobotics.vision.util.color.ColorHSV;
import org.lasarobotics.vision.util.color.ColorRGBA;
import org.lasarobotics.vision.test.android.Cameras;
import org.lasarobotics.vision.test.detection.ColorBlobDetector;
import org.lasarobotics.vision.test.detection.objects.Contour;
import org.lasarobotics.vision.test.ftc.resq.Beacon;
import org.lasarobotics.vision.test.image.Drawing;
import org.lasarobotics.vision.test.opmode.ManualVisionOpMode;
import org.lasarobotics.vision.test.util.color.ColorGRAY;
import org.lasarobotics.vision.test.util.color.ColorHSV;
import org.lasarobotics.vision.test.util.color.ColorRGBA;
import org.opencv.core.Mat;
import org.opencv.core.Point;
import org.opencv.core.Size;
Expand All @@ -53,13 +53,13 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
*/
public class ManualVisionSample extends ManualVisionOpMode {

private Beacon.BeaconAnalysis colorAnalysis = new Beacon.BeaconAnalysis();
private ColorBlobDetector detectorRed;
private ColorBlobDetector detectorBlue;
private static final ColorHSV lowerBoundRed = new ColorHSV((int) (305 / 360.0 * 255.0), (int) (0.200 * 255.0), (int) (0.300 * 255.0));
private static final ColorHSV upperBoundRed = new ColorHSV((int) ((360.0 + 5.0) / 360.0 * 255.0), 255, 255);
private static final ColorHSV lowerBoundBlue = new ColorHSV((int) (170.0 / 360.0 * 255.0), (int) (0.200 * 255.0), (int) (0.750 * 255.0));
private static final ColorHSV upperBoundBlue = new ColorHSV((int) (227.0 / 360.0 * 255.0), 255, 255);
private Beacon.BeaconAnalysis colorAnalysis = new Beacon.BeaconAnalysis();
private ColorBlobDetector detectorRed;
private ColorBlobDetector detectorBlue;
private boolean noError = true;

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.lasarobotics.vision;
package org.lasarobotics.vision.test;

import android.app.Application;
import android.test.ApplicationTestCase;
Expand Down
8 changes: 4 additions & 4 deletions ftc-visionlib/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.lasarobotics.vision">
package="org.lasarobotics.vision.vision">

<application android:allowBackup="true"
android:label="@string/app_name"
>
<application
android:allowBackup="true"
android:label="@string/app_name">

</application>

Expand Down
Loading

0 comments on commit 385e580

Please sign in to comment.