Ask Your Question
2

grab() always returning false

asked 2013-03-01 09:04:53 -0500

sumitsh87 gravatar image

I am trying to capture real time synchronised images with android camera, at a fixed fps. I have an algorithm for that. But the grab() feature always return a false. i.e. I cant get any image captured. what can be the possible issue??

If I use the inputframe that I get from onCameraFrame(Mat inputframe) callback of CvCameraViewListener implemented activity, it works, then why not grab()??

 public void onCameraViewStarted(int width, int height) 
{

    capturedFrame=new Mat(height, width, CvType.CV_8UC4);
    vidCapture=new VideoCapture();
    Thread captureImageThread=new Thread(new cacheFrame());
    captureImageThread.start();
    ----------
            -----------
}

   private class cacheFrame implements Runnable
{

    @Override
    public void run()
    {

        while(true)
        {
            startTime = System.currentTimeMillis();

            if(vidCapture.grab())
            {
              Log.i("sumit", "frame  retreival started at : "+System.currentTimeMillis());
              vidCapture.retrieve(capturedFrame,Highgui.CV_CAP_ANDROID_GREY_FRAME);
            }
            if(capturedFrame!=null)
            {

               frameObject.image=capturedFrame.clone();
                 ---- 
                                     -----
                                     -----
                                     -----
                }       

            }


        }
edit retag flag offensive close merge delete

Comments

bear with me being a c++ guy, and not knowing about android, but i',m missing the part, where you actually start or open your VideoCapture, and supply a camera id. can it be you just forgot to do that ?

( in c++ it would be like VideoCapture capture(0); 0 being the camid )

also you're never checking capture.isOpened() (or similar for android)

berak gravatar imageberak ( 2013-03-01 10:04:52 -0500 )edit

I am doing it like this : void onCameraViewStarted(int width, int height) { VideoCapture vidCapture=new VideoCapture(0); Boolean ifopen=vidCapture.open(0); Log.i("sumit", "is camera opened for grabbing : "+ifopen); Thread captureImageThread=new Thread(new cacheFrame()); captureImageThread.start(); Thread imageProcessThread=new Thread(new processFrame()); imageProcessThread.start();

}

However it is throwing error like this :

03-03 14:41:14.417: E/OpenCV_NativeCamera(5153): initCameraConnect: Unable to connect to CameraService 03-03 14:41:14.417: E/OpenCV::camera(5153): CameraWrapperConnector::connectWrapper ERROR: the initializing function returned false 03-03 14:41:14.417: E/OpenCV::camera(5153): Native_camera returned opening error: 6

sumitsh87 gravatar imagesumitsh87 ( 2013-03-03 07:47:30 -0500 )edit

this would try to open it twice, if i read it right. so EITHER in the constructor, or call open(); maybe it just barked, because it couldn't do it the second time. also, trying -1(any) as an id might be worth a try. also, for checking, there is capture.isOpened();

berak gravatar imageberak ( 2013-03-03 08:57:04 -0500 )edit

ohk!! But the kind of error it is giving, I think there something to do with the native JNI call!! I am new to opencv. I am only using the JavaAPI for my small project and seems sufficient enough. Do I need to make JNI calls? Is it a native function (videocapture.open)?

what I understand from your comment is, instead of writing capture.open() function inside the callback function "void onCameraViewStarted(int width, int height) ", which tries to open the camera twice, I should write it inside oncreate() ?? but when I do it, I get the following error :

03-04 09:56:01.011: D/JavaCameraView(11016): Java camera view ctor 03-04 09:56:01.011: W/dalvikvm(11016): No implementation found for native Lorg/opencv/highgui/VideoCapture;.n_VideoCapture:(I)J

sumitsh87 gravatar imagesumitsh87 ( 2013-03-04 03:33:36 -0500 )edit

I got similar problem , my code is like this '

public Mat onCameraFrame(CvCameraViewFrame inputFrame) { mRgba = inputFrame.rgba(); mGray = inputFrame.gray(); VideoCapture mcapture = new VideoCapture(0); mcapture.open(Highgui.CV_CAP_ANDROID_COLOR_FRAME); if(!mcapture.isOpened()){ Core.putText(mRgba, "Capture Fail", new Point(50, 50), BIND_AUTO_CREATE, BIND_AUTO_CREATE, Color_Green); }else{ Mat frame = new Mat(); Imgproc.cvtColor(mRgba, frame, Imgproc.COLOR_RGB2GRAY); mcapture.retrieve(frame, 3); mRgba = frame;

    }
return mRgba;

}' but mcapture.isOpened() is always false

TonySJH gravatar imageTonySJH ( 2013-11-20 05:28:27 -0500 )edit

Did somebody solve their problem, please notify me if somebody, i am facing the same

Abdul Muheet gravatar imageAbdul Muheet ( 2018-02-09 01:24:01 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-03-01 11:41:59 -0500

VideoCapture.grab() method return false in several cases: camera was not open, camera has been already closed or VideoCapture object is null.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-03-01 09:04:53 -0500

Seen: 1,459 times

Last updated: Mar 01 '13