Download classifier, database

This commit is contained in:
christophhagen
2020-05-16 11:21:55 +02:00
parent dceb3ca07d
commit 7287607a60
50 changed files with 3555 additions and 2919 deletions

View File

@@ -17,16 +17,16 @@ protocol CameraControllerDelegate {
class CameraController: UIViewController {
private let imageSize = 299 // New for XCode models, 227/229 for turicreate
// MARK: Outlets
@IBOutlet weak var imageButton: RoundedButton!
@IBOutlet weak var imageButton: UIButton!
@IBOutlet weak var cropView: CropView!
@IBOutlet weak var cancelButton: RoundedButton!
@IBOutlet weak var cancelButton: UIButton!
@IBOutlet weak var bottomBar: UIView!
@IBOutlet weak var cameraView: CameraView! {
didSet {
cameraView.configure()
@@ -89,12 +89,24 @@ class CameraController: UIViewController {
}
private func setTintColor() {
let tint = AppDelegate.tintColor
cropView.lineColor = tint
imageButton.borderColor = tint
imageButton.imageView?.tintColor = tint
cancelButton.borderColor = tint
cancelButton.set(template: "cancel", with: tint)
let blur = UIBlurEffect(style: .systemThinMaterial)
let a = UIVisualEffectView(effect: blur)
a.translatesAutoresizingMaskIntoConstraints = false
bottomBar.backgroundColor = nil
bottomBar.insertSubview(a, at: 0)
//bottomBar.addSubview(a)
let t = bottomBar.topAnchor.constraint(equalTo: a.topAnchor)
let b = bottomBar.bottomAnchor.constraint(equalTo: a.bottomAnchor)
let l = bottomBar.leadingAnchor.constraint(equalTo: a.leadingAnchor)
let r = bottomBar.trailingAnchor.constraint(equalTo: a.trailingAnchor)
bottomBar.addConstraints([t,b,l,r])
//let tint = AppDelegate.tintColor
//cropView.lineColor = tint
//imageButton.borderColor = tint
imageButton.imageView?.tintColor = .systemBlue
//cancelButton.borderColor = tint
//cancelButton.set(template: "cancel", with: tint)
}
private func giveFeedback(_ style: UIImpactFeedbackGenerator.FeedbackStyle) {
@@ -107,8 +119,8 @@ class CameraController: UIViewController {
private func showNoCameraAccessAlert() {
let alert = UIAlertController(title: "Unable to access the Camera",
message: "To enable access, go to Settings > Privacy > Camera and turn on Camera access for this app.",
preferredStyle: .alert,
blurStyle: .dark)
preferredStyle: .alert)//,
//blurStyle: .dark)
let okAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
alert.addAction(okAction)
@@ -132,10 +144,9 @@ class CameraController: UIViewController {
extension CameraController: PhotoCaptureHandlerDelegate {
func didCapture(_ image: UIImage?) {
event("Image captured")
log("Image captured")
let factor = CGFloat(cropView.relativeSize)
self.dismiss(animated: true)
let size = CGSize(width: imageSize, height: imageSize)
guard let img = image else {
self.error("No image captured")
return
@@ -151,14 +162,10 @@ extension CameraController: PhotoCaptureHandlerDelegate {
return
}
// Only use 227 x 227 image
let scaled = masked.resize(to: size)
let scaled = masked.resize(to: Cap.imageSize)
delegate!.didCapture(image: scaled)
}
}
extension CameraController: Logger {
static var logToken = "[Camera]"
}
extension CameraController: Logger { }

View File

@@ -191,7 +191,7 @@ class CameraView: UIView {
photoOutput.isHighResolutionCaptureEnabled = true
photoOutput.isDepthDataDeliveryEnabled = false
photoOutput.isDualCameraDualPhotoDeliveryEnabled = false
//photoOutput.isDualCameraDualPhotoDeliveryEnabled = false
photoOutput.isLivePhotoCaptureEnabled = false
session.commitConfiguration()
}
@@ -200,7 +200,7 @@ class CameraView: UIView {
let screenSize = bounds.size
let location = touch.location(in: self)
let focusPoint = CGPoint(x: location.y / screenSize.height, y: 1.0 - location.x / screenSize.width)
event("Focusing on point (\(focusPoint.x),\(focusPoint.y))")
log("Focusing on point (\(focusPoint.x),\(focusPoint.y))")
if let device = cameraDevice {
do {
try device.lockForConfiguration()
@@ -221,7 +221,4 @@ class CameraView: UIView {
}
}
extension CameraView: Logger {
static let logToken = "CameraView"
}
extension CameraView: Logger { }

View File

@@ -7,6 +7,7 @@ Photo capture delegate.
import AVFoundation
import Photos
import UIKit
protocol PhotoCaptureHandlerDelegate {
@@ -32,13 +33,13 @@ extension PhotoCaptureHandler: AVCapturePhotoCaptureDelegate {
func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) {
guard error == nil else {
print("PhotoCaptureHandler: \(error!)")
log("PhotoCaptureHandler: \(error!)")
delegate?.didCapture(nil)
return
}
guard let cgImage = photo.cgImageRepresentation()?.takeUnretainedValue() else {
print("PhotoCaptureHandler: No image captured")
log("PhotoCaptureHandler: No image captured")
delegate?.didCapture(nil)
return
}
@@ -49,3 +50,7 @@ extension PhotoCaptureHandler: AVCapturePhotoCaptureDelegate {
}
}
}
extension PhotoCaptureHandler: Logger {
}