@@ -12,42 +12,41 @@ The TargetDetector class specializes in finding vision targets in an image given
12
12
13
13
### Example
14
14
``` 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 ();
26
26
```
27
27
28
28
### Displaying the most probable target example
29
29
``` Java
30
30
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();
53
52
```
0 commit comments