onCameraViewStarted and onCameraFrame never called - black view
Hi,
I am trying to set up OpenCV with Android and just get a black screen whatever I do. OpenCV loads successfully, and enableView is called, yet onCameraViewStarted and onCameraFrame are never called. Some help would be greatly appreciated. Here is the MainActivity.java code:
public class MainActivity extends Activity implements CameraBridgeViewBase.CvCameraViewListener2 {
private static final String TAG = "MainActivity";
private CameraBridgeViewBase mOpenCvCameraView;
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS:
{
Log.i(TAG, "Manager connected");
mOpenCvCameraView.enableView();
} break;
default:
{
super.onManagerConnected(status);
} break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.i(TAG, "called onCreate");
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.activity_main);
if(permission()){
mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.camera_view);
mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
mOpenCvCameraView.setCvCameraViewListener(this);
}
}
@Override
public void onCameraViewStarted(int width, int height) {
Log.i(TAG, "called onCameraViewStarted");
}
@Override
public void onCameraViewStopped() {
}
@Override
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
Log.i(TAG, "called onCameraFrame");
return inputFrame.rgba();
}
@Override
public void onPause()
{
super.onPause();
if (mOpenCvCameraView != null)
mOpenCvCameraView.disableView();
}
@Override
public void onResume()
{
Log.i(TAG, "called resume");
super.onResume();
if (!OpenCVLoader.initDebug()) {
Toast.makeText(this, "There are problems with OpenCV",
Toast.LENGTH_SHORT).show();
} else {
mLoaderCallback.onManagerConnected(BaseLoaderCallback.SUCCESS);
}
}
public void onDestroy() {
super.onDestroy();
if (mOpenCvCameraView != null)
mOpenCvCameraView.disableView();
}
private boolean permission(){
if (ContextCompat.checkSelfPermission(MainActivity.this,
Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]
{Manifest.permission.CAMERA},
50);
} else {
return true;
}
return false;
}
}
please check if
permission()
returns true !It does! I have also tried without the permission stuff, same result...