0
const frameProcessor = useSkiaFrameProcessor((frame) => {
    'worklet'
    const faces = detectFaces(frame);
    frame.render();
    
   
    
    for (const face of faces) {
      if (face?.bounds) {
        console.log(face.bounds);
        
        const { x, y, width, height } = face.bounds;
        

        const paint = Skia.Paint();
        paint.setColor(Skia.Color('red'));
        paint.setStyle(PaintStyle.Stroke);
        frame.drawRect(face.bounds, paint);
      }
    }
    
  }, []);

The bounding box appears offset to the bottom right of faces. I'm aware this is essentially a math problem but haven't been able to find the right solution. The frame processor is passed as a style property for react-native-vision-camera is used for the camera component. and react-native-vision-camera-face-detector is the face detector plugin

 const previewWidth = Dimensions.get('window').width;
    const previewHeight = Dimensions.get('window').height;

    
    const frameWidth = frame.width;
    const frameHeight = frame.height;

    // Calculate scaling factors
    const scaleX = previewWidth / frameWidth;
    const scaleY = previewHeight / frameHeight;

    for (const face of faces) {
      if (face?.bounds) {
        console.log(face.bounds);

        
        const { x, y, width, height } = face.bounds;
        const adjustedX = x * scaleX;
        const adjustedY = y * scaleY;
        const adjustedWidth = width * scaleX;
        const adjustedHeight = height * scaleY;

tried these and similar ratios. haven't found a working one yet. Can subtract a cosntant value from x and y to make it work on my specific device but need something that can work on any device

2
  • Hello, Your calculations are close, but the problem might be influenced by additional factors like device orientation or the way the camera frame is being rendered. if (aspectRatioFrame > aspectRatioPreview) { scaleX = previewWidth / frameWidth; scaleY = scaleX; } else { scaleY = previewHeight / frameHeight; scaleX = scaleY; } Then, apply these adjusted values when drawing the rectangle frame.drawRect({ x: adjustedX, y: adjustedY, width: adjustedWidth, height: adjustedHeight }, paint); Commented Sep 2, 2024 at 8:26
  • unfortunately didn't work. The box is bottom left of the actual face Commented Sep 2, 2024 at 10:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.