Skip to content
This repository was archived by the owner on Apr 3, 2019. It is now read-only.

Conversation

@roselloryan
Copy link

@roselloryan roselloryan commented Jan 9, 2018

Found your project reading about face tracking and wanted to thank you by updating it up for others to find and learn from.

Fixed face tracking to work for all device orientations and added DetailView rotation to match the orientation of user's face.

Assuming the user is turning the device and not the other way around.

Thanks!

return devices.filter { $0.position == .front }.first
let discoverySession = AVCaptureDevice.DiscoverySession.init(deviceTypes: [AVCaptureDevice.DeviceType.builtInWideAngleCamera], mediaType: .video, position: AVCaptureDevice.Position.front)

return discoverySession.devices.count > 0 ? discoverySession.devices.first : nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can just return discoverySession.devices.first, its optional

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check


let attachments = CMCopyDictionaryOfAttachments(kCFAllocatorDefault, sampleBuffer, kCMAttachmentMode_ShouldPropagate)

let ciImage = CIImage(cvImageBuffer: pixelBuffer!, options: attachments as! [String : Any]?)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add guards above instead of using !

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check

"has closed left eye: \(faceFeature.leftEyeClosed)",
"has closed right eye: \(faceFeature.rightEyeClosed)"]
"has closed right eye: \(faceFeature.leftEyeClosed)",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure it's ok?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. I will set it back to the original orientation.

}

func exifOrientation(orientation: UIDeviceOrientation) -> Int {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove it

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check


DispatchQueue.main.async {
UIView.animate(withDuration: 0.2) {
UIView.animate(withDuration: 0.2) { [unowned self] in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in case of animation there is no need to use unowned or weak

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. Check.

}

func rotateDetailViewWithDeviceOrientation() {
switch UIDevice.current.orientation {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change formatting and remove new lines

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hope I did this correctly.

switch UIDevice.current.orientation {

case .portrait:
self.detailsView.transform = CGAffineTransform(rotationAngle: 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self is not necessary here and below

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

case .portraitUpsideDown:
self.detailsView.transform = CGAffineTransform(rotationAngle: CGFloat.pi)

default:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default: ()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome. Thank you for your help.

@@ -1,4 +1,4 @@
//
//
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove it

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check

guard let devices = AVCaptureDevice.devices(withMediaType: AVMediaTypeVideo) as? [AVCaptureDevice] else { return nil }

return devices.filter { $0.position == .front }.first
let discoverySession = AVCaptureDevice.DiscoverySession.init(deviceTypes: [AVCaptureDevice.DeviceType.builtInWideAngleCamera], mediaType: .video, position: AVCaptureDevice.Position.front)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.init is not neccessary just ...DiscoverySession(deviceTypes:...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check

@roselloryan
Copy link
Author

I don't understand why the tests fail. Can anyone help?

@roselloryan roselloryan changed the title Swift 4 update and clean up. Swift 4 update. Feb 22, 2018
@koral--
Copy link
Member

koral-- commented Apr 2, 2019

This project is no longer maintained and will be archived.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants