open video file with opencv java -


so there opencv java now...! can tell me how open videofiles ?

i tryed , on internet, found nothing. documentation of videocapture class not helpfull, becaus gives c# example , show how capture webcam.

the q&a of opencv doesnt either, because there no (public) method whom can give filename string.

but should work written in api. doesn't there privte method in videocapture class sting parameter.

please answer if have solution, or if have same problem. garyee

update: (may 2017)

since version 3.0.0 there constructor videocapture class takes string argument. there easy solution problem now!

to me mystery why called automatically generated java wrapper opencv lacking functionality. first created new videocapture class videocapture(string filename) constructor , called private native method. lead an unsatisfied link error:

exception in thread "main" java.lang.unsatisfiedlinkerror:       org.opencv.highgui.videocapture.n_videocapture(ljava/lang/string;)j     @ org.opencv.highgui.videocapture.n_videocapture(native method)     @ org.opencv.highgui.videocapture.<init>(videocapture.java:90)     @ tester.main(tester.java:30) 

this indicates corresponding jniexport missing. luckily can fixed.

surprisingly needed c-constructor defined in opencv-2.4.6/modules/highgui/include/opencv2/highgui/highgui.cpp

cv_wrap videocapture(const string& filename); 

we add constructor long videocapture class in opencv-2.4.6/modules/java/generator/src/java/highgui+videocapture.java:

// // c++: videocapture::videocapture(const string& filename) //  // javadoc: videocapture::videocapture(string filename) public videocapture(string filename) {     nativeobj = n_videocapture(filename);      return; } 

the crucial , tricky step add jni export. finding right method name jnicall proved challenging, since constructor overloaded , takes java class argument. additionally need convert java sting c-string. rest copied other constructors.

in opencv-2.4.6/modules/java/generator/src/cpp/videocapture.cpp add new jniexport:

// //   videocapture::videocapture(const string& filename) //  jniexport jlong jnicall java_org_opencv_highgui_videocapture_n_1videocapture__ljava_lang_string_2 (jnienv* env, jclass, jstring filename);  jniexport jlong jnicall java_org_opencv_highgui_videocapture_n_1videocapture__ljava_lang_string_2 (jnienv* env, jclass, jstring filename) {     try {         logd("highgui::videocapture_n_1videocapture__ljava_lang_string_2()");         const char* jnamestr = env->getstringutfchars(filename, null);         string stdfilename(jnamestr);         videocapture* _retval_ = new videocapture( jnamestr );          return (jlong) _retval_;     } catch(cv::exception e) {         logd("highgui::videocapture_n_1videocapture__ljava_lang_string_2() catched cv::exception: %s", e.what());         jclass je = env->findclass("org/opencv/core/cvexception");         if(!je) je = env->findclass("java/lang/exception");         env->thrownew(je, e.what());         return 0;     } catch (...) {         logd("highgui::videocapture_n_1videocapture__ljava_lang_string_2() catched unknown exception (...)");         jclass je = env->findclass("java/lang/exception");         env->thrownew(je, "unknown exception in jni code {highgui::videocapture_n_1videocapture__ljava_lang_string_2()}");         return 0;     } } 

recompile opencv , should work.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -