Ask Your Question

GFG's profile - activity

2016-06-02 07:49:07 -0600 received badge  Famous Question (source)
2015-04-17 04:44:20 -0600 received badge  Notable Question (source)
2014-04-23 10:48:21 -0600 received badge  Popular Question (source)
2012-09-24 08:03:22 -0600 asked a question Static initialization of OpenCV on Android

Hello people,

i have a problem with openCV on Android. I need to use static initialization, i followed this tutorial

I have linked the correct library to my project, but when I run the application, I get a black screen

This is the code of the MainActivity

package org.opencv.samples.tutorial2;

import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;

public class Sample2NativeCamera extends Activity {
    static {
        if (!OpenCVLoader.initDebug())
            Log.d("ERROR", "Unable to load OpenCV");
            Log.d("SUCCESS", "OpenCV loaded");
    private static final String TAG = "Sample::Activity";

    public static final int VIEW_MODE_RGBA = 0;
    public static final int VIEW_MODE_GRAY = 1;
    public static final int VIEW_MODE_CANNY = 2;

    private MenuItem mItemPreviewRGBA;
    private MenuItem mItemPreviewGray;
    private MenuItem mItemPreviewCanny;

    public static int viewMode = VIEW_MODE_RGBA;

    private Sample2View mView;

    public Sample2NativeCamera() {
        Log.i(TAG, "Instantiated new " + this.getClass());

    protected void onPause() {
        Log.i(TAG, "onPause");
        if (null != mView)

    protected void onResume() {
        Log.i(TAG, "onResume");
        if ((null != mView) && !mView.openCamera()) {
            AlertDialog ad = new AlertDialog.Builder(this).create();
            ad.setCancelable(false); // This blocks the 'BACK' button
            ad.setMessage("Fatal error: can't open camera!");
            ad.setButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {

    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        Log.i(TAG, "onCreate");

    public boolean onCreateOptionsMenu(Menu menu) {
        Log.i(TAG, "onCreateOptionsMenu");
        mItemPreviewRGBA = menu.add("Preview RGBA");
        mItemPreviewGray = menu.add("Preview GRAY");
        mItemPreviewCanny = menu.add("Canny");
        return true;

    public boolean onOptionsItemSelected(MenuItem item) {
        Log.i(TAG, "Menu Item selected " + item);
        if (item == mItemPreviewRGBA)
            viewMode = VIEW_MODE_RGBA;
        else if (item == mItemPreviewGray)
            viewMode = VIEW_MODE_GRAY;
        else if (item == mItemPreviewCanny)
            viewMode = VIEW_MODE_CANNY;
        return true;