/modules/java/generator/src/cpp/VideoCapture.cpp

https://bitbucket.org/odellus/opencv
C++ | 434 lines | 294 code | 106 blank | 34 comment | 12 complexity | 9583d8f21f2439691e79736287e13bf6 MD5 | raw file
  1. #define LOG_TAG "org.opencv.highgui.VideoCapture"
  2. #include "common.h"
  3. #include "opencv2/opencv_modules.hpp"
  4. #ifdef HAVE_OPENCV_HIGHGUI
  5. #include "opencv2/highgui.hpp"
  6. using namespace cv;
  7. extern "C" {
  8. //
  9. // VideoCapture::VideoCapture()
  10. //
  11. JNIEXPORT jlong JNICALL Java_org_opencv_highgui_VideoCapture_n_1VideoCapture__
  12. (JNIEnv* env, jclass);
  13. JNIEXPORT jlong JNICALL Java_org_opencv_highgui_VideoCapture_n_1VideoCapture__
  14. (JNIEnv* env, jclass)
  15. {
  16. try {
  17. LOGD("highgui::VideoCapture_n_1VideoCapture__()");
  18. VideoCapture* _retval_ = new VideoCapture( );
  19. return (jlong) _retval_;
  20. } catch(cv::Exception e) {
  21. LOGD("highgui::VideoCapture_n_1VideoCapture__() catched cv::Exception: %s", e.what());
  22. jclass je = env->FindClass("org/opencv/core/CvException");
  23. if(!je) je = env->FindClass("java/lang/Exception");
  24. env->ThrowNew(je, e.what());
  25. return 0;
  26. } catch (...) {
  27. LOGD("highgui::VideoCapture_n_1VideoCapture__() catched unknown exception (...)");
  28. jclass je = env->FindClass("java/lang/Exception");
  29. env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1VideoCapture__()}");
  30. return 0;
  31. }
  32. }
  33. //
  34. // VideoCapture::VideoCapture(int device)
  35. //
  36. JNIEXPORT jlong JNICALL Java_org_opencv_highgui_VideoCapture_n_1VideoCapture__I
  37. (JNIEnv* env, jclass, jint device);
  38. JNIEXPORT jlong JNICALL Java_org_opencv_highgui_VideoCapture_n_1VideoCapture__I
  39. (JNIEnv* env, jclass, jint device)
  40. {
  41. try {
  42. LOGD("highgui::VideoCapture_n_1VideoCapture__I()");
  43. VideoCapture* _retval_ = new VideoCapture( device );
  44. return (jlong) _retval_;
  45. } catch(cv::Exception e) {
  46. LOGD("highgui::VideoCapture_n_1VideoCapture__I() catched cv::Exception: %s", e.what());
  47. jclass je = env->FindClass("org/opencv/core/CvException");
  48. if(!je) je = env->FindClass("java/lang/Exception");
  49. env->ThrowNew(je, e.what());
  50. return 0;
  51. } catch (...) {
  52. LOGD("highgui::VideoCapture_n_1VideoCapture__I() catched unknown exception (...)");
  53. jclass je = env->FindClass("java/lang/Exception");
  54. env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1VideoCapture__I()}");
  55. return 0;
  56. }
  57. }
  58. //
  59. // double VideoCapture::get(int propId)
  60. //
  61. JNIEXPORT jdouble JNICALL Java_org_opencv_highgui_VideoCapture_n_1get
  62. (JNIEnv* env, jclass, jlong self, jint propId);
  63. JNIEXPORT jdouble JNICALL Java_org_opencv_highgui_VideoCapture_n_1get
  64. (JNIEnv* env, jclass, jlong self, jint propId)
  65. {
  66. try {
  67. LOGD("highgui::VideoCapture_n_1get()");
  68. VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL
  69. double _retval_ = me->get( propId );
  70. return _retval_;
  71. } catch(cv::Exception e) {
  72. LOGD("highgui::VideoCapture_n_1get() catched cv::Exception: %s", e.what());
  73. jclass je = env->FindClass("org/opencv/core/CvException");
  74. if(!je) je = env->FindClass("java/lang/Exception");
  75. env->ThrowNew(je, e.what());
  76. return 0;
  77. } catch (...) {
  78. LOGD("highgui::VideoCapture_n_1get() catched unknown exception (...)");
  79. jclass je = env->FindClass("java/lang/Exception");
  80. env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1get()}");
  81. return 0;
  82. }
  83. }
  84. //
  85. // bool VideoCapture::grab()
  86. //
  87. JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1grab
  88. (JNIEnv* env, jclass, jlong self);
  89. JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1grab
  90. (JNIEnv* env, jclass, jlong self)
  91. {
  92. try {
  93. LOGD("highgui::VideoCapture_n_1grab()");
  94. VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL
  95. bool _retval_ = me->grab( );
  96. return _retval_;
  97. } catch(cv::Exception e) {
  98. LOGD("highgui::VideoCapture_n_1grab() catched cv::Exception: %s", e.what());
  99. jclass je = env->FindClass("org/opencv/core/CvException");
  100. if(!je) je = env->FindClass("java/lang/Exception");
  101. env->ThrowNew(je, e.what());
  102. return 0;
  103. } catch (...) {
  104. LOGD("highgui::VideoCapture_n_1grab() catched unknown exception (...)");
  105. jclass je = env->FindClass("java/lang/Exception");
  106. env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1grab()}");
  107. return 0;
  108. }
  109. }
  110. //
  111. // bool VideoCapture::isOpened()
  112. //
  113. JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1isOpened
  114. (JNIEnv* env, jclass, jlong self);
  115. JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1isOpened
  116. (JNIEnv* env, jclass, jlong self)
  117. {
  118. try {
  119. LOGD("highgui::VideoCapture_n_1isOpened()");
  120. VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL
  121. bool _retval_ = me->isOpened( );
  122. return _retval_;
  123. } catch(cv::Exception e) {
  124. LOGD("highgui::VideoCapture_n_1isOpened() catched cv::Exception: %s", e.what());
  125. jclass je = env->FindClass("org/opencv/core/CvException");
  126. if(!je) je = env->FindClass("java/lang/Exception");
  127. env->ThrowNew(je, e.what());
  128. return 0;
  129. } catch (...) {
  130. LOGD("highgui::VideoCapture_n_1isOpened() catched unknown exception (...)");
  131. jclass je = env->FindClass("java/lang/Exception");
  132. env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1isOpened()}");
  133. return 0;
  134. }
  135. }
  136. //
  137. // bool VideoCapture::open(int device)
  138. //
  139. JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1open__JI
  140. (JNIEnv* env, jclass, jlong self, jint device);
  141. JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1open__JI
  142. (JNIEnv* env, jclass, jlong self, jint device)
  143. {
  144. try {
  145. LOGD("highgui::VideoCapture_n_1open__JI()");
  146. VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL
  147. bool _retval_ = me->open( device );
  148. return _retval_;
  149. } catch(cv::Exception e) {
  150. LOGD("highgui::VideoCapture_n_1open__JI() catched cv::Exception: %s", e.what());
  151. jclass je = env->FindClass("org/opencv/core/CvException");
  152. if(!je) je = env->FindClass("java/lang/Exception");
  153. env->ThrowNew(je, e.what());
  154. return 0;
  155. } catch (...) {
  156. LOGD("highgui::VideoCapture_n_1open__JI() catched unknown exception (...)");
  157. jclass je = env->FindClass("java/lang/Exception");
  158. env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1open__JI()}");
  159. return 0;
  160. }
  161. }
  162. //
  163. // bool VideoCapture::read(Mat image)
  164. //
  165. JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1read
  166. (JNIEnv* env, jclass, jlong self, jlong image_nativeObj);
  167. JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1read
  168. (JNIEnv* env, jclass, jlong self, jlong image_nativeObj)
  169. {
  170. try {
  171. LOGD("highgui::VideoCapture_n_1read()");
  172. VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL
  173. Mat& image = *((Mat*)image_nativeObj);
  174. bool _retval_ = me->read( image );
  175. return _retval_;
  176. } catch(cv::Exception e) {
  177. LOGD("highgui::VideoCapture_n_1read() catched cv::Exception: %s", e.what());
  178. jclass je = env->FindClass("org/opencv/core/CvException");
  179. if(!je) je = env->FindClass("java/lang/Exception");
  180. env->ThrowNew(je, e.what());
  181. return 0;
  182. } catch (...) {
  183. LOGD("highgui::VideoCapture_n_1read() catched unknown exception (...)");
  184. jclass je = env->FindClass("java/lang/Exception");
  185. env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1read()}");
  186. return 0;
  187. }
  188. }
  189. //
  190. // void VideoCapture::release()
  191. //
  192. JNIEXPORT void JNICALL Java_org_opencv_highgui_VideoCapture_n_1release
  193. (JNIEnv* env, jclass, jlong self);
  194. JNIEXPORT void JNICALL Java_org_opencv_highgui_VideoCapture_n_1release
  195. (JNIEnv* env, jclass, jlong self)
  196. {
  197. try {
  198. LOGD("highgui::VideoCapture_n_1release()");
  199. VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL
  200. me->release( );
  201. return;
  202. } catch(cv::Exception e) {
  203. LOGD("highgui::VideoCapture_n_1release() catched cv::Exception: %s", e.what());
  204. jclass je = env->FindClass("org/opencv/core/CvException");
  205. if(!je) je = env->FindClass("java/lang/Exception");
  206. env->ThrowNew(je, e.what());
  207. return;
  208. } catch (...) {
  209. LOGD("highgui::VideoCapture_n_1release() catched unknown exception (...)");
  210. jclass je = env->FindClass("java/lang/Exception");
  211. env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1release()}");
  212. return;
  213. }
  214. }
  215. //
  216. // bool VideoCapture::retrieve(Mat image, int channel = 0)
  217. //
  218. JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1retrieve__JJI
  219. (JNIEnv* env, jclass, jlong self, jlong image_nativeObj, jint channel);
  220. JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1retrieve__JJI
  221. (JNIEnv* env, jclass, jlong self, jlong image_nativeObj, jint channel)
  222. {
  223. try {
  224. LOGD("highgui::VideoCapture_n_1retrieve__JJI()");
  225. VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL
  226. Mat& image = *((Mat*)image_nativeObj);
  227. bool _retval_ = me->retrieve( image, channel );
  228. return _retval_;
  229. } catch(cv::Exception e) {
  230. LOGD("highgui::VideoCapture_n_1retrieve__JJI() catched cv::Exception: %s", e.what());
  231. jclass je = env->FindClass("org/opencv/core/CvException");
  232. if(!je) je = env->FindClass("java/lang/Exception");
  233. env->ThrowNew(je, e.what());
  234. return 0;
  235. } catch (...) {
  236. LOGD("highgui::VideoCapture_n_1retrieve__JJI() catched unknown exception (...)");
  237. jclass je = env->FindClass("java/lang/Exception");
  238. env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1retrieve__JJI()}");
  239. return 0;
  240. }
  241. }
  242. JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1retrieve__JJ
  243. (JNIEnv* env, jclass, jlong self, jlong image_nativeObj);
  244. JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1retrieve__JJ
  245. (JNIEnv* env, jclass, jlong self, jlong image_nativeObj)
  246. {
  247. try {
  248. LOGD("highgui::VideoCapture_n_1retrieve__JJ()");
  249. VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL
  250. Mat& image = *((Mat*)image_nativeObj);
  251. bool _retval_ = me->retrieve( image );
  252. return _retval_;
  253. } catch(cv::Exception e) {
  254. LOGD("highgui::VideoCapture_n_1retrieve__JJ() catched cv::Exception: %s", e.what());
  255. jclass je = env->FindClass("org/opencv/core/CvException");
  256. if(!je) je = env->FindClass("java/lang/Exception");
  257. env->ThrowNew(je, e.what());
  258. return 0;
  259. } catch (...) {
  260. LOGD("highgui::VideoCapture_n_1retrieve__JJ() catched unknown exception (...)");
  261. jclass je = env->FindClass("java/lang/Exception");
  262. env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1retrieve__JJ()}");
  263. return 0;
  264. }
  265. }
  266. //
  267. // bool VideoCapture::set(int propId, double value)
  268. //
  269. JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1set
  270. (JNIEnv* env, jclass, jlong self, jint propId, jdouble value);
  271. JNIEXPORT jboolean JNICALL Java_org_opencv_highgui_VideoCapture_n_1set
  272. (JNIEnv* env, jclass, jlong self, jint propId, jdouble value)
  273. {
  274. try {
  275. LOGD("highgui::VideoCapture_n_1set()");
  276. VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL
  277. bool _retval_ = me->set( propId, value );
  278. return _retval_;
  279. } catch(cv::Exception e) {
  280. LOGD("highgui::VideoCapture_n_1set() catched cv::Exception: %s", e.what());
  281. jclass je = env->FindClass("org/opencv/core/CvException");
  282. if(!je) je = env->FindClass("java/lang/Exception");
  283. env->ThrowNew(je, e.what());
  284. return 0;
  285. } catch (...) {
  286. LOGD("highgui::VideoCapture_n_1set() catched unknown exception (...)");
  287. jclass je = env->FindClass("java/lang/Exception");
  288. env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1set()}");
  289. return 0;
  290. }
  291. }
  292. JNIEXPORT jstring JNICALL Java_org_opencv_highgui_VideoCapture_n_1getSupportedPreviewSizes
  293. (JNIEnv *env, jclass, jlong self);
  294. JNIEXPORT jstring JNICALL Java_org_opencv_highgui_VideoCapture_n_1getSupportedPreviewSizes
  295. (JNIEnv *env, jclass, jlong self)
  296. {
  297. try {
  298. LOGD("highgui::VideoCapture_n_1set()");
  299. VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL
  300. union {double prop; const char* name;} u;
  301. u.prop = me->get(CAP_PROP_ANDROID_PREVIEW_SIZES_STRING);
  302. return env->NewStringUTF(u.name);
  303. } catch(cv::Exception e) {
  304. LOGD("highgui::VideoCapture_n_1getSupportedPreviewSizes() catched cv::Exception: %s", e.what());
  305. jclass je = env->FindClass("org/opencv/core/CvException");
  306. if(!je) je = env->FindClass("java/lang/Exception");
  307. env->ThrowNew(je, e.what());
  308. return env->NewStringUTF("");
  309. } catch (...) {
  310. LOGD("highgui::VideoCapture_n_1getSupportedPreviewSizes() catched unknown exception (...)");
  311. jclass je = env->FindClass("java/lang/Exception");
  312. env->ThrowNew(je, "Unknown exception in JNI code {highgui::VideoCapture_n_1getSupportedPreviewSizes()}");
  313. return env->NewStringUTF("");
  314. }
  315. }
  316. //
  317. // native support for java finalize()
  318. // static void VideoCapture::n_delete( __int64 self )
  319. //
  320. JNIEXPORT void JNICALL Java_org_opencv_highgui_VideoCapture_n_1delete
  321. (JNIEnv*, jclass, jlong self);
  322. JNIEXPORT void JNICALL Java_org_opencv_highgui_VideoCapture_n_1delete
  323. (JNIEnv*, jclass, jlong self)
  324. {
  325. delete (VideoCapture*) self;
  326. }
  327. } // extern "C"
  328. #endif // HAVE_OPENCV_HIGHGUI