Skip to content
This repository was archived by the owner on Sep 15, 2023. It is now read-only.

Commit bfa6886

Browse files
authored
Update README.md
1 parent 38c4f55 commit bfa6886

File tree

1 file changed

+32
-33
lines changed

1 file changed

+32
-33
lines changed

README.md

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,41 @@ The TargetDetector class specializes in finding vision targets in an image given
1212

1313
### Example
1414
```Java
15-
TargetGroupDetector pegDetector = new TargetGroupDetector.Builder()
16-
.setTargetSpecs(new PegSingleRetroreflectiveSpecs())
17-
.setTargetGroupSpecs(new PegGroupSpecs())
18-
.setProcessor((targets)->{
19-
// do something
20-
})
21-
.build();
22-
23-
CameraSource camera = new CameraSource.Builder(pegDetector)
24-
.setType(CameraSource.Type.USB)
25-
.build();
15+
CameraSource camera = new CameraSource(new UsbCamera("cam", 0));
16+
camera.setExposure(0);
17+
camera.setBrightness(0);
18+
camera.setResolution(640, 480);
19+
20+
TargetDetector targetDetector = new TargetDetector(new ExampleSpecs(), (targets) -> {
21+
// do something
22+
});
23+
camera.setDetector(targetDetector);
24+
25+
camera.start();
2626
```
2727

2828
### Displaying the most probable target example
2929
```Java
3030
final CvSource outputStream = CameraServer.getInstance().putVideo("Target", 640, 480);
31-
32-
TargetGroupDetector pegDetector = new TargetGroupDetector.Builder()
33-
.setTargetSpecs(new PegSingleRetroreflectiveSpecs())
34-
.setTargetGroupSpecs(new PegGroupSpecs())
35-
.setProcessor((targets) - > {
36-
// Draw the most probable target on the output stream
37-
if (!targets.isEmpty()) {
38-
Mat image = camera.getPicture();
39-
Rect boundary = new Rect((int) Math.round(targets.get(0).getPosition().x),
40-
(int) Math.round(targets.get(0).getPosition().y),
41-
(int) Math.round(targets.get(0).getWidth()),
42-
(int) Math.round(targets.get(0).getHeight()));
43-
Imgproc.rectangle(image, boundary.tl(), boundary.br(), new Scalar(0, 255, 0));
44-
outputStream.putFrame(image);
45-
}
46-
})
47-
.build();
48-
49-
CameraSource camera = new CameraSource.Builder(pegDetector)
50-
.setType(CameraSource.Type.USB)
51-
.setResolution(640, 480)
52-
.build();
31+
final CameraSource camera = new CameraSource(new UsbCamera("cam", 0));
32+
camera.setExposure(0);
33+
camera.setBrightness(0);
34+
camera.setResolution(640, 480);
35+
36+
TargetGroupDetector pegDetector = new TargetGroupDetector(new PegSingleRetroreflectiveSpecs(), new PegGroupSpecs(), (targets) -> {
37+
// Draw the most probable target on the output stream
38+
if (!targets.isEmpty()) {
39+
Mat image = camera.getPicture();
40+
Rect boundary = new Rect((int) Math.round(targets.get(0).getPosition().x),
41+
(int) Math.round(targets.get(0).getPosition().y),
42+
(int) Math.round(targets.get(0).getWidth()),
43+
(int) Math.round(targets.get(0).getHeight()));
44+
Imgproc.rectangle(image, boundary.tl(), boundary.br(), new Scalar(0, 255, 0));
45+
outputStream.putFrame(image);
46+
}
47+
});
48+
49+
camera.setDetector(pegDetector);
50+
51+
camera.start();
5352
```

0 commit comments

Comments
 (0)