grab() always returning false
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();
----
-----
-----
-----
}
}
}
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)
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
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();
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
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;
}' but mcapture.isOpened() is always false
Did somebody solve their problem, please notify me if somebody, i am facing the same