forked from FIRST-Tech-Challenge/FtcRobotController
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebcamView.java
53 lines (49 loc) · 2.48 KB
/
webcamView.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import org.firstinspires.ftc.robotcore.external.hardware.camera.WebcamName;
import org.openftc.easyopencv.OpenCvCamera;
import org.openftc.easyopencv.OpenCvCameraFactory;
import org.openftc.easyopencv.OpenCvCameraRotation;
import org.openftc.easyopencv.OpenCvInternalCamera;
@TeleOp(name="openCv", group="test")
public class webcamView extends LinearOpMode {
OpenCvCamera cam;
ringPipeline pipeline;
@Override
public void runOpMode() {
int cameraMonitorViewId = hardwareMap.appContext.getResources().getIdentifier("cameraMonitorViewId", "id", hardwareMap.appContext.getPackageName());
//cam = OpenCvCameraFactory.getInstance().createInternalCamera(OpenCvInternalCamera.CameraDirection.BACK, cameraMonitorViewId);
cam = OpenCvCameraFactory.getInstance().createWebcam(hardwareMap.get(WebcamName.class, "Webcam 1"), cameraMonitorViewId);
pipeline = new ringPipeline();
cam.setPipeline(pipeline);
cam.openCameraDeviceAsync(new OpenCvCamera.AsyncCameraOpenListener()
{
@Override
public void onOpened()
{
/*
* Tell the camera to start streaming images to us! Note that you must make sure
* the resolution you specify is supported by the camera. If it is not, an exception
* will be thrown.
*
* Also, we specify the rotation that the camera is used in. This is so that the image
* from the camera sensor can be rotated such that it is always displayed with the image upright.
* For a front facing camera, rotation is defined assuming the user is looking at the screen.
* For a rear facing camera or a webcam, rotation is defined assuming the camera is facing
* away from the user.
*/
cam.startStreaming(320, 240, OpenCvCameraRotation.UPRIGHT);
}
});
waitForStart();
while(opModeIsActive()){
telemetry.addData("rings", pipeline.getRings());
telemetry.addData("ratio", pipeline.getRatio());
double[] colors= pipeline.getColor();
telemetry.addData("colors", "Y: " + colors[0] + " Cr: " + colors[1] + " Cb: " + colors[2]);
telemetry.update();
sleep(100);
}
}
}