This repository has no description
0

Configure Feed

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

fix: ensure android coordinates correctly show left and right

+31 -21
+1 -1
README.md
··· 6 6 Import the Compose library 7 7 8 8 ```kotlin 9 - implementation("com.performancecoachlab.posedetection:posedetection-compose:1.1.0") 9 + implementation("com.performancecoachlab.posedetection:posedetection-compose:1.1.1") 10 10 ``` 11 11 12 12 Add camera use to your android manifest
+1 -1
posedetection/build.gradle.kts
··· 4 4 5 5 mavenPublishing { 6 6 publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL) 7 - coordinates("com.performancecoachlab.posedetection", "posedetection-compose", "1.1.0") 7 + coordinates("com.performancecoachlab.posedetection", "posedetection-compose", "1.1.1") 8 8 9 9 pom { 10 10 name.set("Pose Detection")
+6 -4
posedetection/src/androidMain/kotlin/com.performancecoachlab/posedetection/camera/CameraView.android.kt
··· 49 49 frontCamera: Boolean 50 50 ) { 51 51 var bitmap by remember { mutableStateOf<ImageBitmap?>(null) } 52 - var skeleton by remember { mutableStateOf(Skeleton()) } 52 + var skeleton by remember { mutableStateOf(Skeleton(width = 0f, height = 0f)) } 53 53 val options = 54 54 PoseDetectorOptions.Builder().setDetectorMode(PoseDetectorOptions.STREAM_MODE).build() 55 55 val poseDetector = PoseDetection.getClient(options) ··· 70 70 image, imageProxy.imageInfo.rotationDegrees 71 71 ) 72 72 poseDetector.process(img).addOnSuccessListener { pose -> 73 - skeleton = skeleton(pose, imageProxy.imageInfo.timestamp) 74 - skeletonRepository.updateSkeleton(skeleton) 73 + skeleton = skeleton(pose, imageProxy.imageInfo.timestamp,img.width, img.height) 74 + skeletonRepository.updateSkeleton(skeleton.mirror()) 75 75 bitmap = 76 76 imageProxy.toBitmap().rotate(imageProxy.imageInfo.rotationDegrees.toFloat()) 77 77 .asImageBitmap().drawSkeleton(if (drawSkeleton) skeleton else null, 0f) ··· 128 128 return asAndroidBitmap().rotate(angle).asImageBitmap() 129 129 } 130 130 131 - fun skeleton(pose: Pose?, timestamp: Long): Skeleton { 131 + fun skeleton(pose: Pose?, timestamp: Long, width: Int, height: Int): Skeleton { 132 132 return Skeleton( 133 133 timestamp = timestamp, 134 134 leftShoulder = pose?.getPoseLandmark(PoseLandmark.LEFT_SHOULDER)?.toSkeletonCoords(), ··· 143 143 rightKnee = pose?.getPoseLandmark(PoseLandmark.RIGHT_KNEE)?.toSkeletonCoords(), 144 144 leftAnkle = pose?.getPoseLandmark(PoseLandmark.LEFT_ANKLE)?.toSkeletonCoords(), 145 145 rightAnkle = pose?.getPoseLandmark(PoseLandmark.RIGHT_ANKLE)?.toSkeletonCoords(), 146 + width = width.toFloat(), 147 + height = height.toFloat(), 146 148 ) 147 149 }
+17 -13
posedetection/src/commonMain/kotlin/com/performancecoachlab/posedetection/skeleton/Skeleton.kt
··· 18 18 val rightKnee: SkeletonCoordinate? = null, 19 19 val leftAnkle: SkeletonCoordinate? = null, 20 20 val rightAnkle: SkeletonCoordinate? = null, 21 + val width: Float, 22 + val height: Float, 21 23 ) { 22 24 data class SkeletonCoordinate( 23 25 val x: Float, ··· 153 155 ) 154 156 } 155 157 156 - fun mirror(w:Float): Skeleton { 158 + fun mirror(w: Float = width): Skeleton { 157 159 return Skeleton( 158 160 timestamp = timestamp, 159 - leftShoulder = leftShoulder?.let { SkeletonCoordinate(it.x, w-it.y) }, 160 - rightShoulder = rightShoulder?.let { SkeletonCoordinate(it.x, w-it.y) }, 161 - leftElbow = leftElbow?.let { SkeletonCoordinate(it.x, w-it.y) }, 162 - rightElbow = rightElbow?.let { SkeletonCoordinate(it.x, w-it.y) }, 163 - leftWrist = leftWrist?.let { SkeletonCoordinate(it.x, w-it.y) }, 164 - rightWrist = rightWrist?.let { SkeletonCoordinate(it.x, w-it.y) }, 165 - leftHip = leftHip?.let { SkeletonCoordinate(it.x,w-it.y) }, 166 - rightHip = rightHip?.let { SkeletonCoordinate(it.x, w-it.y) }, 167 - leftKnee = leftKnee?.let { SkeletonCoordinate(it.x, w-it.y) }, 168 - rightKnee = rightKnee?.let { SkeletonCoordinate(it.x, w-it.y) }, 169 - leftAnkle = leftAnkle?.let { SkeletonCoordinate(it.x, w-it.y) }, 170 - rightAnkle = rightAnkle?.let { SkeletonCoordinate(it.x, w-it.y) }, 161 + leftShoulder = leftShoulder?.let { SkeletonCoordinate(w - it.x, it.y) }, 162 + rightShoulder = rightShoulder?.let { SkeletonCoordinate(w - it.x, it.y) }, 163 + leftElbow = leftElbow?.let { SkeletonCoordinate(w - it.x, it.y) }, 164 + rightElbow = rightElbow?.let { SkeletonCoordinate(w - it.x, it.y) }, 165 + leftWrist = leftWrist?.let { SkeletonCoordinate(w - it.x, it.y) }, 166 + rightWrist = rightWrist?.let { SkeletonCoordinate(w - it.x, it.y) }, 167 + leftHip = leftHip?.let { SkeletonCoordinate(w - it.x, it.y) }, 168 + rightHip = rightHip?.let { SkeletonCoordinate(w - it.x, it.y) }, 169 + leftKnee = leftKnee?.let { SkeletonCoordinate(w - it.x, it.y) }, 170 + rightKnee = rightKnee?.let { SkeletonCoordinate(w - it.x, it.y) }, 171 + leftAnkle = leftAnkle?.let { SkeletonCoordinate(w - it.x, it.y) }, 172 + rightAnkle = rightAnkle?.let { SkeletonCoordinate(w - it.x, it.y) }, 173 + width = width, 174 + height = height, 171 175 ) 172 176 } 173 177 }
+3 -1
posedetection/src/iosMain/kotlin/com/performancecoachlab/posedetection/camera/CameraEngine.kt
··· 479 479 leftKnee = mapPoint(skeleton.leftKnee), 480 480 rightKnee = mapPoint(skeleton.rightKnee), 481 481 leftAnkle = mapPoint(skeleton.leftAnkle), 482 - rightAnkle = mapPoint(skeleton.rightAnkle) 482 + rightAnkle = mapPoint(skeleton.rightAnkle), 483 + width = width, 484 + height = height, 483 485 ) 484 486 } 485 487
+3 -1
posedetection/src/iosMain/kotlin/com/performancecoachlab/posedetection/camera/FrameProcessor.kt
··· 130 130 )?.location?.toSkeletonPoint(width, height), 131 131 rightAnkle = recognizedPoints?.get( 132 132 VNHumanBodyPoseObservationJointNameRightAnkle 133 - )?.location?.toSkeletonPoint(width, height) 133 + )?.location?.toSkeletonPoint(width, height), 134 + height = height.toFloat(), 135 + width = width.toFloat() 134 136 ) 135 137 onProccessed(updatedSkeleton) 136 138 }