Skip to content
Snippets Groups Projects
Commit 64ee540a authored by Altair1618's avatar Altair1618
Browse files

chore: apply formatting

parent e82774f0
1 merge request!24feat: implement crop helper
......@@ -151,7 +151,7 @@ abstract class ResultActivity : MainActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
OpenCVLoader.initLocal()
OpenCVLoader.initLocal()
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q) {
requirePermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, false) {}
......
......@@ -19,49 +19,57 @@ class CropHelper {
): Bitmap {
val mult = 0.03
val newTopLeft = Point(
points.topLeft.x - (points.topRight.x - points.topLeft.x) * mult - (points.bottomLeft.x - points.topLeft.x) * mult,
points.topLeft.y - (points.topRight.y - points.topLeft.y) * mult - (points.bottomLeft.y - points.topLeft.y) * mult,
)
val newTopRight = Point(
points.topRight.x + (points.topRight.x - points.topLeft.x) * mult - (points.bottomRight.x - points.topRight.x) * mult,
points.topRight.y + (points.topRight.y - points.topLeft.y) * mult - (points.bottomRight.y - points.topRight.y) * mult,
)
val newBottomRight = Point(
points.bottomRight.x + (points.bottomRight.x - points.topRight.x) * mult + (points.bottomRight.x - points.bottomLeft.x) * mult,
points.bottomRight.y + (points.bottomRight.y - points.topRight.y) * mult + (points.bottomRight.y - points.bottomLeft.y) * mult,
)
val newBottomLeft = Point(
points.bottomLeft.x - (points.bottomRight.x - points.bottomLeft.x) * mult + (points.bottomRight.x - points.topRight.x) * mult,
points.bottomLeft.y - (points.bottomRight.y - points.bottomLeft.y) * mult + (points.bottomRight.y - points.topRight.y) * mult,
)
val newTopLeft =
Point(
points.topLeft.x - (points.topRight.x - points.topLeft.x) * mult - (points.bottomLeft.x - points.topLeft.x) * mult,
points.topLeft.y - (points.topRight.y - points.topLeft.y) * mult - (points.bottomLeft.y - points.topLeft.y) * mult,
)
val newTopRight =
Point(
points.topRight.x + (points.topRight.x - points.topLeft.x) * mult - (points.bottomRight.x - points.topRight.x) * mult,
points.topRight.y + (points.topRight.y - points.topLeft.y) * mult - (points.bottomRight.y - points.topRight.y) * mult,
)
val newBottomRight =
Point(
points.bottomRight.x + (points.bottomRight.x - points.topRight.x) * mult + (points.bottomRight.x - points.bottomLeft.x) * mult,
points.bottomRight.y + (points.bottomRight.y - points.topRight.y) * mult + (points.bottomRight.y - points.bottomLeft.y) * mult,
)
val newBottomLeft =
Point(
points.bottomLeft.x - (points.bottomRight.x - points.bottomLeft.x) * mult + (points.bottomRight.x - points.topRight.x) * mult,
points.bottomLeft.y - (points.bottomRight.y - points.bottomLeft.y) * mult + (points.bottomRight.y - points.topRight.y) * mult,
)
val newPoints = CornerPoints(newTopLeft, newTopRight, newBottomRight, newBottomLeft)
val topWidth = sqrt(
(newPoints.topRight.x - newPoints.topLeft.x).pow(2) +
(newPoints.topRight.y - newPoints.topLeft.y).pow(2)
)
val topWidth =
sqrt(
(newPoints.topRight.x - newPoints.topLeft.x).pow(2) +
(newPoints.topRight.y - newPoints.topLeft.y).pow(2),
)
val bottomWidth = sqrt(
(newPoints.bottomRight.x - newPoints.bottomLeft.x).pow(2) +
(newPoints.bottomRight.y - newPoints.bottomLeft.y).pow(2)
)
val bottomWidth =
sqrt(
(newPoints.bottomRight.x - newPoints.bottomLeft.x).pow(2) +
(newPoints.bottomRight.y - newPoints.bottomLeft.y).pow(2),
)
val maxWidth = maxOf(topWidth, bottomWidth)
val leftHeight = sqrt(
(newPoints.bottomLeft.x - newPoints.topLeft.x).pow(2) +
(newPoints.bottomLeft.y - newPoints.topLeft.y).pow(2)
)
val leftHeight =
sqrt(
(newPoints.bottomLeft.x - newPoints.topLeft.x).pow(2) +
(newPoints.bottomLeft.y - newPoints.topLeft.y).pow(2),
)
val rightHeight = sqrt(
(newPoints.bottomRight.x - newPoints.topRight.x).pow(2) +
(newPoints.bottomRight.y - newPoints.topRight.y).pow(2)
)
val rightHeight =
sqrt(
(newPoints.bottomRight.x - newPoints.topRight.x).pow(2) +
(newPoints.bottomRight.y - newPoints.topRight.y).pow(2),
)
val maxHeight = maxOf(leftHeight, rightHeight)
......@@ -70,19 +78,21 @@ class CropHelper {
val width = 800
val height = (width / aspectRatio).toInt()
val srcMatrix = MatOfPoint2f(
newPoints.topLeft,
newPoints.topRight,
newPoints.bottomRight,
newPoints.bottomLeft,
)
val dstMatrix = MatOfPoint2f(
Point(0.0, 0.0),
Point(width - 1.0, 0.0),
Point(0.0, height - 1.0),
Point(width - 1.0, height - 1.0),
)
val srcMatrix =
MatOfPoint2f(
newPoints.topLeft,
newPoints.topRight,
newPoints.bottomRight,
newPoints.bottomLeft,
)
val dstMatrix =
MatOfPoint2f(
Point(0.0, 0.0),
Point(width - 1.0, 0.0),
Point(0.0, height - 1.0),
Point(width - 1.0, height - 1.0),
)
val transformMatrix = getPerspectiveTransform(srcMatrix, dstMatrix)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment