- Remove Xcode and Regnet classifier
- Add MobileNet classifier - Add average color for each cap - Add option to show average colors in mosaic
This commit is contained in:
@ -36,6 +36,19 @@ class GridViewController: UIViewController {
|
||||
return true
|
||||
}
|
||||
|
||||
private var isShowingColors = false
|
||||
|
||||
@IBAction func toggleAverageColor(_ sender: Any) {
|
||||
isShowingColors = !isShowingColors
|
||||
for (tile, view) in installedTiles {
|
||||
if isShowingColors {
|
||||
view.image = nil
|
||||
} else {
|
||||
view.image = Cap.tileImage(tile: tile)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
@ -131,10 +144,15 @@ class GridViewController: UIViewController {
|
||||
private func makeTile(_ tile: Int) {
|
||||
let view = RoundedImageView(frame: frame(for: tile))
|
||||
myView.addSubview(view)
|
||||
view.image = Cap.tileImage(tile: tile)
|
||||
view.backgroundColor = Cap.tileColor(tile: tile)
|
||||
// Only set image if images are shown
|
||||
if !isShowingColors {
|
||||
view.image = Cap.tileImage(tile: tile)
|
||||
}
|
||||
|
||||
installedTiles[tile] = view
|
||||
}
|
||||
|
||||
|
||||
private func frame(for tile: Int) -> CGRect {
|
||||
let row = tile / columns
|
||||
let column = tile - row * columns
|
||||
@ -144,12 +162,20 @@ class GridViewController: UIViewController {
|
||||
}
|
||||
|
||||
private func switchTiles(oldTile: Int, newTile: Int) {
|
||||
if oldTile != newTile {
|
||||
Cap.switchTiles(oldTile, newTile)
|
||||
guard oldTile != newTile else {
|
||||
clearTileSelection()
|
||||
return
|
||||
}
|
||||
Cap.switchTiles(oldTile, newTile)
|
||||
// Switch cap colors
|
||||
installedTiles[oldTile]?.backgroundColor = Cap.tileColor(tile: oldTile)
|
||||
installedTiles[newTile]?.backgroundColor = Cap.tileColor(tile: newTile)
|
||||
if !isShowingColors {
|
||||
installedTiles[oldTile]?.image = Cap.tileImage(tile: oldTile)
|
||||
installedTiles[newTile]?.image = Cap.tileImage(tile: newTile)
|
||||
}
|
||||
clearTileSelection()
|
||||
|
||||
}
|
||||
|
||||
private func clearTileSelection() {
|
||||
|
@ -56,7 +56,19 @@ class ImageSelector: UIViewController {
|
||||
private func downloadImages() {
|
||||
images = [UIImage?](repeating: nil, count: cap.count)
|
||||
event("\(cap.count) images for cap \(cap.id)")
|
||||
for number in 0..<cap.count {
|
||||
if let image = cap.image {
|
||||
self.images[0] = image
|
||||
self.collection.reloadItems(at: [IndexPath(row: 0, section: 0)])
|
||||
} else {
|
||||
cap.downloadImage { mainImage in
|
||||
self.images[0] = mainImage
|
||||
self.collection.reloadItems(at: [IndexPath(row: 0, section: 0)])
|
||||
}
|
||||
}
|
||||
guard cap.count > 0 else {
|
||||
return
|
||||
}
|
||||
for number in 1..<cap.count {
|
||||
cap.downloadImage(number) { image in
|
||||
self.images[number] = image
|
||||
self.collection.reloadItems(at: [IndexPath(row: number, section: 0)])
|
||||
@ -67,43 +79,11 @@ class ImageSelector: UIViewController {
|
||||
// MARK: Select
|
||||
|
||||
private func selectedImage(nr: Int) {
|
||||
guard images[nr] != nil else {
|
||||
guard let image = images[nr] else {
|
||||
return
|
||||
}
|
||||
|
||||
let tempId = cap.count
|
||||
let tempFile = "/Images/\(cap.id)/\(cap.id)-\(tempId).jpg"
|
||||
let oldFile = "/Images/\(cap.id)/\(cap.id)-0.jpg"
|
||||
let newFile = "/Images/\(cap.id)/\(cap.id)-\(nr).jpg"
|
||||
guard oldFile != newFile else {
|
||||
return
|
||||
}
|
||||
DropboxController.shared.move(file: oldFile, to: tempFile) { success in
|
||||
guard success else {
|
||||
self.error("Could not move \(oldFile) to \(tempFile)")
|
||||
return
|
||||
}
|
||||
DropboxController.shared.move(file: newFile, to: oldFile) { success in
|
||||
guard success else {
|
||||
self.error("Could not move \(newFile) to \(oldFile)")
|
||||
return
|
||||
}
|
||||
DropboxController.shared.move(file: tempFile, to: newFile) { success in
|
||||
if !success {
|
||||
self.error("Could not move \(tempFile) to \(newFile)")
|
||||
}
|
||||
self.finish(with: nr)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func finish(with nr: Int) {
|
||||
let image = images[nr]!
|
||||
guard cap.save(mainImage: image) else {
|
||||
return
|
||||
}
|
||||
event("Successfully switched image")
|
||||
cap.setMainImage(to: nr, image: image)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,21 +24,22 @@ class SettingsController: UITableViewController {
|
||||
|
||||
@IBOutlet weak var countsLabel: UILabel!
|
||||
|
||||
private var nameFileChanges = false
|
||||
|
||||
private var isUpdatingCounts = false
|
||||
|
||||
private var isUploadingNameFile = false
|
||||
|
||||
private var isUpdatingThumbnails = false
|
||||
|
||||
private var isUpdatingColors = false
|
||||
|
||||
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
|
||||
return .portrait
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
}
|
||||
|
||||
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
updateDropboxStatus()
|
||||
updateNameFileStats()
|
||||
@ -49,7 +50,7 @@ class SettingsController: UITableViewController {
|
||||
|
||||
override func viewDidAppear(_ animated: Bool) {
|
||||
super.viewDidAppear(animated)
|
||||
setAccessories()
|
||||
setClassifierChoice(Persistence.useMobileNet)
|
||||
}
|
||||
|
||||
private func updateThumbnails() {
|
||||
@ -60,6 +61,16 @@ class SettingsController: UITableViewController {
|
||||
isUpdatingThumbnails = false
|
||||
}
|
||||
|
||||
private func updateColors() {
|
||||
isUpdatingColors = true
|
||||
Cap.shouldSave = false
|
||||
for cap in Cap.all.values {
|
||||
cap.makeAverageColor()
|
||||
}
|
||||
Cap.shouldSave = true
|
||||
isUpdatingColors = false
|
||||
}
|
||||
|
||||
private func updateDatabaseStats() {
|
||||
let totalCaps = Cap.totalCapCount
|
||||
totalCapsLabel.text = "\(totalCaps) caps"
|
||||
@ -75,7 +86,6 @@ class SettingsController: UITableViewController {
|
||||
private func updateNameFileStats() {
|
||||
let capCount = Cap.totalCapCount - Persistence.lastUploadedCapCount
|
||||
let imageCount = Cap.imageCount - Persistence.lastUploadedImageCount
|
||||
nameFileChanges = capCount > 0 || imageCount > 0
|
||||
databaseUpdatesLabel.text = "\(capCount) new caps and \(imageCount) new images"
|
||||
}
|
||||
|
||||
@ -83,36 +93,34 @@ class SettingsController: UITableViewController {
|
||||
dropboxAccountLabel.text = DropboxController.shared.isEnabled ? "Sign out" : "Sign in"
|
||||
}
|
||||
|
||||
private func setAccessories() {
|
||||
tableView.cellForRow(at: IndexPath(row: 0, section: 2))?.accessoryType = Persistence.squeezenet ? .checkmark : .none
|
||||
tableView.cellForRow(at: IndexPath(row: 1, section: 2))?.accessoryType = Persistence.resnet ? .checkmark : .none
|
||||
tableView.cellForRow(at: IndexPath(row: 2, section: 2))?.accessoryType = Persistence.xcode ? .checkmark : .none
|
||||
private func setClassifierChoice(_ useMobileNet: Bool) {
|
||||
tableView.cellForRow(at: IndexPath(row: 0, section: 0))?.accessoryType = useMobileNet ? .checkmark : .none
|
||||
}
|
||||
|
||||
private func toggleClassifier(index: Int) {
|
||||
switch index {
|
||||
case 0: Persistence.squeezenet = !Persistence.squeezenet
|
||||
case 1: Persistence.resnet = !Persistence.resnet
|
||||
case 2: Persistence.xcode = !Persistence.xcode
|
||||
default:
|
||||
return
|
||||
}
|
||||
setAccessories()
|
||||
private func toggleClassifier() {
|
||||
let newValue = !Persistence.useMobileNet
|
||||
Persistence.useMobileNet = newValue
|
||||
setClassifierChoice(newValue)
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, shouldHighlightRowAt indexPath: IndexPath) -> Bool {
|
||||
switch indexPath.section {
|
||||
case 0: // Mosaic
|
||||
case 0: // Choose models
|
||||
return true
|
||||
case 1: // Database
|
||||
return indexPath.row == 2 && nameFileChanges
|
||||
case 2: // Choose models
|
||||
case 1: // Mosaic
|
||||
return true
|
||||
case 2: // Database
|
||||
return indexPath.row == 2 && !isUploadingNameFile
|
||||
case 3: // Refresh
|
||||
if indexPath.row == 0 {
|
||||
switch indexPath.row {
|
||||
case 0:
|
||||
return !isUpdatingCounts
|
||||
} else {
|
||||
case 1:
|
||||
return !isUpdatingThumbnails
|
||||
case 2:
|
||||
return !isUpdatingColors
|
||||
default:
|
||||
return false
|
||||
}
|
||||
case 4: // Dropbox account
|
||||
return true
|
||||
@ -124,17 +132,22 @@ class SettingsController: UITableViewController {
|
||||
|
||||
override func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
|
||||
switch indexPath.section {
|
||||
case 0: // Mosaic
|
||||
case 0: // Choose models
|
||||
return indexPath
|
||||
case 1: // Database
|
||||
return (indexPath.row == 2 && nameFileChanges) ? indexPath : nil
|
||||
case 2: // Choose models
|
||||
case 1: // Mosaic
|
||||
return indexPath
|
||||
case 2: // Database
|
||||
return (indexPath.row == 2 && !isUploadingNameFile) ? indexPath : nil
|
||||
case 3: // Refresh count
|
||||
if indexPath.row == 0 {
|
||||
return isUpdatingCounts ? nil : indexPath
|
||||
} else {
|
||||
switch indexPath.row {
|
||||
case 0:
|
||||
return isUpdatingCounts ? nil : indexPath
|
||||
case 1:
|
||||
return isUpdatingThumbnails ? nil : indexPath
|
||||
case 2:
|
||||
return isUpdatingColors ? nil : indexPath
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
case 4: // Dropbox account
|
||||
return indexPath
|
||||
@ -147,17 +160,22 @@ class SettingsController: UITableViewController {
|
||||
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||
tableView.deselectRow(at: indexPath, animated: true)
|
||||
switch indexPath.section {
|
||||
case 1: // Upload
|
||||
if indexPath.row == 2 && nameFileChanges {
|
||||
case 0: // Choose models
|
||||
toggleClassifier()
|
||||
case 2: // Upload
|
||||
if indexPath.row == 2 && !isUploadingNameFile {
|
||||
uploadNameFile()
|
||||
}
|
||||
case 2: // Choose models
|
||||
toggleClassifier(index: indexPath.row)
|
||||
case 3: // Refresh count
|
||||
if indexPath.row == 0 {
|
||||
switch indexPath.row {
|
||||
case 0:
|
||||
updateCounts()
|
||||
} else {
|
||||
case 1:
|
||||
updateThumbnails()
|
||||
case 2:
|
||||
updateColors()
|
||||
default:
|
||||
break
|
||||
}
|
||||
default:
|
||||
break
|
||||
@ -205,7 +223,10 @@ class SettingsController: UITableViewController {
|
||||
}
|
||||
|
||||
private func uploadNameFile() {
|
||||
event("Uploading name file")
|
||||
isUploadingNameFile = true
|
||||
Cap.saveAndUpload() { _ in
|
||||
self.isUploadingNameFile = false
|
||||
self.updateNameFileStats()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user