質問編集履歴
3
title
CHANGED
File without changes
|
body
CHANGED
File without changes
|
2
title
CHANGED
File without changes
|
body
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
実機で動かした際に問題が発生したためと強制終了されるのですが、どうしたら良いのでしょうか。logcatには下記のように記述されています。何かアドバイスをお願いします。
|
3
3
|
|
4
4
|
FATAL EXCEPTION: main
|
5
|
-
Process: com.example.yser.
|
5
|
+
Process: com.example.yser., PID: 21654
|
6
6
|
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.yser.basketballtimer/com.example.yser.basketballtimer.MainActivity}: java.lang.InstantiationException: class com.example.yser.basketballtimer.MainActivity cannot be instantiated
|
7
7
|
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2290)
|
8
8
|
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2442)
|
@@ -28,107 +28,4 @@
|
|
28
28
|
at java.lang.reflect.Method.invoke(Native Method)
|
29
29
|
at java.lang.reflect.Method.invoke(Method.java:372)
|
30
30
|
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
|
31
|
-
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)
|
31
|
+
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
追記:ソースコードはこれです。ストリーム配信した映像から円を検出しようとしています。
|
37
|
-
|
38
|
-
import android.os.Bundle;
|
39
|
-
import android.support.v7.app.AppCompatActivity;
|
40
|
-
import android.util.Log;
|
41
|
-
import org.opencv.android.BaseLoaderCallback;
|
42
|
-
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener;
|
43
|
-
import org.opencv.android.LoaderCallbackInterface;
|
44
|
-
import org.opencv.android.OpenCVLoader;
|
45
|
-
import org.opencv.core.CvType;
|
46
|
-
import org.opencv.core.Core;
|
47
|
-
import org.opencv.core.Mat;
|
48
|
-
import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame;
|
49
|
-
import org.opencv.core.Scalar;
|
50
|
-
import org.opencv.imgproc.Imgproc;
|
51
|
-
import org.opencv.core.Point;
|
52
|
-
import org.opencv.videoio.VideoCapture;
|
53
|
-
|
54
|
-
public abstract class MainActivity extends AppCompatActivity implements CvCameraViewListener {
|
55
|
-
|
56
|
-
private final BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
|
57
|
-
@Override
|
58
|
-
public void onManagerConnected(int status) {
|
59
|
-
switch (status) {
|
60
|
-
case LoaderCallbackInterface.SUCCESS:
|
61
|
-
{
|
62
|
-
Log.i("Opencv", "loaded successfully");
|
63
|
-
}
|
64
|
-
break;
|
65
|
-
default:
|
66
|
-
{
|
67
|
-
super.onManagerConnected(status);
|
68
|
-
}
|
69
|
-
break;
|
70
|
-
}
|
71
|
-
}};
|
72
|
-
|
73
|
-
@Override
|
74
|
-
public void onResume() {
|
75
|
-
super.onResume();
|
76
|
-
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_1_0, this, mLoaderCallback);
|
77
|
-
}
|
78
|
-
|
79
|
-
|
80
|
-
private Mat mCameraFrame;
|
81
|
-
public final VideoCapture capture =new VideoCapture("http://????action=stream");
|
82
|
-
public void onCreate(Bundle savedInstanceState){
|
83
|
-
super.onCreate(savedInstanceState);
|
84
|
-
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
|
85
|
-
if( capture.isOpened()){
|
86
|
-
capture.read(mCameraFrame);
|
87
|
-
if( !mCameraFrame.empty() ) {
|
88
|
-
capture.open(0);
|
89
|
-
setContentView(R.layout.activity_main);
|
90
|
-
}
|
91
|
-
else{
|
92
|
-
System.out.println(" -- No captured frame -- ");
|
93
|
-
setContentView(R.layout.activity_main);
|
94
|
-
}
|
95
|
-
}
|
96
|
-
else{
|
97
|
-
System.out.println(" -- Can't boot -- ");
|
98
|
-
setContentView(R.layout.activity_main);
|
99
|
-
|
100
|
-
}
|
101
|
-
}
|
102
|
-
|
103
|
-
@Override
|
104
|
-
public void onCameraViewStarted(int width, int height) {
|
105
|
-
mCameraFrame = new Mat(height, width, CvType.CV_8UC1);
|
106
|
-
}
|
107
|
-
|
108
|
-
@Override
|
109
|
-
public void onCameraViewStopped() {
|
110
|
-
mCameraFrame.release();
|
111
|
-
}
|
112
|
-
|
113
|
-
@Override
|
114
|
-
public void onCameraFrame(CvCameraViewFrame inputFrame) {
|
115
|
-
Mat circles = new Mat();
|
116
|
-
Imgproc.cvtColor(mCameraFrame, mCameraFrame, Imgproc.COLOR_RGB2GRAY);
|
117
|
-
Imgproc.HoughCircles(mCameraFrame, circles, Imgproc.CV_HOUGH_GRADIENT, 2, 10, 160, 50, 10, 20);
|
118
|
-
fncDrwCircles(circles, mCameraFrame);
|
119
|
-
}
|
120
|
-
|
121
|
-
private void fncDrwCircles(Mat circles, Mat mCameraFrame) {
|
122
|
-
double[] data;
|
123
|
-
double rho;
|
124
|
-
Point pt = new Point();
|
125
|
-
for (int i = 0; i < circles.cols(); i++) {
|
126
|
-
data = circles.get(0, i);
|
127
|
-
pt.x = data[0];
|
128
|
-
pt.y = data[1];
|
129
|
-
rho = data[2];
|
130
|
-
Imgproc.circle(mCameraFrame, pt, (int) rho, new Scalar(255, 0, 0), 2);
|
131
|
-
}
|
132
|
-
|
133
|
-
}
|
134
|
-
}
|
1
ソースコードを追記しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -28,4 +28,107 @@
|
|
28
28
|
at java.lang.reflect.Method.invoke(Native Method)
|
29
29
|
at java.lang.reflect.Method.invoke(Method.java:372)
|
30
30
|
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
|
31
|
-
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)
|
31
|
+
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
追記:ソースコードはこれです。ストリーム配信した映像から円を検出しようとしています。
|
37
|
+
|
38
|
+
import android.os.Bundle;
|
39
|
+
import android.support.v7.app.AppCompatActivity;
|
40
|
+
import android.util.Log;
|
41
|
+
import org.opencv.android.BaseLoaderCallback;
|
42
|
+
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener;
|
43
|
+
import org.opencv.android.LoaderCallbackInterface;
|
44
|
+
import org.opencv.android.OpenCVLoader;
|
45
|
+
import org.opencv.core.CvType;
|
46
|
+
import org.opencv.core.Core;
|
47
|
+
import org.opencv.core.Mat;
|
48
|
+
import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame;
|
49
|
+
import org.opencv.core.Scalar;
|
50
|
+
import org.opencv.imgproc.Imgproc;
|
51
|
+
import org.opencv.core.Point;
|
52
|
+
import org.opencv.videoio.VideoCapture;
|
53
|
+
|
54
|
+
public abstract class MainActivity extends AppCompatActivity implements CvCameraViewListener {
|
55
|
+
|
56
|
+
private final BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
|
57
|
+
@Override
|
58
|
+
public void onManagerConnected(int status) {
|
59
|
+
switch (status) {
|
60
|
+
case LoaderCallbackInterface.SUCCESS:
|
61
|
+
{
|
62
|
+
Log.i("Opencv", "loaded successfully");
|
63
|
+
}
|
64
|
+
break;
|
65
|
+
default:
|
66
|
+
{
|
67
|
+
super.onManagerConnected(status);
|
68
|
+
}
|
69
|
+
break;
|
70
|
+
}
|
71
|
+
}};
|
72
|
+
|
73
|
+
@Override
|
74
|
+
public void onResume() {
|
75
|
+
super.onResume();
|
76
|
+
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_1_0, this, mLoaderCallback);
|
77
|
+
}
|
78
|
+
|
79
|
+
|
80
|
+
private Mat mCameraFrame;
|
81
|
+
public final VideoCapture capture =new VideoCapture("http://????action=stream");
|
82
|
+
public void onCreate(Bundle savedInstanceState){
|
83
|
+
super.onCreate(savedInstanceState);
|
84
|
+
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
|
85
|
+
if( capture.isOpened()){
|
86
|
+
capture.read(mCameraFrame);
|
87
|
+
if( !mCameraFrame.empty() ) {
|
88
|
+
capture.open(0);
|
89
|
+
setContentView(R.layout.activity_main);
|
90
|
+
}
|
91
|
+
else{
|
92
|
+
System.out.println(" -- No captured frame -- ");
|
93
|
+
setContentView(R.layout.activity_main);
|
94
|
+
}
|
95
|
+
}
|
96
|
+
else{
|
97
|
+
System.out.println(" -- Can't boot -- ");
|
98
|
+
setContentView(R.layout.activity_main);
|
99
|
+
|
100
|
+
}
|
101
|
+
}
|
102
|
+
|
103
|
+
@Override
|
104
|
+
public void onCameraViewStarted(int width, int height) {
|
105
|
+
mCameraFrame = new Mat(height, width, CvType.CV_8UC1);
|
106
|
+
}
|
107
|
+
|
108
|
+
@Override
|
109
|
+
public void onCameraViewStopped() {
|
110
|
+
mCameraFrame.release();
|
111
|
+
}
|
112
|
+
|
113
|
+
@Override
|
114
|
+
public void onCameraFrame(CvCameraViewFrame inputFrame) {
|
115
|
+
Mat circles = new Mat();
|
116
|
+
Imgproc.cvtColor(mCameraFrame, mCameraFrame, Imgproc.COLOR_RGB2GRAY);
|
117
|
+
Imgproc.HoughCircles(mCameraFrame, circles, Imgproc.CV_HOUGH_GRADIENT, 2, 10, 160, 50, 10, 20);
|
118
|
+
fncDrwCircles(circles, mCameraFrame);
|
119
|
+
}
|
120
|
+
|
121
|
+
private void fncDrwCircles(Mat circles, Mat mCameraFrame) {
|
122
|
+
double[] data;
|
123
|
+
double rho;
|
124
|
+
Point pt = new Point();
|
125
|
+
for (int i = 0; i < circles.cols(); i++) {
|
126
|
+
data = circles.get(0, i);
|
127
|
+
pt.x = data[0];
|
128
|
+
pt.y = data[1];
|
129
|
+
rho = data[2];
|
130
|
+
Imgproc.circle(mCameraFrame, pt, (int) rho, new Scalar(255, 0, 0), 2);
|
131
|
+
}
|
132
|
+
|
133
|
+
}
|
134
|
+
}
|