Skip to content

Commit

Permalink
Draw poiints
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed May 10, 2024
1 parent 1d66037 commit 5db3194
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions package/example/src/CameraPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { useIsFocused } from '@react-navigation/core'
import { usePreferredCameraDevice } from './hooks/usePreferredCameraDevice'
import { examplePlugin } from './frame-processors/ExamplePlugin'
import { exampleKotlinSwiftPlugin } from './frame-processors/ExampleKotlinSwiftPlugin'
import { Skia } from '@shopify/react-native-skia'
import { PointMode, Skia, StrokeJoin } from '@shopify/react-native-skia'

const ReanimatedCamera = Reanimated.createAnimatedComponent(Camera)
Reanimated.addWhitelistedNativeProps({
Expand Down Expand Up @@ -182,18 +182,16 @@ export function CameraPage({ navigation }: Props): React.ReactElement {
y: number
z: number
visibility: number
presence: number
}
interface Handedness {
score: number
}
interface Hand {
landmarks: Landmark[]
handedness: Handedness[]
}

const paint = Skia.Paint()
paint.setColor(Skia.Color('red'))
paint.setStrokeWidth(15)
paint.setStrokeJoin(StrokeJoin.Round)

const frameProcessor = useSkiaFrameProcessor(
(frame) => {
'worklet'
Expand All @@ -205,11 +203,9 @@ export function CameraPage({ navigation }: Props): React.ReactElement {
const height = frame.height

for (const hand of hands) {
hand.landmarks.forEach((landmark) => {
const rect = Skia.XYWHRect(landmark.x * width, landmark.y * height, 50, 50)
console.log(`Drawing rect at (${landmark.x * width}, ${landmark.y * height})`)
frame.drawRect(rect, paint)
})
const points = hand.landmarks.map((l) => Skia.Point(l.x * width, l.y * height))
console.log(`Drawing ${points.length} points..`)
frame.drawPoints(PointMode.Points, points, paint)
}
},
[paint],
Expand Down

0 comments on commit 5db3194

Please sign in to comment.