質問編集履歴
4
コード
test
CHANGED
File without changes
|
test
CHANGED
@@ -15,6 +15,8 @@
|
|
15
15
|
|
16
16
|
|
17
17
|
```Swift
|
18
|
+
|
19
|
+
|
18
20
|
|
19
21
|
//
|
20
22
|
|
3
コード
test
CHANGED
File without changes
|
test
CHANGED
@@ -11,3 +11,149 @@
|
|
11
11
|
![イメージ説明](4ecfc5dc1fcf9e6f5d82b63324dd5770.png)
|
12
12
|
|
13
13
|
![イメージ説明](af53316dfde366164271a75053f0dd70.png)
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
```Swift
|
18
|
+
|
19
|
+
//
|
20
|
+
|
21
|
+
// ViewController.swift
|
22
|
+
|
23
|
+
// OridoAI
|
24
|
+
|
25
|
+
//
|
26
|
+
|
27
|
+
// Created by Mamiko Hirose2 on 2020/01/02.
|
28
|
+
|
29
|
+
// Copyright © 2020 Mamiko Hirose2. All rights reserved.
|
30
|
+
|
31
|
+
//
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
import UIKit
|
36
|
+
|
37
|
+
import CoreML
|
38
|
+
|
39
|
+
import Vision
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
@IBOutlet weak var imageDisplay: UIImageView!
|
48
|
+
|
49
|
+
@IBOutlet weak var predictionDisplay: UITextView!
|
50
|
+
|
51
|
+
var imagePicker: UIImagePickerController!
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
override func viewDidLoad() {
|
56
|
+
|
57
|
+
super.viewDidLoad()
|
58
|
+
|
59
|
+
// Do any additional setup after loading the view.
|
60
|
+
|
61
|
+
imagePicker = UIImagePickerController()
|
62
|
+
|
63
|
+
imagePicker.delegate = self
|
64
|
+
|
65
|
+
imagePicker.sourceType = .camera
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
@IBAction func takePhoto(_ sender: Any) {
|
72
|
+
|
73
|
+
present(imagePicker, animated: true, completion: nil)
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
|
80
|
+
|
81
|
+
imageDisplay.image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage
|
82
|
+
|
83
|
+
imagePicker.dismiss(animated: true, completion: nil)
|
84
|
+
|
85
|
+
imagePrediction(image: (info[UIImagePickerController.InfoKey.originalImage] as? UIImage)!)
|
86
|
+
|
87
|
+
}
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
func imagePrediction(image: UIImage) {
|
92
|
+
|
93
|
+
guard let model = try? VNCoreMLModel(for: orido_cnn().model) else {
|
94
|
+
|
95
|
+
fatalError("Model not found")
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
let request = VNCoreMLRequest(model: model){
|
102
|
+
|
103
|
+
[week self] request, error inputView
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
guard let results = request.results as? [VNClassificationObservation],
|
108
|
+
|
109
|
+
let firstResult = result else {
|
110
|
+
|
111
|
+
fatalError("No results found")
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
DispatchQueue.main.async {
|
118
|
+
|
119
|
+
self?.predictionDisplay.text = "Accuracy: = (Int(firstResult.confidence * 100))% \n\nラベル: ((firstResult.identifier))"
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
guard let ciImage = CIImage(image: image) else {
|
128
|
+
|
129
|
+
fatalError("Can't convert image.")
|
130
|
+
|
131
|
+
}
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
let imageHandler = VNImageRequestHandler(ciImage : ciImage)
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
DispatchQueue.global(qos: .userInteractive).async {
|
140
|
+
|
141
|
+
do{
|
142
|
+
|
143
|
+
try imageHandler.perform([request])
|
144
|
+
|
145
|
+
} catch {
|
146
|
+
|
147
|
+
print("Error")
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
}
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
``
|
2
画像交換
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
作成したプログラムをビルドしようとしたらエラーが出ました。
|
2
2
|
|
3
|
-
どのように修復すればよろしいでしょうか。
|
3
|
+
どのように修復すればよろしいでしょうか。
|
4
4
|
|
5
|
-
![イメージ説明](4
|
5
|
+
![イメージ説明](188e485e09ccdfba4cd67fe29806e132.png)
|
6
6
|
|
7
|
-
![イメージ説明](
|
7
|
+
![イメージ説明](7b2f3fff21e47f21830561732e6bd9f6.png)
|
8
8
|
|
9
|
-
イメージ説明
|
9
|
+
![イメージ説明](6dee7ed7cb3e1520d109093b1cb74ad9.png)
|
10
10
|
|
11
|
-
|
11
|
+
![イメージ説明](4ecfc5dc1fcf9e6f5d82b63324dd5770.png)
|
12
|
+
|
13
|
+
![イメージ説明](af53316dfde366164271a75053f0dd70.png)
|
1
画像挿入
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
作成したプログラムをビルドしようとしたらエラーが出ました。
|
2
2
|
|
3
|
-
どのように修復すればよろしいでしょうか。![イメ
|
3
|
+
どのように修復すればよろしいでしょうか。![イメージ説明](e00aeee331b04282b11cd147b0d9f5f0.png)340aaf4cd1ad275555f0f1865bf94ee8.png)
|
4
4
|
|
5
5
|
![イメージ説明](4a127f6ccdbc12408cbcdffced09f68b.png)
|
6
6
|
|