VideoCapture android doing nothing ?

asked 2016-01-05 15:32:32 -0600

momo gravatar image

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 !

edit retag flag offensive close merge delete

Comments

there is no backend for this on android (like ffmpeg on the pc version) so you simply can't read video streams or files, only from webcam

berak gravatar imageberak ( 2016-01-05 21:50:00 -0600 )edit

@berak what do you mean only from webcams? how is is different from a video stream?

neutrino gravatar imageneutrino ( 2016-07-25 08:55:03 -0600 )edit