-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make VisionProcessors be automatically detected alongside pipelines
- Loading branch information
1 parent
8661940
commit 907fe5e
Showing
11 changed files
with
149 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...java/com/github/serivesmejia/eocvsim/pipeline/instantiator/DefaultPipelineInstantiator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.github.serivesmejia.eocvsim.pipeline.instantiator | ||
|
||
import com.github.serivesmejia.eocvsim.pipeline.PipelineManager | ||
import org.firstinspires.ftc.robotcore.external.Telemetry | ||
import org.openftc.easyopencv.OpenCvPipeline | ||
|
||
object DefaultPipelineInstantiator : PipelineInstantiator { | ||
|
||
override fun instantiate(clazz: Class<*>, telemetry: Telemetry) = try { | ||
//instantiate pipeline if it has a constructor of a telemetry parameter | ||
val constructor = clazz.getConstructor(Telemetry::class.java) | ||
constructor.newInstance(telemetry) as OpenCvPipeline | ||
} catch (ex: NoSuchMethodException) { | ||
//instantiating with a constructor of no params | ||
val constructor = clazz.getConstructor() | ||
constructor.newInstance() as OpenCvPipeline | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
...c/main/java/com/github/serivesmejia/eocvsim/pipeline/instantiator/PipelineInstantiator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.github.serivesmejia.eocvsim.pipeline.instantiator | ||
|
||
import com.github.serivesmejia.eocvsim.pipeline.PipelineManager | ||
import org.firstinspires.ftc.robotcore.external.Telemetry | ||
import org.openftc.easyopencv.OpenCvPipeline | ||
|
||
interface PipelineInstantiator { | ||
|
||
fun instantiate(clazz: Class<*>, telemetry: Telemetry): OpenCvPipeline | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
.../com/github/serivesmejia/eocvsim/pipeline/instantiator/processor/ProcessorInstantiator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.github.serivesmejia.eocvsim.pipeline.instantiator.processor | ||
|
||
import com.github.serivesmejia.eocvsim.pipeline.PipelineManager | ||
import com.github.serivesmejia.eocvsim.pipeline.instantiator.PipelineInstantiator | ||
import com.github.serivesmejia.eocvsim.util.ReflectUtil | ||
import org.firstinspires.ftc.robotcore.external.Telemetry | ||
import org.firstinspires.ftc.vision.VisionProcessor | ||
import org.openftc.easyopencv.OpenCvPipeline | ||
|
||
object ProcessorInstantiator : PipelineInstantiator { | ||
|
||
override fun instantiate(clazz: Class<*>, telemetry: Telemetry): OpenCvPipeline { | ||
if(!ReflectUtil.hasSuperclass(clazz, VisionProcessor::class.java)) | ||
throw IllegalArgumentException("Class $clazz does not extend VisionProcessor") | ||
|
||
val processor = try { | ||
//instantiate pipeline if it has a constructor of a telemetry parameter | ||
val constructor = clazz.getConstructor(Telemetry::class.java) | ||
constructor.newInstance(telemetry) as VisionProcessor | ||
} catch (ex: NoSuchMethodException) { | ||
//instantiating with a constructor of no params | ||
val constructor = clazz.getConstructor() | ||
constructor.newInstance() as VisionProcessor | ||
} | ||
|
||
return ProcessorPipeline(processor) | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
...va/com/github/serivesmejia/eocvsim/pipeline/instantiator/processor/ProcessorPipeline.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.github.serivesmejia.eocvsim.pipeline.instantiator.processor; | ||
|
||
import android.graphics.Canvas; | ||
import com.qualcomm.robotcore.eventloop.opmode.Disabled; | ||
import org.firstinspires.ftc.vision.VisionProcessor; | ||
import org.opencv.core.Mat; | ||
import org.openftc.easyopencv.TimestampedOpenCvPipeline; | ||
|
||
@Disabled | ||
class ProcessorPipeline extends TimestampedOpenCvPipeline { | ||
|
||
private VisionProcessor processor; | ||
|
||
public ProcessorPipeline(VisionProcessor processor) { | ||
this.processor = processor; | ||
} | ||
|
||
@Override | ||
public void init(Mat mat) { | ||
processor.init(mat.width(), mat.height(), null); | ||
} | ||
|
||
@Override | ||
public Mat processFrame(Mat input, long captureTimeNanos) { | ||
requestViewportDrawHook(processor.processFrame(input, captureTimeNanos)); | ||
return input; | ||
} | ||
|
||
@Override | ||
public void onDrawFrame(Canvas canvas, int onscreenWidth, int onscreenHeight, float scaleBmpPxToCanvasPx, float scaleCanvasDensity, Object userContext) { | ||
processor.onDrawFrame(canvas, onscreenWidth, onscreenHeight, scaleBmpPxToCanvasPx, scaleCanvasDensity, userContext); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters