質問編集履歴
3
見やすくした
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,14 +4,6 @@
|
|
4
4
|
|
5
5
|
|
6
6
|
|
7
|
-
package com.google.android.exoplayer2.demo;
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
7
|
public class PlayerActivity extends Activity implements OnClickListener, ExoPlayer.EventListener
|
16
8
|
|
17
9
|
{
|
@@ -80,7 +72,7 @@
|
|
80
72
|
|
81
73
|
|
82
74
|
|
83
|
-
|
75
|
+
|
84
76
|
|
85
77
|
private TextureView.SurfaceTextureListener mCameraSurfaceTextureListener
|
86
78
|
|
@@ -144,7 +136,7 @@
|
|
144
136
|
|
145
137
|
public void onOpened(@NonNull CameraDevice cameraDevice) {
|
146
138
|
|
147
|
-
|
139
|
+
|
148
140
|
|
149
141
|
}
|
150
142
|
|
@@ -190,6 +182,10 @@
|
|
190
182
|
|
191
183
|
private void startPreview() {
|
192
184
|
|
185
|
+
|
186
|
+
|
187
|
+
//多分ここの作業が足りてなかった
|
188
|
+
|
193
189
|
try {
|
194
190
|
|
195
191
|
SurfaceTexture texture = mTextureView.getSurfaceTexture();
|
@@ -248,6 +244,70 @@
|
|
248
244
|
|
249
245
|
|
250
246
|
|
247
|
+
private void startPreview2() {
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
//多分ここの作業が足りてなかった
|
252
|
+
|
253
|
+
try {
|
254
|
+
|
255
|
+
SurfaceTexture texture = mCameraTextureView.getSurfaceTexture();
|
256
|
+
|
257
|
+
assert texture != null;
|
258
|
+
|
259
|
+
texture2.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());
|
260
|
+
|
261
|
+
mCameraPreviewBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
|
262
|
+
|
263
|
+
Surface previewCameraSurface = new Surface(texture2);
|
264
|
+
|
265
|
+
mCameraPreviewBuilder.addTarget(previewCameraSurface);
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
mCameraDevice.createCaptureSession(Collections.singletonList(previewCameraSurface),
|
270
|
+
|
271
|
+
new CameraCaptureSession.StateCallback() {
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
@Override
|
276
|
+
|
277
|
+
public void onClosed(CameraCaptureSession session) {
|
278
|
+
|
279
|
+
}
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
@Override
|
284
|
+
|
285
|
+
public void onReady(CameraCaptureSession session) {
|
286
|
+
|
287
|
+
}
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
@Override
|
292
|
+
|
293
|
+
public void onConfigured(@NonNull CameraCaptureSession session) {
|
294
|
+
|
295
|
+
mCameraPreviewSession = session;
|
296
|
+
|
297
|
+
}
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
}, mBackgroundHandler);
|
302
|
+
|
303
|
+
} catch (CameraAccessException e) {
|
304
|
+
|
305
|
+
}
|
306
|
+
|
307
|
+
}
|
308
|
+
|
309
|
+
|
310
|
+
|
251
311
|
|
252
312
|
|
253
313
|
private void startRecordingVideo() {
|
@@ -340,7 +400,7 @@
|
|
340
400
|
|
341
401
|
if (faces != null && mode != null)
|
342
402
|
|
343
|
-
|
403
|
+
|
344
404
|
|
345
405
|
for(Face face: faces) {
|
346
406
|
|
@@ -444,4 +504,6 @@
|
|
444
504
|
|
445
505
|
|
446
506
|
|
507
|
+
|
508
|
+
|
447
509
|
```
|
2
コードの編集
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
```java
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
package com.google.android.exoplayer2.demo;
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
|
1
15
|
public class PlayerActivity extends Activity implements OnClickListener, ExoPlayer.EventListener
|
2
16
|
|
3
17
|
{
|
@@ -427,3 +441,7 @@
|
|
427
441
|
}
|
428
442
|
|
429
443
|
}
|
444
|
+
|
445
|
+
|
446
|
+
|
447
|
+
```
|
1
コードをコンパクトにしました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,7 +1,3 @@
|
|
1
|
-
```java
|
2
|
-
|
3
|
-
|
4
|
-
|
5
1
|
public class PlayerActivity extends Activity implements OnClickListener, ExoPlayer.EventListener
|
6
2
|
|
7
3
|
{
|
@@ -30,8 +26,6 @@
|
|
30
26
|
|
31
27
|
int width, int height) {
|
32
28
|
|
33
|
-
openCamera(width, height);
|
34
|
-
|
35
29
|
}
|
36
30
|
|
37
31
|
|
@@ -72,6 +66,8 @@
|
|
72
66
|
|
73
67
|
|
74
68
|
|
69
|
+
|
70
|
+
|
75
71
|
private TextureView.SurfaceTextureListener mCameraSurfaceTextureListener
|
76
72
|
|
77
73
|
= new TextureView.SurfaceTextureListener() {
|
@@ -96,8 +92,6 @@
|
|
96
92
|
|
97
93
|
configureTransform(width, height);
|
98
94
|
|
99
|
-
|
100
|
-
|
101
95
|
canvass=mCameraTextureView.lockCanvas();
|
102
96
|
|
103
97
|
}
|
@@ -126,7 +120,7 @@
|
|
126
120
|
|
127
121
|
|
128
122
|
|
129
|
-
|
123
|
+
|
130
124
|
|
131
125
|
private CameraDevice.StateCallback mStateCallback = new CameraDevice.StateCallback() {
|
132
126
|
|
@@ -136,141 +130,275 @@
|
|
136
130
|
|
137
131
|
public void onOpened(@NonNull CameraDevice cameraDevice) {
|
138
132
|
|
139
|
-
|
140
|
-
|
141
133
|
|
142
134
|
|
135
|
+
}
|
136
|
+
|
137
|
+
};
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
private CaptureRequest.Builder mPreviewBuilder;
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
public void onCreate(Bundle savedInstanceState) {
|
148
|
+
|
149
|
+
super.onCreate(savedInstanceState);
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
setContentView(R.layout.player_activity);
|
154
|
+
|
155
|
+
mTextureView = (AutoFitTextureView) findViewById(R.id.texture);
|
156
|
+
|
157
|
+
mCameraTextureView = (CameraFaceLineTextureView) findViewById(R.id.texture2);
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
@Override
|
162
|
+
|
143
|
-
|
163
|
+
public void onResume() {
|
144
|
-
|
145
|
-
|
146
|
-
|
164
|
+
|
147
|
-
|
165
|
+
super.onResume();
|
166
|
+
|
148
|
-
|
167
|
+
mTextureView.setSurfaceTextureListener(mSurfaceTextureListener);
|
168
|
+
|
149
|
-
|
169
|
+
mCameraTextureView.setSurfaceTextureListener(mCameraSurfaceTextureListener);
|
170
|
+
|
150
|
-
|
171
|
+
}
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
|
176
|
+
|
151
|
-
|
177
|
+
private void startPreview() {
|
178
|
+
|
152
|
-
|
179
|
+
try {
|
180
|
+
|
181
|
+
SurfaceTexture texture = mTextureView.getSurfaceTexture();
|
182
|
+
|
183
|
+
assert texture != null;
|
184
|
+
|
153
|
-
|
185
|
+
texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());
|
186
|
+
|
187
|
+
mPreviewBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
|
188
|
+
|
189
|
+
Surface previewSurface = new Surface(texture);
|
190
|
+
|
191
|
+
mPreviewBuilder.addTarget(previewSurface);
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
mCameraDevice.createCaptureSession(Collections.singletonList(previewSurface),
|
196
|
+
|
197
|
+
new CameraCaptureSession.StateCallback() {
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
@Override
|
202
|
+
|
203
|
+
public void onClosed(CameraCaptureSession session) {
|
204
|
+
|
205
|
+
}
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
@Override
|
210
|
+
|
211
|
+
public void onReady(CameraCaptureSession session) {
|
212
|
+
|
213
|
+
}
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
@Override
|
218
|
+
|
219
|
+
public void onConfigured(@NonNull CameraCaptureSession session) {
|
220
|
+
|
221
|
+
mPreviewSession = session;
|
222
|
+
|
223
|
+
}
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
}, mBackgroundHandler);
|
228
|
+
|
229
|
+
} catch (CameraAccessException e) {
|
230
|
+
|
231
|
+
}
|
232
|
+
|
233
|
+
}
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
private void startRecordingVideo() {
|
240
|
+
|
241
|
+
if (null == mCameraDevice || !mTextureView.isAvailable() || null == mPreviewSize) {
|
242
|
+
|
243
|
+
return;
|
244
|
+
|
245
|
+
}
|
246
|
+
|
247
|
+
try {
|
248
|
+
|
249
|
+
SurfaceTexture texture = mTextureView.getSurfaceTexture();
|
250
|
+
|
251
|
+
assert texture != null;
|
252
|
+
|
253
|
+
texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
mPreviewBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
|
258
|
+
|
259
|
+
List<Surface> surfaces = new ArrayList<>();
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
// Set up Surface for the camera preview
|
264
|
+
|
265
|
+
Surface previewSurface = new Surface(texture);
|
266
|
+
|
267
|
+
surfaces.add(previewSurface);
|
268
|
+
|
269
|
+
mPreviewBuilder.addTarget(previewSurface);
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
// Set up Surface for the MediaRecorder
|
274
|
+
|
275
|
+
Surface recorderSurface = mMediaRecorder.getSurface();
|
276
|
+
|
277
|
+
surfaces.add(recorderSurface);
|
278
|
+
|
279
|
+
mPreviewBuilder.addTarget(recorderSurface);
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
// Start a capture session
|
284
|
+
|
285
|
+
// Once the session starts, we can update the UI and start recording
|
286
|
+
|
287
|
+
mCameraDevice.createCaptureSession(surfaces, new CameraCaptureSession.StateCallback() {
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
@Override
|
292
|
+
|
293
|
+
public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) {
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
mPreviewSession = cameraCaptureSession;
|
154
298
|
|
155
299
|
}
|
156
300
|
|
301
|
+
}, mBackgroundHandler);
|
302
|
+
|
303
|
+
} catch (CameraAccessException | IOException e) {
|
304
|
+
|
305
|
+
}
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
}
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
private CameraCaptureSession.CaptureCallback mCaptureCallback
|
316
|
+
|
317
|
+
= new CameraCaptureSession.CaptureCallback() {
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
private void process(CaptureResult result) {
|
322
|
+
|
323
|
+
Integer mode = result.get(CaptureResult.STATISTICS_FACE_DETECT_MODE);
|
324
|
+
|
325
|
+
Face[] faces = result.get(CaptureResult.STATISTICS_FACES);
|
326
|
+
|
327
|
+
if (faces != null && mode != null)
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
for(Face face: faces) {
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
Rect r=faceRect2PixelRect(face);
|
336
|
+
|
337
|
+
drawFace(r,Color.argb(255, 255, 0, 255));
|
338
|
+
|
339
|
+
}
|
340
|
+
|
341
|
+
Log.e("tag", "faces : " + faces.length + " , mode : " + mode);
|
342
|
+
|
343
|
+
}
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
@Override
|
348
|
+
|
349
|
+
public void onCaptureProgressed(CameraCaptureSession session, CaptureRequest request,
|
350
|
+
|
351
|
+
CaptureResult partialResult) {
|
352
|
+
|
353
|
+
process(partialResult);
|
354
|
+
|
355
|
+
}
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
@Override
|
360
|
+
|
361
|
+
public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request,
|
362
|
+
|
363
|
+
TotalCaptureResult result) {
|
364
|
+
|
365
|
+
process(result);
|
366
|
+
|
367
|
+
}
|
368
|
+
|
369
|
+
};
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
private Paint paint = new Paint();
|
376
|
+
|
377
|
+
public void drawFace(Rect rect1, int color) {
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
try {
|
382
|
+
|
383
|
+
if (canvass != null) {
|
384
|
+
|
385
|
+
try {
|
386
|
+
|
387
|
+
canvass.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
|
388
|
+
|
389
|
+
paint.setColor(color);
|
390
|
+
|
391
|
+
canvass.drawRect(rect1,paint);
|
392
|
+
|
393
|
+
} finally {
|
394
|
+
|
395
|
+
mCameraTextureView.unlockCanvasAndPost(canvass);
|
396
|
+
|
397
|
+
}
|
398
|
+
|
157
399
|
}
|
158
400
|
|
159
|
-
}
|
160
|
-
|
161
|
-
};
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
private CaptureRequest.Builder mPreviewBuilder;
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
public void onCreate(Bundle savedInstanceState) {
|
172
|
-
|
173
|
-
super.onCreate(savedInstanceState);
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
setContentView(R.layout.player_activity);
|
178
|
-
|
179
|
-
//撮影に使うViewを取得
|
180
|
-
|
181
|
-
mTextureView = (AutoFitTextureView) findViewById(R.id.texture);
|
182
|
-
|
183
|
-
mCameraTextureView = (CameraFaceLineTextureView) findViewById(R.id.texture2);
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
@Override
|
188
|
-
|
189
|
-
public void onResume() {
|
190
|
-
|
191
|
-
super.onResume();
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
if (mTextureView.isAvailable()) {
|
196
|
-
|
197
|
-
openCamera(mTextureView.getWidth(), mTextureView.getHeight());
|
198
|
-
|
199
|
-
} else {
|
200
|
-
|
201
|
-
mTextureView.setSurfaceTextureListener(mSurfaceTextureListener);
|
202
|
-
|
203
|
-
mCameraTextureView.setSurfaceTextureListener(mCameraSurfaceTextureListener);
|
204
|
-
|
205
|
-
}
|
206
|
-
|
207
|
-
}
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
private void startPreview() {
|
214
|
-
|
215
|
-
if (null == mCameraDevice || !mTextureView.isAvailable() || null == mPreviewSize) {
|
216
|
-
|
217
|
-
return;
|
218
|
-
|
219
|
-
}
|
220
|
-
|
221
|
-
try {
|
222
|
-
|
223
|
-
SurfaceTexture texture = mTextureView.getSurfaceTexture();
|
224
|
-
|
225
|
-
assert texture != null;
|
226
|
-
|
227
|
-
texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());
|
228
|
-
|
229
|
-
mPreviewBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
|
230
|
-
|
231
|
-
Surface previewSurface = new Surface(texture);
|
232
|
-
|
233
|
-
mPreviewBuilder.addTarget(previewSurface);
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
mCameraDevice.createCaptureSession(Collections.singletonList(previewSurface),
|
238
|
-
|
239
|
-
new CameraCaptureSession.StateCallback() {
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
@Override
|
244
|
-
|
245
|
-
public void onClosed(CameraCaptureSession session) {
|
246
|
-
|
247
|
-
}
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
@Override
|
252
|
-
|
253
|
-
public void onReady(CameraCaptureSession session) {
|
254
|
-
|
255
|
-
}
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
@Override
|
260
|
-
|
261
|
-
public void onConfigured(@NonNull CameraCaptureSession session) {
|
262
|
-
|
263
|
-
mPreviewSession = session;
|
264
|
-
|
265
|
-
}
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
}, mBackgroundHandler);
|
270
|
-
|
271
|
-
} catch (
|
401
|
+
} catch (IllegalArgumentException e) {
|
272
|
-
|
273
|
-
e.printStackTrace();
|
274
402
|
|
275
403
|
}
|
276
404
|
|
@@ -278,216 +406,24 @@
|
|
278
406
|
|
279
407
|
|
280
408
|
|
281
|
-
|
282
|
-
|
283
|
-
private
|
409
|
+
private Rect faceRect2PixelRect(Face face) {
|
410
|
+
|
284
|
-
|
411
|
+
int w = mCameraTextureView.getWidth();
|
412
|
+
|
285
|
-
i
|
413
|
+
int h = mCameraTextureView.getHeight();
|
414
|
+
|
286
|
-
|
415
|
+
Rect r=face.getBounds();
|
416
|
+
|
417
|
+
r.left = w * (-r.top + 1000) / 2000;
|
418
|
+
|
419
|
+
r.right = w * (-r.bottom + 1000) / 2000;
|
420
|
+
|
421
|
+
r.top = h * (-r.left + 1000) / 2000;
|
422
|
+
|
423
|
+
r.bottom = h * (-r.right + 1000) / 2000;
|
424
|
+
|
287
|
-
|
425
|
+
return r;
|
288
|
-
|
289
|
-
}
|
290
|
-
|
291
|
-
try {
|
292
|
-
|
293
|
-
SurfaceTexture texture = mTextureView.getSurfaceTexture();
|
294
|
-
|
295
|
-
assert texture != null;
|
296
|
-
|
297
|
-
texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
mPreviewBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
|
302
|
-
|
303
|
-
List<Surface> surfaces = new ArrayList<>();
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
// Set up Surface for the camera preview
|
308
|
-
|
309
|
-
Surface previewSurface = new Surface(texture);
|
310
|
-
|
311
|
-
surfaces.add(previewSurface);
|
312
|
-
|
313
|
-
mPreviewBuilder.addTarget(previewSurface);
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
// Set up Surface for the MediaRecorder
|
318
|
-
|
319
|
-
Surface recorderSurface = mMediaRecorder.getSurface();
|
320
|
-
|
321
|
-
surfaces.add(recorderSurface);
|
322
|
-
|
323
|
-
mPreviewBuilder.addTarget(recorderSurface);
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
// Start a capture session
|
328
|
-
|
329
|
-
// Once the session starts, we can update the UI and start recording
|
330
|
-
|
331
|
-
mCameraDevice.createCaptureSession(surfaces, new CameraCaptureSession.StateCallback() {
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
@Override
|
336
|
-
|
337
|
-
public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) {
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
mPreviewSession = cameraCaptureSession;
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
}
|
346
|
-
|
347
|
-
}, mBackgroundHandler);
|
348
|
-
|
349
|
-
} catch (CameraAccessException | IOException e) {
|
350
|
-
|
351
|
-
e.printStackTrace();
|
352
|
-
|
353
|
-
}
|
354
|
-
|
355
|
-
|
356
426
|
|
357
427
|
}
|
358
428
|
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
private CameraCaptureSession.CaptureCallback mCaptureCallback
|
364
|
-
|
365
|
-
= new CameraCaptureSession.CaptureCallback() {
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
private void process(CaptureResult result) {
|
370
|
-
|
371
|
-
Integer mode = result.get(CaptureResult.STATISTICS_FACE_DETECT_MODE);
|
372
|
-
|
373
|
-
Face[] faces = result.get(CaptureResult.STATISTICS_FACES);
|
374
|
-
|
375
|
-
if (faces != null && mode != null)
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
for(Face face: faces) {
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
Rect r=faceRect2PixelRect(face);
|
386
|
-
|
387
|
-
drawFace(r,Color.argb(255, 255, 0, 255));
|
388
|
-
|
389
|
-
}
|
390
|
-
|
391
|
-
Log.e("tag", "faces : " + faces.length + " , mode : " + mode);
|
392
|
-
|
393
|
-
}
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
@Override
|
398
|
-
|
399
|
-
public void onCaptureProgressed(CameraCaptureSession session, CaptureRequest request,
|
400
|
-
|
401
|
-
CaptureResult partialResult) {
|
402
|
-
|
403
|
-
process(partialResult);
|
404
|
-
|
405
|
-
}
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
@Override
|
410
|
-
|
411
|
-
public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request,
|
412
|
-
|
413
|
-
TotalCaptureResult result) {
|
414
|
-
|
415
|
-
process(result);
|
416
|
-
|
417
|
-
}
|
418
|
-
|
419
|
-
};
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
private Paint paint = new Paint();
|
426
|
-
|
427
|
-
public void drawFace(Rect rect1, int color) {
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
try {
|
432
|
-
|
433
|
-
if (mCameraTextureView != null) {
|
434
|
-
|
435
|
-
} else if (mCameraTextureView == null) {
|
436
|
-
|
437
|
-
}
|
438
|
-
|
439
|
-
//直接canvassを試すからこの下のコードはいらない
|
440
|
-
|
441
|
-
//Canvas canvas = mTextureView.lockCanvas();
|
442
|
-
|
443
|
-
if (canvass != null) {
|
444
|
-
|
445
|
-
try {
|
446
|
-
|
447
|
-
canvass.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
|
448
|
-
|
449
|
-
paint.setColor(color);
|
450
|
-
|
451
|
-
canvass.drawRect(rect1,paint);
|
452
|
-
|
453
|
-
} finally {
|
454
|
-
|
455
|
-
//一応mTextureViewでやっておく
|
456
|
-
|
457
|
-
mCameraTextureView.unlockCanvasAndPost(canvass);
|
458
|
-
|
459
|
-
}
|
460
|
-
|
461
|
-
}
|
462
|
-
|
463
|
-
} catch (IllegalArgumentException e) {
|
464
|
-
|
465
|
-
}
|
466
|
-
|
467
|
-
}
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
private Rect faceRect2PixelRect(Face face) {
|
472
|
-
|
473
|
-
int w = mCameraTextureView.getWidth();
|
474
|
-
|
475
|
-
int h = mCameraTextureView.getHeight();
|
476
|
-
|
477
|
-
Rect r=face.getBounds();
|
478
|
-
|
479
|
-
r.left = w * (-r.top + 1000) / 2000;
|
480
|
-
|
481
|
-
r.right = w * (-r.bottom + 1000) / 2000;
|
482
|
-
|
483
|
-
r.top = h * (-r.left + 1000) / 2000;
|
484
|
-
|
485
|
-
r.bottom = h * (-r.right + 1000) / 2000;
|
486
|
-
|
487
|
-
return r;
|
488
|
-
|
489
|
-
}
|
490
|
-
|
491
429
|
}
|
492
|
-
|
493
|
-
```
|