質問編集履歴
2
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -158,6 +158,10 @@
|
|
158
158
|
|
159
159
|
|
160
160
|
|
161
|
+
レビュワー側では以下のprint("isDepthDataDeliveryEnabled: FALSE")の部分が実行されてしまっている様です。ポートレイト対応機種ならphotoOutput!.isDepthDataDeliveryEnabledはtrueとなっていると思われるのですが、ここが実行されてしまう可能性は何かあるのでしょうか?もしわかる方がいたら教えて頂きたいです。。。
|
162
|
+
|
163
|
+
|
164
|
+
|
161
165
|
```swift
|
162
166
|
|
163
167
|
import UIKit
|
1
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -149,3 +149,215 @@
|
|
149
149
|
}
|
150
150
|
|
151
151
|
```
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
ーーーーーーーーーーーーーーーーーーー変更後ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
```swift
|
162
|
+
|
163
|
+
import UIKit
|
164
|
+
|
165
|
+
import AVFoundation
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
class ViewController: UIViewController {
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
private var captureSession = AVCaptureSession()
|
174
|
+
|
175
|
+
private var photoOutput : AVCapturePhotoOutput?
|
176
|
+
|
177
|
+
private var currentDevice : AVCaptureDevice?
|
178
|
+
|
179
|
+
private var videoDeviceInput : AVCaptureDeviceInput!
|
180
|
+
|
181
|
+
private var photoQualityPrioritizationMode: AVCapturePhotoOutput.QualityPrioritization = .balanced
|
182
|
+
|
183
|
+
private let videoDeviceDiscoverySession = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInWideAngleCamera, .builtInDualCamera, .builtInTrueDepthCamera],
|
184
|
+
|
185
|
+
mediaType: .video, position: .unspecified)
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
override func viewDidLoad() {
|
190
|
+
|
191
|
+
super.viewDidLoad()
|
192
|
+
|
193
|
+
captureSession.sessionPreset = AVCaptureSession.Preset.photo
|
194
|
+
|
195
|
+
setupCaptureSession(withPosition: AVCaptureDevice.Position.front)
|
196
|
+
|
197
|
+
action()
|
198
|
+
|
199
|
+
}
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
func setupCaptureSession(withPosition cameraPosition: AVCaptureDevice.Position) {
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
self.captureSession = AVCaptureSession()
|
208
|
+
|
209
|
+
photoOutput = AVCapturePhotoOutput()
|
210
|
+
|
211
|
+
guard let photoOutput = photoOutput else { return }
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
do {
|
216
|
+
|
217
|
+
captureSession.beginConfiguration()
|
218
|
+
|
219
|
+
captureSession.sessionPreset = .photo
|
220
|
+
|
221
|
+
let devices = self.videoDeviceDiscoverySession.devices
|
222
|
+
|
223
|
+
for device in devices {
|
224
|
+
|
225
|
+
if device.position == cameraPosition {
|
226
|
+
|
227
|
+
currentDevice = device
|
228
|
+
|
229
|
+
}
|
230
|
+
|
231
|
+
}
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
guard let videoDevice = currentDevice else { return }
|
236
|
+
|
237
|
+
videoDeviceInput = try AVCaptureDeviceInput(device: videoDevice)
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
if captureSession.canAddInput(videoDeviceInput) {
|
242
|
+
|
243
|
+
captureSession.addInput(videoDeviceInput)
|
244
|
+
|
245
|
+
}
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
} catch {
|
252
|
+
|
253
|
+
print(error)
|
254
|
+
|
255
|
+
}
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
// add audio input to a capture session
|
260
|
+
|
261
|
+
let audioDevice = AVCaptureDevice.default(for: AVMediaType.audio)
|
262
|
+
|
263
|
+
let audioInput = try! AVCaptureDeviceInput(device: audioDevice!)
|
264
|
+
|
265
|
+
self.captureSession.addInput(audioInput)
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
if captureSession.canAddOutput(photoOutput) {
|
270
|
+
|
271
|
+
captureSession.addOutput(photoOutput)
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
photoOutput.isHighResolutionCaptureEnabled = true
|
276
|
+
|
277
|
+
photoOutput.isLivePhotoCaptureEnabled = photoOutput.isLivePhotoCaptureSupported
|
278
|
+
|
279
|
+
photoOutput.isDepthDataDeliveryEnabled = photoOutput.isDepthDataDeliverySupported
|
280
|
+
|
281
|
+
print("photoOutput.isDepthDataDeliverySupported:", photoOutput.isDepthDataDeliverySupported)
|
282
|
+
|
283
|
+
photoOutput.isPortraitEffectsMatteDeliveryEnabled = photoOutput.isPortraitEffectsMatteDeliverySupported
|
284
|
+
|
285
|
+
print("photoOutput.isPortraitEffectsMatteDeliverySupported:", photoOutput.isPortraitEffectsMatteDeliverySupported)
|
286
|
+
|
287
|
+
photoOutput.enabledSemanticSegmentationMatteTypes = photoOutput.availableSemanticSegmentationMatteTypes
|
288
|
+
|
289
|
+
print("photoOutput.availableSemanticSegmentationMatteTypes:", photoOutput.availableSemanticSegmentationMatteTypes)
|
290
|
+
|
291
|
+
photoOutput.maxPhotoQualityPrioritization = .quality
|
292
|
+
|
293
|
+
captureSession.commitConfiguration()
|
294
|
+
|
295
|
+
}
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
self.captureSession.startRunning()
|
300
|
+
|
301
|
+
}
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
func action(){
|
306
|
+
|
307
|
+
var settings = AVCapturePhotoSettings()
|
308
|
+
|
309
|
+
settings = AVCapturePhotoSettings(format: [AVVideoCodecKey: AVVideoCodecType.hevc])
|
310
|
+
|
311
|
+
settings.flashMode = .auto
|
312
|
+
|
313
|
+
settings.isHighResolutionPhotoEnabled = true
|
314
|
+
|
315
|
+
settings.previewPhotoFormat = [kCVPixelBufferPixelFormatTypeKey as String: settings.__availablePreviewPhotoPixelFormatTypes.first!]
|
316
|
+
|
317
|
+
settings.isDepthDataDeliveryEnabled = true
|
318
|
+
|
319
|
+
settings.isPortraitEffectsMatteDeliveryEnabled = true
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
if !(self.photoOutput?.enabledSemanticSegmentationMatteTypes.isEmpty)! {
|
324
|
+
|
325
|
+
settings.enabledSemanticSegmentationMatteTypes = self.photoOutput?.enabledSemanticSegmentationMatteTypes ?? [AVSemanticSegmentationMatte.MatteType]()
|
326
|
+
|
327
|
+
} else {
|
328
|
+
|
329
|
+
print("enabledSemanticSegmentationMatteTypes is Empty")
|
330
|
+
|
331
|
+
}
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
settings.photoQualityPrioritization = self.photoQualityPrioritizationMode
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
if (!photoOutput!.isDepthDataDeliveryEnabled) {
|
342
|
+
|
343
|
+
print("isDepthDataDeliveryEnabled: FALSE")
|
344
|
+
|
345
|
+
} else {
|
346
|
+
|
347
|
+
print("isDepthDataDeliveryEnabled: TRUE")
|
348
|
+
|
349
|
+
}
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
}
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
}
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
```
|