From f70b2af480a18570572f8aee9fc84611793c3683 Mon Sep 17 00:00:00 2001 From: Mads Mogensen Date: Mon, 1 May 2023 13:20:10 +0200 Subject: [PATCH] Show history as red dots --- .../stage_combinations/FullCornerDetection.kt | 98 +++++++++---------- .../stage_combinations/FullPipeline.kt | 32 +++--- .../points_stages/WeightedPointsStage.kt | 19 +++- 3 files changed, 83 insertions(+), 66 deletions(-) diff --git a/app/src/main/java/dk/scuffed/whiteboardapp/pipeline/stage_combinations/FullCornerDetection.kt b/app/src/main/java/dk/scuffed/whiteboardapp/pipeline/stage_combinations/FullCornerDetection.kt index 423cf2d..e1cdde1 100644 --- a/app/src/main/java/dk/scuffed/whiteboardapp/pipeline/stage_combinations/FullCornerDetection.kt +++ b/app/src/main/java/dk/scuffed/whiteboardapp/pipeline/stage_combinations/FullCornerDetection.kt @@ -23,66 +23,56 @@ internal fun fullCornerDetection( inputStage: GLOutputStage, pipeline: IPipeline ): PointsOutputStage { + val edges = fullCannyEdgeDetection( + context, + inputStage, + pipeline + ) - val threadedBitmapInputPointOutputStage = ThreadedBitmapInputPointOutputStage( - { pipeline -> - val edges = fullCannyEdgeDetection( - context, - inputStage, - pipeline - ) + val edgesBitmapStage = FramebufferToBitmapStage( + edges.frameBufferInfo, + Bitmap.Config.ARGB_8888, + pipeline + ) - val edgesBitmapStage = FramebufferToBitmapStage( - edges.frameBufferInfo, - Bitmap.Config.ARGB_8888, - pipeline - ) - }, - { inputBitmapStage, pipeline -> - val openCVLineDetectionStage = OpenCVLineDetectionStage( - inputBitmapStage, - 150, - 50, - pipeline, - 1.0, - Math.PI / 180.0, - 15.0, - Math.PI / 75.0 - ) + val openCVLineDetectionStage = OpenCVLineDetectionStage( + edgesBitmapStage, + 150, + 50, + pipeline, + 1.0, + Math.PI / 180.0, + 15.0, + Math.PI / 75.0 + ) - val verticalLinesAngleDiscriminatorStage = LinesAngleDiscriminatorStage( - openCVLineDetectionStage, - -(Math.PI / 4.0f).toFloat(), - (Math.PI / 4.0f).toFloat(), - pipeline - ) + val verticalLinesAngleDiscriminatorStage = LinesAngleDiscriminatorStage( + openCVLineDetectionStage, + -(Math.PI / 4.0f).toFloat(), + (Math.PI / 4.0f).toFloat(), + pipeline + ) - val horizontalLinesAngleDiscriminatorStage = LinesAngleDiscriminatorStage( - openCVLineDetectionStage, - (Math.PI / 4.0f).toFloat(), - (Math.PI / 2.0f + Math.PI / 4.0f).toFloat(), - pipeline - ) + val horizontalLinesAngleDiscriminatorStage = LinesAngleDiscriminatorStage( + openCVLineDetectionStage, + (Math.PI / 4.0f).toFloat(), + (Math.PI / 2.0f + Math.PI / 4.0f).toFloat(), + pipeline + ) - val biggestQuadStage = BiggestQuadStage( - horizontalLinesAngleDiscriminatorStage, - verticalLinesAngleDiscriminatorStage, - pipeline - ) + val biggestQuadStage = BiggestQuadStage( + horizontalLinesAngleDiscriminatorStage, + verticalLinesAngleDiscriminatorStage, + pipeline + ) - val weightedCornerStage = WeightedPointsStage( - biggestQuadStage, - 20, - 5.0f, - pipeline - ) - }, - pipeline, - Vec2Int(0,0), - Vec2Int(0,0), - Vec2Int(0,0), - Vec2Int(0,0) + val weightedCornerStage = WeightedPointsStage( + biggestQuadStage, + 20, + 5.0f, + pipeline ) - return threadedBitmapInputPointOutputStage.myOutputPointsStage + return weightedCornerStage + } \ No newline at end of file diff --git a/app/src/main/java/dk/scuffed/whiteboardapp/pipeline/stage_combinations/FullPipeline.kt b/app/src/main/java/dk/scuffed/whiteboardapp/pipeline/stage_combinations/FullPipeline.kt index 7cf6501..7025217 100644 --- a/app/src/main/java/dk/scuffed/whiteboardapp/pipeline/stage_combinations/FullPipeline.kt +++ b/app/src/main/java/dk/scuffed/whiteboardapp/pipeline/stage_combinations/FullPipeline.kt @@ -6,6 +6,7 @@ import android.opengl.GLES20 import android.util.Size import dk.scuffed.whiteboardapp.pipeline.IPipeline import dk.scuffed.whiteboardapp.pipeline.stages.GLOutputStage +import dk.scuffed.whiteboardapp.pipeline.stages.PointsOutputStage import dk.scuffed.whiteboardapp.pipeline.stages.bitmap_process_stages.DumpToGalleryStage import dk.scuffed.whiteboardapp.pipeline.stages.opengl_process_stages.* import dk.scuffed.whiteboardapp.pipeline.stages.opengl_process_stages.BinarizationStage @@ -13,10 +14,10 @@ import dk.scuffed.whiteboardapp.pipeline.stages.opengl_process_stages.MaskingSta import dk.scuffed.whiteboardapp.pipeline.stages.opengl_process_stages.OverlayStage import dk.scuffed.whiteboardapp.pipeline.stages.opengl_process_stages.StoreStage import dk.scuffed.whiteboardapp.pipeline.stages.pipeline_stages.SwitchablePointPipeline +import dk.scuffed.whiteboardapp.pipeline.stages.points_stages.* import dk.scuffed.whiteboardapp.pipeline.stages.points_stages.CornersFromResolutionStage import dk.scuffed.whiteboardapp.pipeline.stages.points_stages.DraggablePointsStage import dk.scuffed.whiteboardapp.pipeline.stages.points_stages.DrawCornersStage -import dk.scuffed.whiteboardapp.pipeline.stages.points_stages.ScreenCornerPointsStage import dk.scuffed.whiteboardapp.utils.Color /** @@ -26,7 +27,7 @@ internal fun fullPipeline( context: Context, inputStage: GLOutputStage, pipeline: IPipeline -): Pair { +): Pair { // ------------------ SEGMENTATION STUFF START -------------- @@ -61,20 +62,22 @@ internal fun fullPipeline( // ------------------ LINE DETECTION STUFF START -------------- - val switchablePointPipeline = SwitchablePointPipeline( - context, - { pipeline -> DraggablePointsStage(pipeline) }, - { pipeline -> fullCornerDetection(context, storeStage, pipeline) }, - pipeline - ) + val cornerDetection = fullCornerDetection(context, storeStage, pipeline) val drawCorners = DrawCornersStage( context, pipeline, - switchablePointPipeline.pointsOutputStage, + cornerDetection, Color(0.0f, 1.0f, 0.0f, 1.0f) ) + val drawHistoryCorners = DrawCornersStage( + context, + pipeline, + (cornerDetection as WeightedPointsStage).historyPointsStage, + Color(1.0f, 0.0f, 0.0f, 1.0f) + ) + // --------------- LINE DETECTION STUFF END @@ -86,7 +89,7 @@ internal fun fullPipeline( val perspectiveCorrected = fullPerspectiveCorrection( context, maskStage, - switchablePointPipeline.pointsOutputStage, + cornerDetection, cameraPointsStage, pipeline ) @@ -137,9 +140,16 @@ internal fun fullPipeline( val overlay = OverlayStage( context, readdedColour.frameBufferInfo, + drawHistoryCorners.frameBufferInfo, + pipeline + ) + + val overlay2 = OverlayStage( + context, + overlay.frameBufferInfo, drawCorners.frameBufferInfo, pipeline ) - return Pair(switchablePointPipeline, overlay) + return Pair(cornerDetection, overlay2) } \ No newline at end of file diff --git a/app/src/main/java/dk/scuffed/whiteboardapp/pipeline/stages/points_stages/WeightedPointsStage.kt b/app/src/main/java/dk/scuffed/whiteboardapp/pipeline/stages/points_stages/WeightedPointsStage.kt index 560cc3a..2fa3170 100644 --- a/app/src/main/java/dk/scuffed/whiteboardapp/pipeline/stages/points_stages/WeightedPointsStage.kt +++ b/app/src/main/java/dk/scuffed/whiteboardapp/pipeline/stages/points_stages/WeightedPointsStage.kt @@ -12,7 +12,7 @@ internal class WeightedPointsStage( private val weightThreshold: Float, pipeline: IPipeline ) : PointsOutputStage(pipeline, inputPoints.points[0], inputPoints.points[1], inputPoints.points[2], inputPoints.points[3]) { - private var pointHistories = + private val pointHistories = arrayOf( Array(historySize) { inputPoints.points[0] }, Array(historySize) { inputPoints.points[1] }, @@ -21,6 +21,8 @@ internal class WeightedPointsStage( ) private var pointIndex = 0 + val historyPointsStage: PointsOutputStage = MyHistoryPointsStage(pipeline, *pointHistories.flatten().toTypedArray()) + override fun update() { pointHistories[0][pointIndex] = inputPoints.points[0] @@ -34,6 +36,8 @@ internal class WeightedPointsStage( points[1] = weightedAvgPoint(pointHistories[1]) points[2] = weightedAvgPoint(pointHistories[2]) points[3] = weightedAvgPoint(pointHistories[3]) + + (historyPointsStage as MyHistoryPointsStage).setPoints(pointHistories.flatten().toTypedArray()) } private fun weightedAvgPoint(pointHistory: Array): Vec2Int { @@ -57,4 +61,17 @@ internal class WeightedPointsStage( val result = sum / weightSum return Vec2Float(round(result.x), round(result.y)).toVec2Int() } + + private class MyHistoryPointsStage(pipeline: IPipeline, vararg initialPoints: Vec2Int) : + PointsOutputStage(pipeline, *initialPoints) { + override fun update() { + // Nothing + } + + fun setPoints(newPoints: Array) { + for (i in points.indices) { + points[i] = newPoints[i] + } + } + } } \ No newline at end of file