質問編集履歴
2
追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -7,6 +7,164 @@
|
|
7
7
|
どなたか原因分かる方いらっしゃいましたらご教授お願い致します。。
|
8
8
|
|
9
9
|
補足
|
10
|
+
ソースコードです
|
11
|
+
AutoCamera.java
|
12
|
+
```ここに言語を入力
|
13
|
+
package a.camera;
|
14
|
+
import android.app.Activity;
|
15
|
+
import android.bluetooth.BluetoothAdapter;
|
16
|
+
import android.graphics.Bitmap;
|
17
|
+
import android.graphics.BitmapFactory;
|
18
|
+
import android.hardware.Camera;
|
19
|
+
import android.os.Bundle;
|
20
|
+
import android.os.Environment;
|
21
|
+
import android.os.Handler;
|
22
|
+
import android.util.Log;
|
23
|
+
import android.view.SurfaceHolder;
|
24
|
+
import android.view.SurfaceView;
|
25
|
+
import android.view.View;
|
26
|
+
import android.view.Window;
|
27
|
+
import android.view.WindowManager;
|
28
|
+
import android.widget.Toast;
|
29
|
+
|
30
|
+
import java.io.FileOutputStream;
|
31
|
+
|
32
|
+
public class AutoCamera extends Activity {
|
33
|
+
protected void onCreate(Bundle savedInstanceState) {
|
34
|
+
super.onCreate(savedInstanceState);
|
35
|
+
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
36
|
+
setContentView(new CameraView(this));
|
37
|
+
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
38
|
+
}
|
39
|
+
}
|
40
|
+
```
|
41
|
+
|
42
|
+
CameraPreview.java
|
43
|
+
```ここに言語を入力
|
44
|
+
package a.camera;
|
45
|
+
|
46
|
+
import android.annotation.TargetApi;
|
47
|
+
import android.content.Context;
|
48
|
+
import android.graphics.PixelFormat;
|
49
|
+
import android.hardware.Camera;
|
50
|
+
import android.os.Build;
|
51
|
+
import android.os.Handler;
|
52
|
+
import android.util.Log;
|
53
|
+
import android.view.SurfaceHolder;
|
54
|
+
import android.view.SurfaceView;
|
55
|
+
import android.widget.Toast;
|
56
|
+
|
57
|
+
import java.io.BufferedOutputStream;
|
58
|
+
import java.net.Socket;
|
59
|
+
|
60
|
+
import static android.content.ContentValues.TAG;
|
61
|
+
|
62
|
+
public class CameraView extends SurfaceView implements SurfaceHolder.Callback{
|
63
|
+
private SurfaceHolder holder;
|
64
|
+
private Camera camera;
|
65
|
+
private static final int WIDTH = 480;
|
66
|
+
private static final int HEIGHT = 320;
|
67
|
+
private static final int PORT = 49152;
|
68
|
+
private static final String IP_ADDR = "192.168.11.2";
|
69
|
+
private static boolean is_save;
|
70
|
+
|
71
|
+
public CameraView(Context context) {
|
72
|
+
super(context);
|
73
|
+
holder=getHolder();
|
74
|
+
holder.addCallback(this);
|
75
|
+
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
|
76
|
+
}
|
77
|
+
|
78
|
+
@Override
|
79
|
+
public void surfaceCreated(SurfaceHolder holder) {
|
80
|
+
try {
|
81
|
+
camera = Camera.open(0);
|
82
|
+
camera.setPreviewDisplay(holder);
|
83
|
+
} catch (Exception e) {
|
84
|
+
}
|
85
|
+
}
|
86
|
+
|
87
|
+
@Override
|
88
|
+
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
|
89
|
+
Camera.Parameters parameters=camera.getParameters();
|
90
|
+
parameters.setPictureSize(WIDTH, HEIGHT);
|
91
|
+
camera.setParameters(parameters);
|
92
|
+
camera.startPreview();
|
93
|
+
faceDetection();
|
94
|
+
}
|
95
|
+
|
96
|
+
@Override
|
97
|
+
public void surfaceDestroyed(SurfaceHolder holder) {
|
98
|
+
camera.setPreviewCallback(null);
|
99
|
+
camera.stopPreview();
|
100
|
+
camera.release();
|
101
|
+
camera=null;
|
102
|
+
}
|
103
|
+
|
104
|
+
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
|
105
|
+
public void faceDetection(){
|
106
|
+
final int standardFaceScore = 60000;
|
107
|
+
try {camera.startFaceDetection();
|
108
|
+
} catch (IllegalArgumentException e) {
|
109
|
+
} catch (RuntimeException e) {}
|
110
|
+
|
111
|
+
camera.setFaceDetectionListener(new Camera.FaceDetectionListener() {
|
112
|
+
@Override
|
113
|
+
public void onFaceDetection(Camera.Face[] faces, Camera camera) {
|
114
|
+
Log.d(TAG, "faces count: " + faces.length);
|
115
|
+
for (Camera.Face face : faces) {
|
116
|
+
Log.d(TAG, "face id: " + face.id);
|
117
|
+
Log.d(TAG, "face score: " + face.score);
|
118
|
+
Log.d(TAG, "face rect: " + face.rect.left + "," + face.rect.top + " - "
|
119
|
+
+ face.rect.right + "," + face.rect.bottom);
|
120
|
+
if (face.mouth != null) {
|
121
|
+
Log.d(TAG, "face mouth: " + face.mouth.x + "," + face.mouth.y);
|
122
|
+
Log.d(TAG, "face leftEye: " + face.leftEye.x + "," + face.leftEye.y);
|
123
|
+
Log.d(TAG, "face rightEye: " + face.rightEye.x + "," + face.rightEye.y);
|
124
|
+
}
|
125
|
+
if(face.score > standardFaceScore && !is_save){
|
126
|
+
takePicture();
|
127
|
+
}
|
128
|
+
}
|
129
|
+
}
|
130
|
+
});
|
131
|
+
}
|
132
|
+
|
133
|
+
public void takePicture() {
|
134
|
+
// カメラのスクリーンショットの取得
|
135
|
+
camera.takePicture(null, null,new Camera.PictureCallback() {
|
136
|
+
public void onPictureTaken(byte[] data,Camera camera) {
|
137
|
+
Toast.makeText(getContext(), "撮影しました", Toast.LENGTH_LONG).show();
|
138
|
+
is_save = true;
|
139
|
+
sendData(getContext(), data);
|
140
|
+
new Handler().postDelayed(new Runnable() {
|
141
|
+
@Override
|
142
|
+
public void run() {
|
143
|
+
is_save = false;
|
144
|
+
}
|
145
|
+
}, 3000);
|
146
|
+
}
|
147
|
+
});
|
148
|
+
}
|
149
|
+
|
150
|
+
private void sendData(Context context, byte[] data){
|
151
|
+
// ソケットの作成
|
152
|
+
Socket socket;
|
153
|
+
BufferedOutputStream out;
|
154
|
+
try{
|
155
|
+
socket = new Socket(IP_ADDR, PORT);
|
156
|
+
out = new BufferedOutputStream(socket.getOutputStream());
|
157
|
+
out.write(data);
|
158
|
+
if(out != null) out.close();
|
159
|
+
if(socket != null) socket.close();
|
160
|
+
} catch (Exception ex){
|
161
|
+
ex.printStackTrace();
|
162
|
+
}
|
163
|
+
}
|
164
|
+
}
|
165
|
+
|
166
|
+
```
|
167
|
+
|
10
168
|
基本このエラーです。
|
11
169
|
```ここに言語を入力
|
12
170
|
12-02 16:16:33.598 1305-17957/? E/HCEOutdoorUtil: (413) int HCEView_ManagerSensor::getIdent() Error(ALooper_pollAll returns TIMEOUT. Set Initialized Values)
|
1
質問の追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,4 +4,10 @@
|
|
4
4
|
OSは両方同じAndroid4.4です。
|
5
5
|
やはりらくらくスマートフォンとあって、カメラなどを使用することはできないのでしょうか?
|
6
6
|
ちゃんとカメラのパーミッションを許可してます。
|
7
|
-
どなたか原因分かる方いらっしゃいましたらご教授お願い致します。。
|
7
|
+
どなたか原因分かる方いらっしゃいましたらご教授お願い致します。。
|
8
|
+
|
9
|
+
補足
|
10
|
+
基本このエラーです。
|
11
|
+
```ここに言語を入力
|
12
|
+
12-02 16:16:33.598 1305-17957/? E/HCEOutdoorUtil: (413) int HCEView_ManagerSensor::getIdent() Error(ALooper_pollAll returns TIMEOUT. Set Initialized Values)
|
13
|
+
```
|