rodgomesc / vision-camera-face-detector

VisionCamera Frame Processor Plugin to detect faces using MLKit Vision Face Detector
MIT License
89 stars 65 forks source link

What is `bounds.x` and `bounds.y` for? #22

Open bglgwyng opened 1 year ago

bglgwyng commented 1 year ago

I supposed that those are top and left of the bounding box, and I directly used them to display the overlay bounding box for the detected face. And I realized that frame is mirrored so I tried right instead of left. Nevertheless, the bounding box was not correctly positioned over the face.

So I looked into the source and I saw these lines.

    Double offsetX =  (boundingBox.exactCenterX() - ceil(boundingBox.width())) / 2.0f;
    Double offsetY =  (boundingBox.exactCenterY() - ceil(boundingBox.height())) / 2.0f;

    Double x = boundingBox.right + offsetX;
    Double y = boundingBox.top + offsetY;

    bounds.putDouble("x", boundingBox.centerX() + (boundingBox.centerX() - x));
    bounds.putDouble("y", boundingBox.centerY() + (y - boundingBox.centerY()));

But I couldn't understand the definition of x and y. So I just replaced the definitions with boundingBox.top and boundingBox.left. And It worked really well! What is the intended usage of x and y? What is the problem when I just use boundingBox.top and boundingBox.left?

nguyenhieuax commented 1 year ago

Any update on this, I'm getting different results on Android and IOS

bglgwyng commented 1 year ago

@nguyenhieuax https://github.com/bglgwyng/vision-camera-face-detector I forked this repo and fix this issue. Frame object works differently in ios and android. You'll receive cropped images in ios, so their aspect ratio is different to each other even in the same camera view size. I'm going to share face detection + bounding box rendering example soon.

bglgwyng commented 1 year ago

https://github.com/mrousavy/react-native-vision-camera/discussions/1229 I made a simple example.

jackviatick commented 1 year ago

@bglgwyng the top value still not so correct when i test on the Ipad one. Also, when i use your lib there are no contours data anymore.

bglgwyng commented 1 year ago

@jackviatick Sorry, I removed countours for my own purpose. I think you can easily restore it. And if you figure out the correct solution that works also on iPad, please share it here for me. I'd be very grateful.