66import com .google .inject .Inject ;
77import com .google .inject .Singleton ;
88import com .google .inject .name .Named ;
9+ import edu .wpi .grip .core .OperationDescription ;
910import edu .wpi .grip .core .OperationMetaData ;
1011import edu .wpi .grip .core .events .OperationAddedEvent ;
1112import edu .wpi .grip .core .operations .composite .*;
2122import edu .wpi .grip .core .operations .opencv .MinMaxLoc ;
2223import edu .wpi .grip .core .operations .opencv .NewPointOperation ;
2324import edu .wpi .grip .core .operations .opencv .NewSizeOperation ;
25+ import edu .wpi .grip .core .operations .templated .TemplateFactory ;
2426import edu .wpi .grip .core .sockets .InputSocket ;
2527import edu .wpi .grip .core .sockets .OutputSocket ;
28+ import edu .wpi .grip .core .sockets .SocketHint ;
29+ import edu .wpi .grip .core .sockets .SocketHints ;
30+ import edu .wpi .grip .core .util .Icon ;
31+ import org .bytedeco .javacpp .opencv_core .Mat ;
2632import org .bytedeco .javacpp .opencv_core .Point ;
33+ import org .bytedeco .javacpp .opencv_core .Rect ;
2734import org .bytedeco .javacpp .opencv_core .Size ;
2835
2936import static com .google .common .base .Preconditions .checkNotNull ;
@@ -44,6 +51,8 @@ public class Operations {
4451 this .eventBus = checkNotNull (eventBus , "EventBus cannot be null" );
4552 checkNotNull (ntPublisherFactory , "ntPublisherFactory cannot be null" );
4653 checkNotNull (rosPublishFactory , "rosPublishFactory cannot be null" );
54+ TemplateFactory templateFactory = new TemplateFactory (isf , osf );
55+
4756 this .operations = ImmutableList .of (
4857 // Composite operations
4958 new OperationMetaData (BlurOperation .DESCRIPTION , () -> new BlurOperation (isf , osf )),
@@ -67,8 +76,54 @@ public class Operations {
6776 new OperationMetaData (WatershedOperation .DESCRIPTION , () -> new WatershedOperation (isf , osf )),
6877 new OperationMetaData (ThresholdMoving .DESCRIPTION , () -> new ThresholdMoving (isf , osf )),
6978
79+ new OperationMetaData (
80+ OperationDescription .builder ()
81+ .name ("Crop" )
82+ .summary ("Crop an image" )
83+ .icon (Icon .iconStream ("grip" ))
84+ .build (),
85+ templateFactory .create (
86+ SocketHints .Inputs .createMatSocketHint ("src" , false ),
87+ SocketHints .Inputs .createPointSocketHint ("p1" , false ),
88+ SocketHints .Inputs .createPointSocketHint ("p2" , false ),
89+ SocketHints .Inputs .createMatSocketHint ("dst" , true ),
90+ (src , p1 , p2 , dst ) -> {
91+ final Rect rect = new Rect (p1 , p2 );
92+ final Mat tmp = new Mat (src , rect );
93+ tmp .copyTo (dst );
94+ }
95+ )),
96+
97+ new OperationMetaData (
98+ OperationDescription .builder ()
99+ .name ("Number Threshold" )
100+ .summary ("Returns a boolean on whether or not the number is within the given range." )
101+ .icon (Icon .iconStream ("grip" ))
102+ .build (),
103+ templateFactory .createReturning (
104+ SocketHints .Inputs .createNumberSpinnerSocketHint ("Input" , 0 ),
105+ SocketHints .Inputs .createNumberSpinnerSocketHint ("Min" , -1 ),
106+ SocketHints .Inputs .createNumberSpinnerSocketHint ("Max" , 1 ),
107+ SocketHints .Outputs .createBooleanSocketHint ("Output" , true ),
108+ (num , min , max ) -> min .doubleValue () <= num .doubleValue () && max .doubleValue () >= num .doubleValue ()
109+ )
110+ ),
111+
112+ new OperationMetaData (
113+ OperationDescription .builder ()
114+ .name ("Count Contours" )
115+ .summary ("Counts the number of contours in a contours report." )
116+ .icon (Icon .iconStream ("grip" ))
117+ .build (),
118+ templateFactory .createReturning (
119+ new SocketHint .Builder <>(ContoursReport .class ).identifier ("Contours" ).build (),
120+ SocketHints .Outputs .createNumberSocketHint ("Count" , 0 ),
121+ (contours ) -> contours .getContours ().size ()
122+ )
123+ ),
124+
70125 // OpenCV operations
71- new OperationMetaData (MatFieldAccessor .DESCRIPTION , () -> new MatFieldAccessor (isf , osf )),
126+ new OperationMetaData (MatFieldAccessor .DESCRIPTION , () -> new MatFieldAccessor (isf , osf )),
72127 new OperationMetaData (MinMaxLoc .DESCRIPTION , () -> new MinMaxLoc (isf , osf )),
73128 new OperationMetaData (NewPointOperation .DESCRIPTION , () -> new NewPointOperation (isf , osf )),
74129 new OperationMetaData (NewSizeOperation .DESCRIPTION , () -> new NewSizeOperation (isf , osf )),
0 commit comments