Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

VideoCapture android doing nothing ?

Hi !

I'm just trying to get this stream "http://mjpeg.sanford.io/count.mjpeg" into a VideoCapture into my smartphone ... Unfortunately when i do :

VideoCapture cap = new VideoCapture();
cap.open("http://mjpeg.sanford.io/count.mjpeg");
if(!cap.isOpened())
Log.i(TAG, "yolo");

i always get "yolo" ....

Here is my full code. It's a bit dirty cause i'm trying a lot of thing, and i'm starting from the Tutorial .

public class Tutorial1Activity extends Activity {

    private static final String TAG = "OCVSample::Activity";

    private CameraBridgeViewBase mOpenCvCameraView;
    private boolean              mIsJavaCamera = true;
    private MenuItem             mItemSwitchCamera = null;

    MediaPlayer mediaPlayer;
    SurfaceHolder surfaceHolder;
    SurfaceView playerSurfaceView;

    private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
        @Override
        public void onManagerConnected(int status) {
            switch (status) {
                case LoaderCallbackInterface.SUCCESS:
                {
                    /*Log.i(TAG, "OpenCV loaded successfully");
                    mOpenCvCameraView.enableView();*/
                    VideoCapture cap = new VideoCapture();
                    cap.open("http://mjpeg.sanford.io/count.mjpeg");

                    if(!cap.isOpened())
                        Log.i(TAG,"yolo");
                    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
                } break;
                default:
                {
                    super.onManagerConnected(status);
                } break;
            }
        }
    };

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

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {

        if (!OpenCVLoader.initDebug()) {
            Log.d(TAG, "Internal OpenCV library not found. Using OpenCV Manager for initialization");
            OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0, this, mLoaderCallback);
        } else {
            Log.d(TAG, "OpenCV library found inside package. Using it!");
            mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
        }

        Log.i(TAG, "called onCreate");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tutorial1_surface_view);




        /*setContentView(R.layout.tutorial1_surface_view);

        mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.tutorial1_activity_java_surface_view);

        mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);

        mOpenCvCameraView.setCvCameraViewListener(this);*/
    }


}

I really need to read this stream frame by frame for a shape recognition !

Thanks !