Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help using Dlib coordinates #30

Open
ccastelano opened this issue Aug 29, 2017 · 7 comments
Open

Help using Dlib coordinates #30

ccastelano opened this issue Aug 29, 2017 · 7 comments

Comments

@ccastelano
Copy link

ccastelano commented Aug 29, 2017

First of all, congratulations for your good job!
My question is: Is there any way to grab the coordinates (x, y) of the points detected by the algorithm, inside the "SessionHandler.swift" file? (more specifically inside the "captureOutput" function). I'm trying to figure out how to do this for a few days, but I couldn't get any further, because I'm having difficuties to understand Objective C and adapt the code. Thank you for sharing!

@zweigraf
Copy link
Owner

zweigraf commented Sep 1, 2017

Yes you could return the calculated coordinates from the doWork method in DlibWrapper.

@ccastelano
Copy link
Author

It worked perfectly, man!

However, I came across with one last "coordinate conversion" issue.

The code after the modification seems like:

-(CGPoint)doWorkOnSampleBuffer:(CMSampleBufferRef)sampleBuffer inRects:(NSArray<NSValue *> *)rects {

    CGPoint mypoint = CGPointMake(0, 0); // DECLARING MY POINT

    (...)

        for (unsigned long k = 0; k < shape.num_parts(); k++) {
            dlib::point p = shape.part(k);
            
            if (k == 36) {
                mypoint = CGPointMake(p.x(), p.y()); // MY POINT OF INTEREST
            }

    (...)

    return mypoint;
}

Now, inside my ViewController.swift, I declared an global variable for "myView" as follow:

var myView = UIView()

(...)

override func viewDidLoad() {
        super.viewDidLoad()
        
        myView = UIView(frame: CGRect(x: 0, y: 0, width: 20, height: 20))
        view.addSubview(myView)
        view.bringSubview(toFront: myView)
 }

And finally, inside my SessionHandler.swift file, I did like:

func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, from connection: AVCaptureConnection!) {

    (...)

            var myPoint = wrapper?.doWork(on: sampleBuffer, inRects: boundsArray)
            print("myPoint = ", myPoint)
            
            DispatchQueue.main.async(execute: {
                
                myView.center = CGPoint(x: ((myPoint?.x)!/2), y: ((myPoint?.y)!/2))
                myView.backgroundColor = .red
                
            })
}

Then, I noticed that the position of the points are not coinciding, and things seems mislocated.

I think I need to make some coordinate (x,y) conversion.

Any ideia?

Thanks!

@zweigraf
Copy link
Owner

zweigraf commented Sep 1, 2017

If I understand the problem correctly, yes you need some coordinate conversion.

In this line: https://github.com/zweigraf/face-landmarking-ios/blob/master/DisplayLiveSamples/SessionHandler.swift#L72 we first convert the metadata object into some other format depending on camera orientation and stuff like that.

Then, in this line: https://github.com/zweigraf/face-landmarking-ios/blob/master/DisplayLiveSamples/DlibWrapper.mm#L87 we are converting those coordinates into Dlib suitable coordinates.

If you want to use the points again in SessionHandler, after calculating your point, you first need to reverse the Dlib conversion from DlibWrapper (instead of iOS-> Dlib make it Dlib->iOS), and then maybe reverse the camera conversion from SessionHandler.

@zweigraf zweigraf changed the title Help Help using Dlib coordinates Sep 1, 2017
@harshchitrla
Copy link

harshchitrla commented Mar 9, 2018

@zweigraf Any idea how do I convert Dlib to iOS points ? Anyone tried to figure out.

@harshchitrla
Copy link

@ccastelano hi, did you manage to solve "coordinate conversion" issue

@leynercastillo
Copy link

@harshchitrla hi. The coordinates returned by Dlib are the coordinates of the original image. You only need to convert the original image coordinate to you UIImageView or containerView coordinates. That depend of you content mode and the container size.

@jirkaskotak
Copy link

Hey, has anyone found a solution to this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants