-
Notifications
You must be signed in to change notification settings - Fork 13
Swift 4 update. #4
base: master
Are you sure you want to change the base?
Conversation
… and removed unecessary cast to clear warning
…ather than image orientation
…o detailView to follow device orientation
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check
FaceTracking/ViewController.swift
Outdated
|
|
||
| let attachments = CMCopyDictionaryOfAttachments(kCFAllocatorDefault, sampleBuffer, kCMAttachmentMode_ShouldPropagate) | ||
|
|
||
| let ciImage = CIImage(cvImageBuffer: pixelBuffer!, options: attachments as! [String : Any]?) |
There was a problem hiding this comment.
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 !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check
FaceTracking/ViewController.swift
Outdated
| "has closed left eye: \(faceFeature.leftEyeClosed)", | ||
| "has closed right eye: \(faceFeature.rightEyeClosed)"] | ||
| "has closed right eye: \(faceFeature.leftEyeClosed)", |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
FaceTracking/ViewController.swift
Outdated
| } | ||
|
|
||
| func exifOrientation(orientation: UIDeviceOrientation) -> Int { | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check
FaceTracking/ViewController.swift
Outdated
|
|
||
| DispatchQueue.main.async { | ||
| UIView.animate(withDuration: 0.2) { | ||
| UIView.animate(withDuration: 0.2) { [unowned self] in |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. Check.
FaceTracking/ViewController.swift
Outdated
| } | ||
|
|
||
| func rotateDetailViewWithDeviceOrientation() { | ||
| switch UIDevice.current.orientation { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
FaceTracking/ViewController.swift
Outdated
| switch UIDevice.current.orientation { | ||
|
|
||
| case .portrait: | ||
| self.detailsView.transform = CGAffineTransform(rotationAngle: 0) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
FaceTracking/ViewController.swift
Outdated
| case .portraitUpsideDown: | ||
| self.detailsView.transform = CGAffineTransform(rotationAngle: CGFloat.pi) | ||
|
|
||
| default: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default: ()
There was a problem hiding this comment.
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.
FaceTracking/ViewController.swift
Outdated
| @@ -1,4 +1,4 @@ | |||
| // | |||
| // | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check
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) |
There was a problem hiding this comment.
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:...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check
|
I don't understand why the tests fail. Can anyone help? |
|
This project is no longer maintained and will be archived. |
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!