This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

feat: ability to crop inputFrame

+51 -2
+1 -1
README.md
··· 8 8 Import the Compose library 9 9 10 10 ```kotlin 11 - implementation("com.performancecoachlab.posedetection:posedetection-compose:3.1.0") 11 + implementation("com.performancecoachlab.posedetection:posedetection-compose:3.1.1") 12 12 ``` 13 13 14 14 Add camera use to your android manifest
+19
posedetection/src/androidMain/kotlin/com/performancecoachlab/posedetection/recording/InputFrame.android.kt
··· 26 26 actual fun drawAnalysisResults(analysisResults: AnalysisResult): ImageBitmap { 27 27 return toImageBitmap().drawAnalysisResults(analysisResults) 28 28 } 29 + 30 + actual fun crop(rect: Rect): InputFrame { 31 + val width = bitmap.width 32 + val height = bitmap.height 33 + val sanitised = Rect( 34 + left = rect.left.coerceIn(0f, width.toFloat()), 35 + top = rect.top.coerceIn(0f, height.toFloat()), 36 + right = rect.right.coerceIn(0f, width.toFloat()), 37 + bottom = rect.bottom.coerceIn(0f, height.toFloat()) 38 + ) 39 + val croppedBitmap = Bitmap.createBitmap( 40 + bitmap, 41 + sanitised.left.toInt(), 42 + sanitised.top.toInt(), 43 + sanitised.width.toInt(), 44 + sanitised.height.toInt() 45 + ) 46 + return InputFrame(croppedBitmap, timestamp) 47 + } 29 48 } 30 49 31 50 actual class FrameAnalyser actual constructor(val model: ObjectModel?) {
+1
posedetection/src/commonMain/kotlin/com/performancecoachlab/posedetection/recording/InputFrame.kt
··· 9 9 fun toImageBitmap(): ImageBitmap 10 10 fun drawSkeleton(skel: Skeleton): ImageBitmap 11 11 fun drawAnalysisResults(analysisResults: AnalysisResult): ImageBitmap 12 + fun crop(rect: Rect): InputFrame 12 13 13 14 val timestamp: Long 14 15 }
+29
posedetection/src/iosMain/kotlin/com/performancecoachlab/posedetection/recording/InputFrame.ios.kt
··· 10 10 import com.performancecoachlab.posedetection.skeleton.Skeleton 11 11 import kotlinx.cinterop.ExperimentalForeignApi 12 12 import kotlinx.coroutines.suspendCancellableCoroutine 13 + import platform.CoreGraphics.CGImageCreateWithImageInRect 14 + import platform.CoreGraphics.CGImageGetHeight 15 + import platform.CoreGraphics.CGImageGetWidth 13 16 import platform.CoreGraphics.CGImageRef 17 + import platform.CoreGraphics.CGRectMake 14 18 import platform.CoreML.MLModel 15 19 import platform.Foundation.NSBundle 16 20 import platform.Foundation.NSURL 17 21 import platform.UIKit.UIImage 18 22 import platform.Vision.VNCoreMLModel 19 23 import kotlin.coroutines.resume 24 + import kotlin.native.runtime.NativeRuntimeApi 25 + import kotlin.text.toDouble 26 + import kotlin.text.toFloat 20 27 21 28 actual class InputFrame @OptIn(ExperimentalForeignApi::class) constructor( 22 29 val cgImage: CGImageRef, actual val timestamp: Long ··· 32 39 33 40 actual fun drawAnalysisResults(analysisResults: AnalysisResult): ImageBitmap { 34 41 return toImageBitmap().drawAnalysisResults(analysisResults) 42 + } 43 + 44 + @OptIn(ExperimentalForeignApi::class, NativeRuntimeApi::class) 45 + actual fun crop(rect: Rect): InputFrame { 46 + val widthPx = CGImageGetWidth(cgImage).toFloat() 47 + val heightPx = CGImageGetHeight(cgImage).toFloat() 48 + val sanitised = Rect( 49 + left = rect.left.coerceIn(0f, widthPx), 50 + top = rect.top.coerceIn(0f, heightPx), 51 + right = rect.right.coerceIn(0f, widthPx), 52 + bottom = rect.bottom.coerceIn(0f, heightPx) 53 + ) 54 + 55 + val cropX = sanitised.left.toDouble() 56 + // invert y for CoreGraphics coordinate system 57 + val cropY = (sanitised.top).toDouble() 58 + val cropW = (sanitised.right - sanitised.left).toDouble() 59 + val cropH = (sanitised.bottom - sanitised.top).toDouble() 60 + 61 + val cgRect = CGRectMake(cropX, cropY, cropW, cropH) 62 + kotlin.native.runtime.GC.collect() 63 + return InputFrame(CGImageCreateWithImageInRect(cgImage, cgRect)?:cgImage, timestamp) 35 64 } 36 65 } 37 66
+1 -1
sample/composeApp/src/commonMain/kotlin/com/nate/posedetection/App.kt
··· 23 23 import androidx.compose.runtime.setValue 24 24 import androidx.compose.ui.Alignment 25 25 import androidx.compose.ui.Modifier 26 + import androidx.compose.ui.geometry.Rect 26 27 import androidx.compose.ui.graphics.ImageBitmap 27 28 import androidx.compose.ui.layout.ContentScale 28 29 import androidx.compose.ui.unit.dp ··· 206 207 207 208 } 208 209 } 209 - image = extractedFrame 210 210 } catch (e: Exception) { 211 211 // Handle any error that may occur 212 212 e.printStackTrace()
sample/iosApp/iosApp/models/best_for_speed_not_for_accuracy.mlpackage/Data/com.apple.CoreML/weights/weight.bin

This is a binary file and will not be displayed.