sawpawan / javacv

Automatically exported from code.google.com/p/javacv
GNU General Public License v2.0
0 stars 0 forks source link

No FrameGrabber to capture from Android camera #290

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Creating a FrameGrabber/OpenCVFrameGrabber in Android.
2. Starting the grabber(with the start() method).
3. Grabbing a frame( with grab() method) and receive it in an IplImage.

What is the expected output? What do you see instead?
I should not get an error message and the code should giveme a Non-Null 
IplImage.
I see the following error:-
03-07 17:05:40.110: W/System.err(17523): 
com.googlecode.javacv.FrameGrabber$Exception: cvCreateCameraCapture() Error: 
Could not create camera capture.
03-07 17:05:40.110: W/System.err(17523):    at 
com.googlecode.javacv.OpenCVFrameGrabber.start(OpenCVFrameGrabber.java:176)

What version of the product are you using? On what operating system?
0.4

Please provide any additional information below.
In my Image processing I want to continuously process frames so I need to 
capture these frames in a timely manner. I want to be able to do so with 
JavaCV. But this is the situation that I am encountering right now. Is this is 
a known issue? Please find attached my Java file with this issue. I did the 
initial setup according to the instructions on the main JavaCV project page and 
I am using Eclipse for development.

Original issue reported on code.google.com by Sumits...@gmail.com on 7 Mar 2013 at 4:14

Attachments:

GoogleCodeExporter commented 8 years ago
To capture images from the camera, use the Android API as shown in the 
FacePreview and RecordActivity samples here:
http://code.google.com/p/javacv/source/browse/samples/FacePreview.java
http://code.google.com/p/javacv/source/browse/samples/RecordActivity.java
The way it works with callbacks doesn't make it suitable for implementation as 
a `FrameGrabber`, but it could be done. If you would like to make a 
contribution, please attach it here, thank you.

Original comment by samuel.a...@gmail.com on 8 Mar 2013 at 8:45

GoogleCodeExporter commented 8 years ago
I did that already with callbacks. However the problem is I need a precise fps. 
call back function doesnt provide a precise fps. I need a grabber to do that.

I hope you understand my issue!! Let me know if you need further clarification.

BTW I would be glad to contibute to the forum, once I implement it successfully 
:)

Original comment by Sumits...@gmail.com on 8 Mar 2013 at 9:18

GoogleCodeExporter commented 8 years ago
You're not going to get anything close to real-time with Android, if that's 
what your asking. You're going to need some other platform.

Original comment by samuel.a...@gmail.com on 8 Mar 2013 at 9:27

GoogleCodeExporter commented 8 years ago
I guess I can. I could use NDK and JNI calls to use cv::videocapture.grab() and 
cv::videocapture.retreive() methods from c++ api. Use a buffer to store images 
in real time and process image using separate thread.This will solve my issue.

But problem : I am newbie to NDk and JNi calls...struggling with it. So thought 
javaCV could be the savior :)

But I guess, now I have to work hard with JNI calls, as I am sure that will 
solve my purpose.

whats your say?? 

Original comment by Sumits...@gmail.com on 8 Mar 2013 at 9:40

GoogleCodeExporter commented 8 years ago
How do you know that the native hacks used in OpenCV have any better 
performance?

Original comment by samuel.a...@gmail.com on 8 Mar 2013 at 9:45

GoogleCodeExporter commented 8 years ago
I know, I may have to compromise with slow jni calls. However I dont really 
need the maximum frame rates. I am OK if I can get low frame rates. But I need 
a steady and precise fps.

for that what I do is

0. start thread loop 
1. grab Image using grab()  ( store time stamp t)
2. process image (store time stamp t1, when processing finish)
3. sleep thread for (100-(t1-t))

this way I grab a frame every 100 ms. so I get a precise 10fps. and I am OK 
with it as long as its precisely 10 fps.

makes sense?

Original comment by Sumits...@gmail.com on 8 Mar 2013 at 9:57

GoogleCodeExporter commented 8 years ago
Maybe. Please test it and let us know the results.

Original comment by samuel.a...@gmail.com on 8 Mar 2013 at 10:00

GoogleCodeExporter commented 8 years ago
here facePreview is always disconnected 
as with this error

2013-06-09 07:23:55 - FacePreviewnew] emulator-5554 disconnected! Cancelling 
'com.googlecode.javacv.facepreview.FacePreview activity launch'!

I am in a working project. can I please know the reason for this issue please.

Original comment by hrshsbs...@gmail.com on 9 Jun 2013 at 1:56

GoogleCodeExporter commented 8 years ago
With the latest release of JavaCV 0.8, we should now be able to use OpenCV (as 
well as OpenCVFrameGrabber) to grab from the camera on Android. If it doesn't 
work for you, please let me, and I'll check it out again, thanks!

A lot of other things have changed with this release, so please make sure to 
read the announcement here:
    http://bytedeco.org/release/2014/04/28/first-release.html

Original comment by samuel.a...@gmail.com on 29 Apr 2014 at 12:11

GoogleCodeExporter commented 8 years ago
I am trying to use a FrameRecorder and FrameGrabber to grab an image from the 
android camera and then send it over the network.  I successfully got this 
working with the FrameRecorder/CameraPreview method, but the latency was really 
bad, like 20-30 second delay.  I have tried plain FrameGrabber, 
FFmpegFrameGrabber, VideoInputFrameGrabber, and OpenCVFrameGrabber. I have 
tried many methods over the past couple of days to no avail.

Basic code snippet:
FrameGrabber ffGrabber = OpenCVFrameGrabber.createDefault(0);
ffGrabber.start();

07-02 15:18:16.375: W/CameraBase(20339): An error occurred while connecting to 
camera: 0
07-02 15:18:16.375: E/OpenCV_NativeCamera(20339): initCameraConnect: Unable to 
connect to CameraService
07-02 15:18:16.375: E/OpenCV::camera(20339): 
CameraWrapperConnector::connectWrapper ERROR: the initializing function 
returned false
07-02 15:18:16.375: E/OpenCV::camera(20339): Native_camera returned opening 
error: 6
07-02 15:18:16.375: D/CameraPreview(20339): cvCreateCameraCapture() Error: 
Could not create camera capture.
07-02 15:18:16.375: W/System.err(20339): 
org.bytedeco.javacv.FrameGrabber$Exception: cvCreateCameraCapture() Error: 
Could not create camera capture.

Original comment by ejo4...@gmail.com on 2 Jul 2014 at 7:22

GoogleCodeExporter commented 8 years ago
I broke the program down so I am only trying to start a grabber now.  Below are 
results for FFmpegFrameGrabber and OpenCVFrameGrabber When I try 
FFmpegFrameGrabber, I get a null pointer exception when trying to start it.

import org.bytedeco.javacv.FFmpegFrameGrabber;
import org.bytedeco.javacv.FrameGrabber;
import org.bytedeco.javacv.FrameGrabber.Exception;

import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

    private FrameGrabber fg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);            
            try {
                fg = FFmpegFrameGrabber.createDefault(0);
                fg.start();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    }
}

07-03 08:11:35.703: E/AndroidRuntime(24619): FATAL EXCEPTION: main
07-03 08:11:35.703: E/AndroidRuntime(24619): Process: com.apexxs.javacvtest, 
PID: 24619
07-03 08:11:35.703: E/AndroidRuntime(24619): java.lang.RuntimeException: Unable 
to start activity 
ComponentInfo{com.apexxs.javacvtest/com.apexxs.javacvtest.MainActivity}: 
java.lang.NullPointerException
07-03 08:11:35.703: E/AndroidRuntime(24619):    at 
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2328)
07-03 08:11:35.703: E/AndroidRuntime(24619):    at 
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2386)
07-03 08:11:35.703: E/AndroidRuntime(24619):    at 
android.app.ActivityThread.access$900(ActivityThread.java:169)
07-03 08:11:35.703: E/AndroidRuntime(24619):    at 
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1277)
07-03 08:11:35.703: E/AndroidRuntime(24619):    at 
android.os.Handler.dispatchMessage(Handler.java:102)
07-03 08:11:35.703: E/AndroidRuntime(24619):    at 
android.os.Looper.loop(Looper.java:136)
07-03 08:11:35.703: E/AndroidRuntime(24619):    at 
android.app.ActivityThread.main(ActivityThread.java:5476)
07-03 08:11:35.703: E/AndroidRuntime(24619):    at 
java.lang.reflect.Method.invokeNative(Native Method)
07-03 08:11:35.703: E/AndroidRuntime(24619):    at 
java.lang.reflect.Method.invoke(Method.java:515)
07-03 08:11:35.703: E/AndroidRuntime(24619):    at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
07-03 08:11:35.703: E/AndroidRuntime(24619):    at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
07-03 08:11:35.703: E/AndroidRuntime(24619):    at 
dalvik.system.NativeStart.main(Native Method)
07-03 08:11:35.703: E/AndroidRuntime(24619): Caused by: 
java.lang.NullPointerException
07-03 08:11:35.703: E/AndroidRuntime(24619):    at 
com.apexxs.javacvtest.MainActivity.onCreate(MainActivity.java:20)
07-03 08:11:35.703: E/AndroidRuntime(24619):    at 
android.app.Activity.performCreate(Activity.java:5451)
07-03 08:11:35.703: E/AndroidRuntime(24619):    at 
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
07-03 08:11:35.703: E/AndroidRuntime(24619):    at 
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292)
07-03 08:11:35.703: E/AndroidRuntime(24619):    ... 11 more

--------------------------------------------------------------------------------
--

Separate test for OpenCVFrameGrabber:

import org.bytedeco.javacv.FrameGrabber;
import org.bytedeco.javacv.FrameGrabber.Exception;
import org.bytedeco.javacv.OpenCVFrameGrabber;

import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

    private FrameGrabber fg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);            
            try {
                fg = OpenCVFrameGrabber.createDefault(0);
                fg.start();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    }
}

07-03 08:12:51.483: A/libc(25325): Fatal signal 11 (SIGSEGV) at 0x00000000 
(code=1), thread 25325 (exxs.javacvtest)
07-03 08:12:51.483: E/cac3(377):  [cac3_buffer_latency] memset for mem size 
3997696 bytes: 2 ms 
07-03 08:12:51.503: E/libaprpmem(377):  Ion allocation success virtaddr : 
ret=2956521472 fd=43 heapid=1048576
07-03 08:12:51.503: E/cac3(377):  [cac3_buffer_latency] Allocated 0xb038f000, 
mem size 15982592 bytes from ION Heap ID 20: 17 ms 
07-03 08:12:51.513: E/cac3(377):  [cac3_buffer_latency] memset for mem size 
15982592 bytes: 9 ms 
07-03 08:12:51.523: E/libaprpmem(377):  Ion allocation success virtaddr : 
ret=2952458240 fd=44 heapid=1048576
07-03 08:12:51.523: E/cac3(377):  [cac3_buffer_latency] Allocated 0xaffaf000, 
mem size 4063232 bytes from ION Heap ID 20: 8 ms 
07-03 08:12:51.523: E/cac3(377):  [cac3_buffer_latency] memset for mem size 
4063232 bytes: 4 ms 
07-03 08:12:51.533: E/libaprpmem(377):  Ion allocation success virtaddr : 
ret=2948395008 fd=45 heapid=1048576
07-03 08:12:51.533: E/cac3(377):  [cac3_buffer_latency] Allocated 0xafbcf000, 
mem size 4063232 bytes from ION Heap ID 20: 4 ms 
07-03 08:12:51.533: E/cac3(377):  [cac3_buffer_latency] memset for mem size 
4063232 bytes: 4 ms 

Original comment by ejo4...@gmail.com on 3 Jul 2014 at 12:15

GoogleCodeExporter commented 8 years ago
There was a problem with 0.8 that should be fixed in the latest SNAPSHOTs:
https://oss.sonatype.org/content/repositories/snapshots//org/bytedeco/

Original comment by samuel.a...@gmail.com on 3 Jul 2014 at 12:20

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Do I need the new ffmpeg-android-arm.jar?  I was relying on binaries before, 
had some trouble building from src.  I have all of the snapshots you linked to, 
but still seeing the same errors.  I still have all of the old .so files from 
ffmpeg-android-arm.jar.  I didn't see the new ffmpeg-android-arm.jar in the 
snapshots.

Original comment by ejo4...@gmail.com on 3 Jul 2014 at 12:48

GoogleCodeExporter commented 8 years ago
Please make sure your device is supported by OpenCV. OpenCV uses a hack that is 
not officially supported by Android. If you're aiming for portability, you 
should use Android's official API as shown in the FacePreview.java sample 
anyway.

Original comment by samuel.a...@gmail.com on 3 Jul 2014 at 12:53

GoogleCodeExporter commented 8 years ago
Is there a way to tell if my device is supported?  It's a samsung galaxy s5.  I 
used the Android API before, but it was very slow, we are talking a 20-30 
second delay with the preview callback method.

Original comment by ejo4...@gmail.com on 3 Jul 2014 at 12:59

GoogleCodeExporter commented 8 years ago
I don't know how to tell for sure if it's supported or not. Please ask the 
OpenCV developers and let us know what you find out, thanks! :)

Original comment by samuel.a...@gmail.com on 3 Jul 2014 at 1:15