Giter Site home page Giter Site logo

Comments (6)

gwendall avatar gwendall commented on June 3, 2024 1

There you go. It's probably because the model expects images with faces up. I tried doing frame.rotate(90, 0, 0) in the frame processor before passing the frame to the face detector but it doesn't seem to have any effect.

RPReplay_Final1716295251.mov

from react-native-vision-camera-face-detector.

mrousavy avatar mrousavy commented on June 3, 2024 1

Okay I definitely need to update the documentation on frame.orientation as a lot of people seem to misunderstand what it actually means and I get asked about this almost daily.

  1. Orientation is not fully implemented. I'm trying to raise money so I can implement orientation here: mrousavy/react-native-vision-camera#1891
  2. The orientation of the Frame is probably not what most people think under orientation. Maybe I can find a different name for it. But it is always the way you need to read the Frame to make sure it is up-right. That's because Camera sensors are often in landscape orientation and that means you need to rotate the Frame by 90deg to display it up-right. This is handled already for preview photo and video, but in Frame Processors you need to do it yourself - if I would always rotate the frame to be 90deg upright position, that would introduce a huge latency and performance bottleneck in the pipeline. So instead, ML models work by internally just reading the Frame rotated. That way I don't have to actually rotate any buffers around and it's much faster.

Hope this explains why it stays the same.

from react-native-vision-camera-face-detector.

luicfrr avatar luicfrr commented on June 3, 2024

can you add a screenshot or a video showing what you mean with "detections appear erratic"?

from react-native-vision-camera-face-detector.

luicfrr avatar luicfrr commented on June 3, 2024

Okay, can you please check if frame.orientation change when you rotate your device?

Currently I’m using frame’s orientation to determine MLKit orientation.

from react-native-vision-camera-face-detector.

gwendall avatar gwendall commented on June 3, 2024

My app was locked in portrait mode so I just unlocked it. Oddly frame.orientation still never changes. Orientation change does get captured with expo-screen-orientation though (see recording below). So I guess it is a react-native-vision-camera issue? It is possible that expo or the screen orientation lib interferes with frame.orientation @mrousavy?

What would be awesome (and maybe the simpler fix) would be to be able to manually pass the screen orientation to detectFaces. May also enable to lock the UI in portrait mode while still handling frames for vision computing in their actual directions like it's done on instagram, tiktok, etc. What do you think?

bug2.mov

from react-native-vision-camera-face-detector.

luicfrr avatar luicfrr commented on June 3, 2024

I'll do some tests and try to implement this feature ASAP. The problem is I'm busy with another project right now so I can't say when I'll have time to do this.

Anyway, if you want to try it yourself: orientation is handled on native side in these lines:

val rotation = getFrameRotation(frame.orientation)
val image = InputImage.fromMediaImage(frame.image, rotation)
val sourceWidth: Double
val sourceHeight: Double
if (rotation == 270 || rotation == 90) {
sourceWidth = image.height.toDouble()
sourceHeight = image.width.toDouble()
} else {
sourceWidth = image.width.toDouble()
sourceHeight = image.height.toDouble()
}

let image = VisionImage(buffer: frame.buffer)
image.orientation = frame.orientation
var scaleX:CGFloat
var scaleY:CGFloat
if autoScale {
scaleX = screenBounds.size.width / CGFloat(frame.width)
scaleY = screenBounds.size.height / CGFloat(frame.height)
} else {
scaleX = CGFloat(1)
scaleY = CGFloat(1)
}

a good start point is to set fixed values on native side and check if it works:

// ios
let image = VisionImage(buffer: frame.buffer)
image.orientation = .up //or .left or .right etc....

// android
val image = InputImage.fromMediaImage(frame.image, 0) // or 90, 180, etc...

maybe we can add the orientation prop on config so when orientation changes it will recreate face detector:

const orientation = someOrientationHook() 
const { detectFaces } = useFaceDetector( {
  ... other props,
  orientation
} )

Or maybe get device's orientation on native side instead?

from react-native-vision-camera-face-detector.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.