Skip to content

Commit

Permalink
Show history as red dots
Browse files Browse the repository at this point in the history
  • Loading branch information
mads256h committed May 1, 2023
1 parent 0c3d8cb commit f70b2af
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ 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
import dk.scuffed.whiteboardapp.pipeline.stages.opengl_process_stages.MaskingStage
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

/**
Expand All @@ -26,7 +27,7 @@ internal fun fullPipeline(
context: Context,
inputStage: GLOutputStage,
pipeline: IPipeline
): Pair<SwitchablePointPipeline, GLOutputStage> {
): Pair<PointsOutputStage, GLOutputStage> {


// ------------------ SEGMENTATION STUFF START --------------
Expand Down Expand Up @@ -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


Expand All @@ -86,7 +89,7 @@ internal fun fullPipeline(
val perspectiveCorrected = fullPerspectiveCorrection(
context,
maskStage,
switchablePointPipeline.pointsOutputStage,
cornerDetection,
cameraPointsStage,
pipeline
)
Expand Down Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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] },
Expand All @@ -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]
Expand All @@ -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>): Vec2Int {
Expand All @@ -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<Vec2Int>) {
for (i in points.indices) {
points[i] = newPoints[i]
}
}
}
}

0 comments on commit f70b2af

Please sign in to comment.