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

Swift 4 update.#4

Open
roselloryan wants to merge 16 commits into
DroidsOnRoids:masterfrom
roselloryan:master
Open

Swift 4 update.#4
roselloryan wants to merge 16 commits into
DroidsOnRoids:masterfrom
roselloryan:master

Conversation

@roselloryan
Copy link
Copy Markdown

@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!

Comment thread FaceTracking/ViewController.swift Outdated
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
Copy Markdown
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
Copy Markdown
Author

Choose a reason for hiding this comment

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

check

Comment thread FaceTracking/ViewController.swift Outdated

let attachments = CMCopyDictionaryOfAttachments(kCFAllocatorDefault, sampleBuffer, kCMAttachmentMode_ShouldPropagate)

let ciImage = CIImage(cvImageBuffer: pixelBuffer!, options: attachments as! [String : Any]?)
Copy link
Copy Markdown
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
Copy Markdown
Author

Choose a reason for hiding this comment

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

check

Comment thread FaceTracking/ViewController.swift Outdated
"has closed left eye: \(faceFeature.leftEyeClosed)",
"has closed right eye: \(faceFeature.rightEyeClosed)"]
"has closed right eye: \(faceFeature.leftEyeClosed)",
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread FaceTracking/ViewController.swift Outdated
}

func exifOrientation(orientation: UIDeviceOrientation) -> Int {

Copy link
Copy Markdown
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
Copy Markdown
Author

Choose a reason for hiding this comment

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

check

Comment thread FaceTracking/ViewController.swift Outdated

DispatchQueue.main.async {
UIView.animate(withDuration: 0.2) {
UIView.animate(withDuration: 0.2) { [unowned self] in
Copy link
Copy Markdown
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
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thank you. Check.

Comment thread FaceTracking/ViewController.swift Outdated
}

func rotateDetailViewWithDeviceOrientation() {
switch UIDevice.current.orientation {
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread FaceTracking/ViewController.swift Outdated
switch UIDevice.current.orientation {

case .portrait:
self.detailsView.transform = CGAffineTransform(rotationAngle: 0)
Copy link
Copy Markdown
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
Copy Markdown
Author

Choose a reason for hiding this comment

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

Removed.

Comment thread FaceTracking/ViewController.swift Outdated
case .portraitUpsideDown:
self.detailsView.transform = CGAffineTransform(rotationAngle: CGFloat.pi)

default:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

default: ()

Copy link
Copy Markdown
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.

Comment thread FaceTracking/ViewController.swift Outdated
@@ -1,4 +1,4 @@
//
//
Copy link
Copy Markdown
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
Copy Markdown
Author

Choose a reason for hiding this comment

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

check

Comment thread FaceTracking/ViewController.swift Outdated
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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