forked from PHScodemaster/FRC4949
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIntermediateVision
57 lines (44 loc) · 1.89 KB
/
IntermediateVision
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
54
55
56
57
package org.usfirst.frc.team4949.robot;
import com.ni.vision.NIVision;
import com.ni.vision.NIVision.DrawMode;
import com.ni.vision.NIVision.Image;
import com.ni.vision.NIVision.ShapeMode;
import edu.wpi.first.wpilibj.CameraServer;
import edu.wpi.first.wpilibj.SampleRobot;
import edu.wpi.first.wpilibj.Timer;
/**
* This is a demo program showing the use of the NIVision class to do vision processing.
* The image is acquired from the USB Webcam, then a circle is overlayed on it.
* The NIVision class supplies dozens of methods for different types of processing.
* The resulting image can then be sent to the FRC PC Dashboard with setImage()
*/
public class Robot extends SampleRobot {
int session;
Image frame;
public void robotInit() {
frame = NIVision.imaqCreateImage(NIVision.ImageType.IMAGE_RGB, 0);
// the camera name (ex "cam0") can be found through the roborio web interface
session = NIVision.IMAQdxOpenCamera("cam1",
NIVision.IMAQdxCameraControlMode.CameraControlModeController);
NIVision.IMAQdxConfigureGrab(session);
}
public void operatorControl() {
NIVision.IMAQdxStartAcquisition(session);
/**
* grab an image, draw the circle, and provide it for the camera server
* which will in turn send it to the dashboard.
*/
//NIVision.Rect rect = new NIVision.Rect(10, 10, 100, 100);
while (isOperatorControl() && isEnabled()) {
NIVision.IMAQdxGrab(session, frame, 1);
/*NIVision.imaqDrawShapeOnImage(frame, frame, rect,
DrawMode.DRAW_VALUE, ShapeMode.SHAPE_OVAL, 0.0f);*/
CameraServer.getInstance().setImage(frame);
/** robot code here! **/
Timer.delay(0.005); // wait for a motor update time
}
NIVision.IMAQdxStopAcquisition(session);
}
public void test() {
}
}