Swift 4 update.#4
Conversation
… and removed unecessary cast to clear warning
…ather than image orientation
…o detailView to follow device orientation
| 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.
you can just return discoverySession.devices.first, its optional
|
|
||
| let attachments = CMCopyDictionaryOfAttachments(kCFAllocatorDefault, sampleBuffer, kCMAttachmentMode_ShouldPropagate) | ||
|
|
||
| let ciImage = CIImage(cvImageBuffer: pixelBuffer!, options: attachments as! [String : Any]?) |
There was a problem hiding this comment.
add guards above instead of using !
| "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.
No. I will set it back to the original orientation.
| } | ||
|
|
||
| func exifOrientation(orientation: UIDeviceOrientation) -> Int { | ||
|
|
|
|
||
| DispatchQueue.main.async { | ||
| UIView.animate(withDuration: 0.2) { | ||
| UIView.animate(withDuration: 0.2) { [unowned self] in |
There was a problem hiding this comment.
in case of animation there is no need to use unowned or weak
| } | ||
|
|
||
| func rotateDetailViewWithDeviceOrientation() { | ||
| switch UIDevice.current.orientation { |
There was a problem hiding this comment.
change formatting and remove new lines
| switch UIDevice.current.orientation { | ||
|
|
||
| case .portrait: | ||
| self.detailsView.transform = CGAffineTransform(rotationAngle: 0) |
There was a problem hiding this comment.
self is not necessary here and below
| case .portraitUpsideDown: | ||
| self.detailsView.transform = CGAffineTransform(rotationAngle: CGFloat.pi) | ||
|
|
||
| default: |
There was a problem hiding this comment.
Awesome. Thank you for your help.
| @@ -1,4 +1,4 @@ | |||
| // | |||
| // | |||
| 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.
.init is not neccessary just ...DiscoverySession(deviceTypes:...
|
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!