bytedeco / javacv

Java interface to OpenCV, FFmpeg, and more
Other
7.55k stars 1.58k forks source link

opencv_videostab.IFrameSource needs opencv_videoio.VideoCapture #277

Closed androiddevaccnt7 closed 8 years ago

androiddevaccnt7 commented 8 years ago

Is this supported on the Android platform?

I'm trying to use VideoFileSource in opencv_videostab, but it is unable to open a file.

E/AndroidRuntime: java.lang.RuntimeException: /home/saudet/projects/bytedeco/javacpp-presets/opencv/cppbuild/android-arm/opencv-3.0.0/modules/videostab/src/frame_source.cpp:71: error: (0) can't open file: /storage/emulated/0/Download/file_sample.mp4 in function virtual void cv::videostab::{anonymous}::VideoFileSourceImpl::reset()

I've done some research and found some discussion that opencv may not have the backend required for this without FFmpeg. But I already have FFmpeg in my project. Is there any way to make this work?

saudet commented 8 years ago

You could rebuild OpenCV with support for FFmpeg, but it doesn't usually work very well anyway. Anything wrong with FFmpegFrameGrabber?

androiddevaccnt7 commented 8 years ago

hey saudet - thanks for the reply and all the great work here.

The videostab Stabilizers require an opencv_videostab.IFrameSource. The only one of these built-in - VideoFileSource - uses VideoCapture.

FrameGrabber gets me the frames, but not in a way I can use with video_stab. I'm beginning to think my best approach may be to add and rebuild with a new IFrameSource which can be created from a list of existing frames.

Does that seem like a reasonable approach? I can't see anyway the videostab module can be used out of the box without VideoCapture support.

saudet commented 8 years ago

We can implement our own IFrameSource in Java, but to do so, it would have to be "virtualized"... something I neglected to do. I've done so in the commit above. Enjoy! :)

androiddevaccnt7 commented 8 years ago

Thanks @saudet, that should open up this api for me. I had a problem compiling the latest snapshot including that change (), but could compile the 1.1 release without issue. I attempted to apply only the commit linked above and rebuild, when I ran into the following errors during the step "Compiling ..../libjniopencv_videostab.so":

/home/javacpp-presets-1.1/opencv/target/classes/org/bytedeco/javacpp/jniopencv_videostab.cpp: In function '_jobject* Java_org_bytedeco_javacpp_opencv_1videostab_00024IFrameSource_nextFrame(JNIEnv, jobject)':
/home/javacpp-presets-1.1/opencv/target/classes/org/bytedeco/javacpp/jniopencv_videostab.cpp:8374:20: error: expected type-specifier before 'JavaCPP__0003a_0003acv_0003a_0003aMat'
rptr = new JavaCPP__0003a_0003acv_0003a_0003aMat((dynamic_cast<JavaCPP__0003a_0003acv_0003a_0003avideostab_0003a_0003aIFrameSource>(ptr) != NULL ? ((JavaCPP__0003a_0003acv_0003a_0003avideostab_0003a_0003aIFrameSource)ptr)->super_nextFrame() : ptr->nextFrame()));
^
/home/javacpp-presets-1.1/opencv/target/classes/org/bytedeco/javacpp/jniopencv_videostab.cpp:8382:15: error: 'JavaCPP__0003a_0003acv_0003a_0003aMat' was not declared in this scope
((JavaCPP__0003a_0003acv_0003a_0003aMat))rptr->obj = env->NewWeakGlobalRef(rarg);
^
/home/javacpp-presets-1.1/opencv/target/classes/org/bytedeco/javacpp/jniopencv_videostab.cpp:8382:53: error: expected primary-expression before ')' token
((JavaCPP__0003a_0003acv_0003a_0003aMat*))rptr->obj = env->NewWeakGlobalRef(rarg);

Seems to be related to the above change, trying to figure out whats wrong see if I maybe need an additional commit since 1.1.

saudet commented 8 years ago

Yes, there was a bug in JavaCPP. Be sure to get the latest changes for that module as well.

saudet commented 8 years ago

The changes are in JavaCV 1.2. Thanks for reporting!