Refactor OpenCV Java Wrapping
This commit is contained in:
+124
-638
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys, re, os.path
|
||||
import json
|
||||
import logging
|
||||
from pprint import pformat
|
||||
from string import Template
|
||||
@@ -10,176 +11,23 @@ if sys.version_info[0] >= 3:
|
||||
else:
|
||||
from cStringIO import StringIO
|
||||
|
||||
class_ignore_list = (
|
||||
#core
|
||||
"FileNode", "FileStorage", "KDTree", "KeyPoint", "DMatch",
|
||||
#features2d
|
||||
"SimpleBlobDetector",
|
||||
"CirclesGridFinderParameters"
|
||||
)
|
||||
# list of class names, which should be skipped by wrapper generator
|
||||
# the list is loaded from misc/java/gen_dict.json defined for the module and its dependencies
|
||||
class_ignore_list = []
|
||||
|
||||
const_ignore_list = (
|
||||
"CV_CAP_OPENNI",
|
||||
"CV_CAP_PROP_OPENNI_",
|
||||
"CV_CAP_INTELPERC",
|
||||
"CV_CAP_PROP_INTELPERC_"
|
||||
"WINDOW_AUTOSIZE",
|
||||
"CV_WND_PROP_",
|
||||
"CV_WINDOW_",
|
||||
"CV_EVENT_",
|
||||
"CV_GUI_",
|
||||
"CV_PUSH_BUTTON",
|
||||
"CV_CHECKBOX",
|
||||
"CV_RADIOBOX",
|
||||
# list of constant names, which should be skipped by wrapper generator
|
||||
# ignored constants can be defined using regular expressions
|
||||
const_ignore_list = []
|
||||
|
||||
#attention!
|
||||
#the following constants are added to this list using code automatic generation
|
||||
#TODO: should be checked
|
||||
"CV_CAP_ANY",
|
||||
"CV_CAP_MIL",
|
||||
"CV_CAP_VFW",
|
||||
"CV_CAP_V4L",
|
||||
"CV_CAP_V4L2",
|
||||
"CV_CAP_FIREWARE",
|
||||
"CV_CAP_FIREWIRE",
|
||||
"CV_CAP_IEEE1394",
|
||||
"CV_CAP_DC1394",
|
||||
"CV_CAP_CMU1394",
|
||||
"CV_CAP_STEREO",
|
||||
"CV_CAP_TYZX",
|
||||
"CV_TYZX_LEFT",
|
||||
"CV_TYZX_RIGHT",
|
||||
"CV_TYZX_COLOR",
|
||||
"CV_TYZX_Z",
|
||||
"CV_CAP_QT",
|
||||
"CV_CAP_UNICAP",
|
||||
"CV_CAP_DSHOW",
|
||||
"CV_CAP_PVAPI",
|
||||
"CV_CAP_PROP_DC1394_OFF",
|
||||
"CV_CAP_PROP_DC1394_MODE_MANUAL",
|
||||
"CV_CAP_PROP_DC1394_MODE_AUTO",
|
||||
"CV_CAP_PROP_DC1394_MODE_ONE_PUSH_AUTO",
|
||||
"CV_CAP_PROP_POS_MSEC",
|
||||
"CV_CAP_PROP_POS_FRAMES",
|
||||
"CV_CAP_PROP_POS_AVI_RATIO",
|
||||
"CV_CAP_PROP_FPS",
|
||||
"CV_CAP_PROP_FOURCC",
|
||||
"CV_CAP_PROP_FRAME_COUNT",
|
||||
"CV_CAP_PROP_FORMAT",
|
||||
"CV_CAP_PROP_MODE",
|
||||
"CV_CAP_PROP_BRIGHTNESS",
|
||||
"CV_CAP_PROP_CONTRAST",
|
||||
"CV_CAP_PROP_SATURATION",
|
||||
"CV_CAP_PROP_HUE",
|
||||
"CV_CAP_PROP_GAIN",
|
||||
"CV_CAP_PROP_EXPOSURE",
|
||||
"CV_CAP_PROP_CONVERT_RGB",
|
||||
"CV_CAP_PROP_WHITE_BALANCE_BLUE_U",
|
||||
"CV_CAP_PROP_RECTIFICATION",
|
||||
"CV_CAP_PROP_MONOCHROME",
|
||||
"CV_CAP_PROP_SHARPNESS",
|
||||
"CV_CAP_PROP_AUTO_EXPOSURE",
|
||||
"CV_CAP_PROP_GAMMA",
|
||||
"CV_CAP_PROP_TEMPERATURE",
|
||||
"CV_CAP_PROP_TRIGGER",
|
||||
"CV_CAP_PROP_TRIGGER_DELAY",
|
||||
"CV_CAP_PROP_WHITE_BALANCE_RED_V",
|
||||
"CV_CAP_PROP_MAX_DC1394",
|
||||
"CV_CAP_GSTREAMER_QUEUE_LENGTH",
|
||||
"CV_CAP_PROP_PVAPI_MULTICASTIP",
|
||||
"CV_CAP_PROP_SUPPORTED_PREVIEW_SIZES_STRING",
|
||||
"EVENT_.*",
|
||||
"CV_L?(BGRA?|RGBA?|GRAY|XYZ|YCrCb|Luv|Lab|HLS|YUV|HSV)\d*2L?(BGRA?|RGBA?|GRAY|XYZ|YCrCb|Luv|Lab|HLS|YUV|HSV).*",
|
||||
"CV_COLORCVT_MAX",
|
||||
"CV_.*Bayer.*",
|
||||
"CV_YUV420(i|sp|p)2.+",
|
||||
"CV_TM_.+",
|
||||
"CV_FLOODFILL_.+",
|
||||
"CV_ADAPTIVE_THRESH_.+",
|
||||
"WINDOW_.+",
|
||||
"WND_PROP_.+",
|
||||
)
|
||||
|
||||
const_private_list = (
|
||||
"CV_MOP_.+",
|
||||
"CV_INTER_.+",
|
||||
"CV_THRESH_.+",
|
||||
"CV_INPAINT_.+",
|
||||
"CV_RETR_.+",
|
||||
"CV_CHAIN_APPROX_.+",
|
||||
"OPPONENTEXTRACTOR",
|
||||
"GRIDDETECTOR",
|
||||
"PYRAMIDDETECTOR",
|
||||
"DYNAMICDETECTOR",
|
||||
)
|
||||
# list of private constants
|
||||
const_private_list = []
|
||||
|
||||
# { Module : { public : [[name, val],...], private : [[]...] } }
|
||||
missing_consts = \
|
||||
{
|
||||
'Core' :
|
||||
{
|
||||
'private' :
|
||||
(
|
||||
('CV_8U', 0 ), ('CV_8S', 1 ),
|
||||
('CV_16U', 2 ), ('CV_16S', 3 ),
|
||||
('CV_32S', 4 ),
|
||||
('CV_32F', 5 ), ('CV_64F', 6 ),
|
||||
('CV_USRTYPE1', 7 ),
|
||||
), # private
|
||||
'public' :
|
||||
(
|
||||
('SVD_MODIFY_A', 1), ('SVD_NO_UV', 2), ('SVD_FULL_UV', 4),
|
||||
('FILLED', -1),
|
||||
('REDUCE_SUM', 0), ('REDUCE_AVG', 1), ('REDUCE_MAX', 2), ('REDUCE_MIN', 3),
|
||||
) #public
|
||||
}, # Core
|
||||
|
||||
"Imgproc":
|
||||
{
|
||||
'private' :
|
||||
(
|
||||
('IPL_BORDER_CONSTANT', 0 ),
|
||||
('IPL_BORDER_REPLICATE', 1 ),
|
||||
('IPL_BORDER_REFLECT', 2 ),
|
||||
('IPL_BORDER_WRAP', 3 ),
|
||||
('IPL_BORDER_REFLECT_101', 4 ),
|
||||
('IPL_BORDER_TRANSPARENT', 5 ),
|
||||
), # private
|
||||
'public' :
|
||||
(
|
||||
('LINE_AA', 16), ('LINE_8', 8), ('LINE_4', 4),
|
||||
) #public
|
||||
}, # Imgproc
|
||||
|
||||
"Calib3d":
|
||||
{
|
||||
'public' :
|
||||
(
|
||||
('CALIB_USE_INTRINSIC_GUESS', '1'),
|
||||
('CALIB_RECOMPUTE_EXTRINSIC', '2'),
|
||||
('CALIB_CHECK_COND', '4'),
|
||||
('CALIB_FIX_SKEW', '8'),
|
||||
('CALIB_FIX_K1', '16'),
|
||||
('CALIB_FIX_K2', '32'),
|
||||
('CALIB_FIX_K3', '64'),
|
||||
('CALIB_FIX_K4', '128'),
|
||||
('CALIB_FIX_INTRINSIC', '256')
|
||||
)
|
||||
}, # Calib3d
|
||||
|
||||
"Video":
|
||||
{
|
||||
'private' :
|
||||
(
|
||||
('CV_LKFLOW_INITIAL_GUESSES', 4 ),
|
||||
('CV_LKFLOW_GET_MIN_EIGENVALS', 8 ),
|
||||
) # private
|
||||
}, # Video
|
||||
|
||||
}
|
||||
|
||||
missing_consts = {}
|
||||
|
||||
# c_type : { java/jni correspondence }
|
||||
# Complex data types are configured for each module using misc/java/gen_dict.json
|
||||
|
||||
type_dict = {
|
||||
# "simple" : { j_type : "?", jn_type : "?", jni_type : "?", suffix : "?" },
|
||||
"" : { "j_type" : "", "jn_type" : "long", "jni_type" : "jlong" }, # c-tor ret_type
|
||||
@@ -195,397 +43,14 @@ type_dict = {
|
||||
"size_t" : { "j_type" : "long", "jn_type" : "long", "jni_type" : "jlong", "suffix" : "J" },
|
||||
"__int64" : { "j_type" : "long", "jn_type" : "long", "jni_type" : "jlong", "suffix" : "J" },
|
||||
"int64" : { "j_type" : "long", "jn_type" : "long", "jni_type" : "jlong", "suffix" : "J" },
|
||||
"double[]": { "j_type" : "double[]", "jn_type" : "double[]", "jni_type" : "jdoubleArray", "suffix" : "_3D" },
|
||||
|
||||
# "complex" : { j_type : "?", jn_args : (("", ""),), jn_name : "", jni_var : "", jni_name : "", "suffix" : "?" },
|
||||
|
||||
"vector_Point" : { "j_type" : "MatOfPoint", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "std::vector<Point> %(n)s", "suffix" : "J" },
|
||||
"vector_Point2f" : { "j_type" : "MatOfPoint2f", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "std::vector<Point2f> %(n)s", "suffix" : "J" },
|
||||
#"vector_Point2d" : { "j_type" : "MatOfPoint2d", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "std::vector<Point2d> %(n)s", "suffix" : "J" },
|
||||
"vector_Point3i" : { "j_type" : "MatOfPoint3", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "std::vector<Point3i> %(n)s", "suffix" : "J" },
|
||||
"vector_Point3f" : { "j_type" : "MatOfPoint3f", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "std::vector<Point3f> %(n)s", "suffix" : "J" },
|
||||
#"vector_Point3d" : { "j_type" : "MatOfPoint3d", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "std::vector<Point3d> %(n)s", "suffix" : "J" },
|
||||
"vector_KeyPoint" : { "j_type" : "MatOfKeyPoint", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "std::vector<KeyPoint> %(n)s", "suffix" : "J" },
|
||||
"vector_DMatch" : { "j_type" : "MatOfDMatch", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "std::vector<DMatch> %(n)s", "suffix" : "J" },
|
||||
"vector_Rect" : { "j_type" : "MatOfRect", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "std::vector<Rect> %(n)s", "suffix" : "J" },
|
||||
"vector_Rect2d" : { "j_type" : "MatOfRect2d", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "std::vector<Rect2d> %(n)s", "suffix" : "J" },
|
||||
"vector_uchar" : { "j_type" : "MatOfByte", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "std::vector<uchar> %(n)s", "suffix" : "J" },
|
||||
"vector_char" : { "j_type" : "MatOfByte", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "std::vector<char> %(n)s", "suffix" : "J" },
|
||||
"vector_int" : { "j_type" : "MatOfInt", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "std::vector<int> %(n)s", "suffix" : "J" },
|
||||
"vector_float" : { "j_type" : "MatOfFloat", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "std::vector<float> %(n)s", "suffix" : "J" },
|
||||
"vector_double" : { "j_type" : "MatOfDouble", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "std::vector<double> %(n)s", "suffix" : "J" },
|
||||
"vector_Vec4i" : { "j_type" : "MatOfInt4", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "std::vector<Vec4i> %(n)s", "suffix" : "J" },
|
||||
"vector_Vec4f" : { "j_type" : "MatOfFloat4", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "std::vector<Vec4f> %(n)s", "suffix" : "J" },
|
||||
"vector_Vec6f" : { "j_type" : "MatOfFloat6", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "std::vector<Vec6f> %(n)s", "suffix" : "J" },
|
||||
|
||||
"vector_Mat" : { "j_type" : "List<Mat>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "std::vector<Mat> %(n)s", "suffix" : "J" },
|
||||
|
||||
"vector_vector_KeyPoint": { "j_type" : "List<MatOfKeyPoint>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "std::vector< std::vector<KeyPoint> > %(n)s" },
|
||||
"vector_vector_DMatch" : { "j_type" : "List<MatOfDMatch>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "std::vector< std::vector<DMatch> > %(n)s" },
|
||||
"vector_vector_char" : { "j_type" : "List<MatOfByte>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "std::vector< std::vector<char> > %(n)s" },
|
||||
"vector_vector_Point" : { "j_type" : "List<MatOfPoint>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "std::vector< std::vector<Point> > %(n)s" },
|
||||
"vector_vector_Point2f" : { "j_type" : "List<MatOfPoint2f>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "std::vector< std::vector<Point2f> > %(n)s" },
|
||||
"vector_vector_Point3f" : { "j_type" : "List<MatOfPoint3f>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "std::vector< std::vector<Point3f> > %(n)s" },
|
||||
|
||||
"Mat" : { "j_type" : "Mat", "jn_type" : "long", "jn_args" : (("__int64", ".nativeObj"),),
|
||||
"jni_var" : "Mat& %(n)s = *((Mat*)%(n)s_nativeObj)",
|
||||
"jni_type" : "jlong", #"jni_name" : "*%(n)s",
|
||||
"suffix" : "J" },
|
||||
|
||||
"Point" : { "j_type" : "Point", "jn_args" : (("double", ".x"), ("double", ".y")),
|
||||
"jni_var" : "Point %(n)s((int)%(n)s_x, (int)%(n)s_y)", "jni_type" : "jdoubleArray",
|
||||
"suffix" : "DD"},
|
||||
"Point2f" : { "j_type" : "Point", "jn_args" : (("double", ".x"), ("double", ".y")),
|
||||
"jni_var" : "Point2f %(n)s((float)%(n)s_x, (float)%(n)s_y)", "jni_type" : "jdoubleArray",
|
||||
"suffix" : "DD"},
|
||||
"Point2d" : { "j_type" : "Point", "jn_args" : (("double", ".x"), ("double", ".y")),
|
||||
"jni_var" : "Point2d %(n)s(%(n)s_x, %(n)s_y)", "jni_type" : "jdoubleArray",
|
||||
"suffix" : "DD"},
|
||||
"Point3i" : { "j_type" : "Point3", "jn_args" : (("double", ".x"), ("double", ".y"), ("double", ".z")),
|
||||
"jni_var" : "Point3i %(n)s((int)%(n)s_x, (int)%(n)s_y, (int)%(n)s_z)", "jni_type" : "jdoubleArray",
|
||||
"suffix" : "DDD"},
|
||||
"Point3f" : { "j_type" : "Point3", "jn_args" : (("double", ".x"), ("double", ".y"), ("double", ".z")),
|
||||
"jni_var" : "Point3f %(n)s((float)%(n)s_x, (float)%(n)s_y, (float)%(n)s_z)", "jni_type" : "jdoubleArray",
|
||||
"suffix" : "DDD"},
|
||||
"Point3d" : { "j_type" : "Point3", "jn_args" : (("double", ".x"), ("double", ".y"), ("double", ".z")),
|
||||
"jni_var" : "Point3d %(n)s(%(n)s_x, %(n)s_y, %(n)s_z)", "jni_type" : "jdoubleArray",
|
||||
"suffix" : "DDD"},
|
||||
"KeyPoint": { "j_type" : "KeyPoint", "jn_args" : (("float", ".x"), ("float", ".y"), ("float", ".size"),
|
||||
("float", ".angle"), ("float", ".response"), ("int", ".octave"), ("int", ".class_id")),
|
||||
"jni_var" : "KeyPoint %(n)s(%(n)s_x, %(n)s_y, %(n)s_size, %(n)s_angle, %(n)s_response, %(n)s_octave, %(n)s_class_id)",
|
||||
"jni_type" : "jdoubleArray",
|
||||
"suffix" : "FFFFFII"},
|
||||
"DMatch" : { "j_type" : "DMatch", "jn_args" : ( ('int', 'queryIdx'), ('int', 'trainIdx'),
|
||||
('int', 'imgIdx'), ('float', 'distance'), ),
|
||||
"jni_var" : "DMatch %(n)s(%(n)s_queryIdx, %(n)s_trainIdx, %(n)s_imgIdx, %(n)s_distance)",
|
||||
"jni_type" : "jdoubleArray",
|
||||
"suffix" : "IIIF"},
|
||||
"Rect" : { "j_type" : "Rect", "jn_args" : (("int", ".x"), ("int", ".y"), ("int", ".width"), ("int", ".height")),
|
||||
"jni_var" : "Rect %(n)s(%(n)s_x, %(n)s_y, %(n)s_width, %(n)s_height)", "jni_type" : "jdoubleArray",
|
||||
"suffix" : "IIII"},
|
||||
"Rect2d" : { "j_type" : "Rect2d", "jn_args" : (("double", ".x"), ("double", ".y"), ("double", ".width"), ("double", ".height")),
|
||||
"jni_var" : "Rect %(n)s(%(n)s_x, %(n)s_y, %(n)s_width, %(n)s_height)", "jni_type" : "jdoubleArray",
|
||||
"suffix" : "DDDD"},
|
||||
"Size" : { "j_type" : "Size", "jn_args" : (("double", ".width"), ("double", ".height")),
|
||||
"jni_var" : "Size %(n)s((int)%(n)s_width, (int)%(n)s_height)", "jni_type" : "jdoubleArray",
|
||||
"suffix" : "DD"},
|
||||
"Size2f" : { "j_type" : "Size", "jn_args" : (("double", ".width"), ("double", ".height")),
|
||||
"jni_var" : "Size2f %(n)s((float)%(n)s_width, (float)%(n)s_height)", "jni_type" : "jdoubleArray",
|
||||
"suffix" : "DD"},
|
||||
"RotatedRect": { "j_type" : "RotatedRect", "jn_args" : (("double", ".center.x"), ("double", ".center.y"), ("double", ".size.width"), ("double", ".size.height"), ("double", ".angle")),
|
||||
"jni_var" : "RotatedRect %(n)s(cv::Point2f(%(n)s_center_x, %(n)s_center_y), cv::Size2f(%(n)s_size_width, %(n)s_size_height), %(n)s_angle)",
|
||||
"jni_type" : "jdoubleArray", "suffix" : "DDDDD"},
|
||||
"Scalar" : { "j_type" : "Scalar", "jn_args" : (("double", ".val[0]"), ("double", ".val[1]"), ("double", ".val[2]"), ("double", ".val[3]")),
|
||||
"jni_var" : "Scalar %(n)s(%(n)s_val0, %(n)s_val1, %(n)s_val2, %(n)s_val3)", "jni_type" : "jdoubleArray",
|
||||
"suffix" : "DDDD"},
|
||||
"Range" : { "j_type" : "Range", "jn_args" : (("int", ".start"), ("int", ".end")),
|
||||
"jni_var" : "Range %(n)s(%(n)s_start, %(n)s_end)", "jni_type" : "jdoubleArray",
|
||||
"suffix" : "II"},
|
||||
"CvSlice" : { "j_type" : "Range", "jn_args" : (("int", ".start"), ("int", ".end")),
|
||||
"jni_var" : "Range %(n)s(%(n)s_start, %(n)s_end)", "jni_type" : "jdoubleArray",
|
||||
"suffix" : "II"},
|
||||
"String" : { "j_type" : "String", "jn_type" : "String",
|
||||
"jni_type" : "jstring", "jni_name" : "n_%(n)s",
|
||||
"jni_var" : 'const char* utf_%(n)s = env->GetStringUTFChars(%(n)s, 0); String n_%(n)s( utf_%(n)s ? utf_%(n)s : "" ); env->ReleaseStringUTFChars(%(n)s, utf_%(n)s)',
|
||||
"suffix" : "Ljava_lang_String_2"},
|
||||
"c_string": { "j_type" : "String", "jn_type" : "String",
|
||||
"jni_type" : "jstring", "jni_name" : "n_%(n)s.c_str()",
|
||||
"jni_var" : 'const char* utf_%(n)s = env->GetStringUTFChars(%(n)s, 0); String n_%(n)s( utf_%(n)s ? utf_%(n)s : "" ); env->ReleaseStringUTFChars(%(n)s, utf_%(n)s)',
|
||||
"suffix" : "Ljava_lang_String_2"},
|
||||
"TermCriteria": { "j_type" : "TermCriteria", "jn_args" : (("int", ".type"), ("int", ".maxCount"), ("double", ".epsilon")),
|
||||
"jni_var" : "TermCriteria %(n)s(%(n)s_type, %(n)s_maxCount, %(n)s_epsilon)", "jni_type" : "jdoubleArray",
|
||||
"suffix" : "IID"},
|
||||
"CvTermCriteria": { "j_type" : "TermCriteria", "jn_args" : (("int", ".type"), ("int", ".maxCount"), ("double", ".epsilon")),
|
||||
"jni_var" : "TermCriteria %(n)s(%(n)s_type, %(n)s_maxCount, %(n)s_epsilon)", "jni_type" : "jdoubleArray",
|
||||
"suffix" : "IID"},
|
||||
"Vec2d" : { "j_type" : "double[]", "jn_args" : (("double", ".val[0]"), ("double", ".val[1]")),
|
||||
"jn_type" : "double[]",
|
||||
"jni_var" : "Vec2d %(n)s(%(n)s_val0, %(n)s_val1)", "jni_type" : "jdoubleArray",
|
||||
"suffix" : "DD"},
|
||||
"Vec3d" : { "j_type" : "double[]", "jn_args" : (("double", ".val[0]"), ("double", ".val[1]"), ("double", ".val[2]")),
|
||||
"jn_type" : "double[]",
|
||||
"jni_var" : "Vec3d %(n)s(%(n)s_val0, %(n)s_val1, %(n)s_val2)", "jni_type" : "jdoubleArray",
|
||||
"suffix" : "DDD"},
|
||||
"Moments" : {
|
||||
"j_type" : "Moments",
|
||||
"jn_args" : (("double", ".m00"), ("double", ".m10"), ("double", ".m01"), ("double", ".m20"), ("double", ".m11"),
|
||||
("double", ".m02"), ("double", ".m30"), ("double", ".m21"), ("double", ".m12"), ("double", ".m03")),
|
||||
"jni_var" : "Moments %(n)s(%(n)s_m00, %(n)s_m10, %(n)s_m01, %(n)s_m20, %(n)s_m11, %(n)s_m02, %(n)s_m30, %(n)s_m21, %(n)s_m12, %(n)s_m03)",
|
||||
"jni_type" : "jdoubleArray",
|
||||
"suffix" : "DDDDDDDDDD"},
|
||||
|
||||
"double[]": { "j_type" : "double[]", "jn_type" : "double[]", "jni_type" : "jdoubleArray", "suffix" : "_3D" }
|
||||
}
|
||||
|
||||
# { class : { func : {j_code, jn_code, cpp_code} } }
|
||||
ManualFuncs = {
|
||||
'Core' :
|
||||
{
|
||||
'minMaxLoc' : {
|
||||
'j_code' : """
|
||||
// manual port
|
||||
public static class MinMaxLocResult {
|
||||
public double minVal;
|
||||
public double maxVal;
|
||||
public Point minLoc;
|
||||
public Point maxLoc;
|
||||
|
||||
public MinMaxLocResult() {
|
||||
minVal=0; maxVal=0;
|
||||
minLoc=new Point();
|
||||
maxLoc=new Point();
|
||||
}
|
||||
}
|
||||
|
||||
// C++: minMaxLoc(Mat src, double* minVal, double* maxVal=0, Point* minLoc=0, Point* maxLoc=0, InputArray mask=noArray())
|
||||
|
||||
//javadoc: minMaxLoc(src, mask)
|
||||
public static MinMaxLocResult minMaxLoc(Mat src, Mat mask) {
|
||||
MinMaxLocResult res = new MinMaxLocResult();
|
||||
long maskNativeObj=0;
|
||||
if (mask != null) {
|
||||
maskNativeObj=mask.nativeObj;
|
||||
}
|
||||
double resarr[] = n_minMaxLocManual(src.nativeObj, maskNativeObj);
|
||||
res.minVal=resarr[0];
|
||||
res.maxVal=resarr[1];
|
||||
res.minLoc.x=resarr[2];
|
||||
res.minLoc.y=resarr[3];
|
||||
res.maxLoc.x=resarr[4];
|
||||
res.maxLoc.y=resarr[5];
|
||||
return res;
|
||||
}
|
||||
|
||||
//javadoc: minMaxLoc(src)
|
||||
public static MinMaxLocResult minMaxLoc(Mat src) {
|
||||
return minMaxLoc(src, null);
|
||||
}
|
||||
|
||||
""",
|
||||
'jn_code' :
|
||||
""" private static native double[] n_minMaxLocManual(long src_nativeObj, long mask_nativeObj);\n""",
|
||||
'cpp_code' :
|
||||
"""
|
||||
// C++: minMaxLoc(Mat src, double* minVal, double* maxVal=0, Point* minLoc=0, Point* maxLoc=0, InputArray mask=noArray())
|
||||
JNIEXPORT jdoubleArray JNICALL Java_org_opencv_core_Core_n_1minMaxLocManual (JNIEnv*, jclass, jlong, jlong);
|
||||
|
||||
JNIEXPORT jdoubleArray JNICALL Java_org_opencv_core_Core_n_1minMaxLocManual
|
||||
(JNIEnv* env, jclass, jlong src_nativeObj, jlong mask_nativeObj)
|
||||
{
|
||||
try {
|
||||
LOGD("Core::n_1minMaxLoc()");
|
||||
jdoubleArray result;
|
||||
result = env->NewDoubleArray(6);
|
||||
if (result == NULL) {
|
||||
return NULL; /* out of memory error thrown */
|
||||
}
|
||||
|
||||
Mat& src = *((Mat*)src_nativeObj);
|
||||
|
||||
double minVal, maxVal;
|
||||
Point minLoc, maxLoc;
|
||||
if (mask_nativeObj != 0) {
|
||||
Mat& mask = *((Mat*)mask_nativeObj);
|
||||
minMaxLoc(src, &minVal, &maxVal, &minLoc, &maxLoc, mask);
|
||||
} else {
|
||||
minMaxLoc(src, &minVal, &maxVal, &minLoc, &maxLoc);
|
||||
}
|
||||
|
||||
jdouble fill[6];
|
||||
fill[0]=minVal;
|
||||
fill[1]=maxVal;
|
||||
fill[2]=minLoc.x;
|
||||
fill[3]=minLoc.y;
|
||||
fill[4]=maxLoc.x;
|
||||
fill[5]=maxLoc.y;
|
||||
|
||||
env->SetDoubleArrayRegion(result, 0, 6, fill);
|
||||
|
||||
return result;
|
||||
|
||||
} catch(const cv::Exception& e) {
|
||||
LOGD("Core::n_1minMaxLoc() 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 NULL;
|
||||
} catch (...) {
|
||||
LOGD("Core::n_1minMaxLoc() catched unknown exception (...)");
|
||||
jclass je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, "Unknown exception in JNI code {core::minMaxLoc()}");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
""",
|
||||
}, # minMaxLoc
|
||||
|
||||
|
||||
## "checkRange" : #TBD
|
||||
## {'j_code' : '/* TBD: checkRange() */', 'jn_code' : '', 'cpp_code' : '' },
|
||||
|
||||
"checkHardwareSupport" : {'j_code' : '', 'jn_code' : '', 'cpp_code' : '' },
|
||||
"setUseOptimized" : {'j_code' : '', 'jn_code' : '', 'cpp_code' : '' },
|
||||
"useOptimized" : {'j_code' : '', 'jn_code' : '', 'cpp_code' : '' },
|
||||
|
||||
}, # Core
|
||||
|
||||
'Imgproc' :
|
||||
{
|
||||
'getTextSize' :
|
||||
{
|
||||
'j_code' :
|
||||
"""
|
||||
// C++: Size getTextSize(const String& text, int fontFace, double fontScale, int thickness, int* baseLine);
|
||||
//javadoc:getTextSize(text, fontFace, fontScale, thickness, baseLine)
|
||||
public static Size getTextSize(String text, int fontFace, double fontScale, int thickness, int[] baseLine) {
|
||||
if(baseLine != null && baseLine.length != 1)
|
||||
throw new java.lang.IllegalArgumentException("'baseLine' must be 'int[1]' or 'null'.");
|
||||
Size retVal = new Size(n_getTextSize(text, fontFace, fontScale, thickness, baseLine));
|
||||
return retVal;
|
||||
}
|
||||
""",
|
||||
'jn_code' :
|
||||
""" private static native double[] n_getTextSize(String text, int fontFace, double fontScale, int thickness, int[] baseLine);\n""",
|
||||
'cpp_code' :
|
||||
"""
|
||||
// C++: Size getTextSize(const String& text, int fontFace, double fontScale, int thickness, int* baseLine);
|
||||
JNIEXPORT jdoubleArray JNICALL Java_org_opencv_imgproc_Imgproc_n_1getTextSize (JNIEnv*, jclass, jstring, jint, jdouble, jint, jintArray);
|
||||
|
||||
JNIEXPORT jdoubleArray JNICALL Java_org_opencv_imgproc_Imgproc_n_1getTextSize
|
||||
(JNIEnv* env, jclass, jstring text, jint fontFace, jdouble fontScale, jint thickness, jintArray baseLine)
|
||||
{
|
||||
try {
|
||||
LOGD("Core::n_1getTextSize()");
|
||||
jdoubleArray result;
|
||||
result = env->NewDoubleArray(2);
|
||||
if (result == NULL) {
|
||||
return NULL; /* out of memory error thrown */
|
||||
}
|
||||
|
||||
const char* utf_text = env->GetStringUTFChars(text, 0);
|
||||
String n_text( utf_text ? utf_text : "" );
|
||||
env->ReleaseStringUTFChars(text, utf_text);
|
||||
|
||||
int _baseLine;
|
||||
int* pbaseLine = 0;
|
||||
|
||||
if (baseLine != NULL)
|
||||
pbaseLine = &_baseLine;
|
||||
|
||||
cv::Size rsize = cv::getTextSize(n_text, (int)fontFace, (double)fontScale, (int)thickness, pbaseLine);
|
||||
|
||||
jdouble fill[2];
|
||||
fill[0]=rsize.width;
|
||||
fill[1]=rsize.height;
|
||||
|
||||
env->SetDoubleArrayRegion(result, 0, 2, fill);
|
||||
|
||||
if (baseLine != NULL) {
|
||||
jint jbaseLine = (jint)(*pbaseLine);
|
||||
env->SetIntArrayRegion(baseLine, 0, 1, &jbaseLine);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
} catch(const cv::Exception& e) {
|
||||
LOGD("Imgproc::n_1getTextSize() 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 NULL;
|
||||
} catch (...) {
|
||||
LOGD("Imgproc::n_1getTextSize() catched unknown exception (...)");
|
||||
jclass je = env->FindClass("java/lang/Exception");
|
||||
env->ThrowNew(je, "Unknown exception in JNI code {core::getTextSize()}");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
""",
|
||||
}, # getTextSize
|
||||
|
||||
}, # Imgproc
|
||||
|
||||
'Highgui' :
|
||||
{
|
||||
"namedWindow" : {'j_code' : '', 'jn_code' : '', 'cpp_code' : '' },
|
||||
"destroyWindow" : {'j_code' : '', 'jn_code' : '', 'cpp_code' : '' },
|
||||
"destroyAllWindows" : {'j_code' : '', 'jn_code' : '', 'cpp_code' : '' },
|
||||
"startWindowThread" : {'j_code' : '', 'jn_code' : '', 'cpp_code' : '' },
|
||||
"setWindowProperty" : {'j_code' : '', 'jn_code' : '', 'cpp_code' : '' },
|
||||
"getWindowProperty" : {'j_code' : '', 'jn_code' : '', 'cpp_code' : '' },
|
||||
"getTrackbarPos" : {'j_code' : '', 'jn_code' : '', 'cpp_code' : '' },
|
||||
"setTrackbarPos" : {'j_code' : '', 'jn_code' : '', 'cpp_code' : '' },
|
||||
"imshow" : {'j_code' : '', 'jn_code' : '', 'cpp_code' : '' },
|
||||
"waitKey" : {'j_code' : '', 'jn_code' : '', 'cpp_code' : '' },
|
||||
"moveWindow" : {'j_code' : '', 'jn_code' : '', 'cpp_code' : '' },
|
||||
"resizeWindow" : {'j_code' : '', 'jn_code' : '', 'cpp_code' : '' },
|
||||
}, # Highgui
|
||||
}
|
||||
ManualFuncs = {}
|
||||
|
||||
# { class : { func : { arg_name : {"ctype" : ctype, "attrib" : [attrib]} } } }
|
||||
func_arg_fix = {
|
||||
'' : {
|
||||
'randu' : { 'low' : {"ctype" : 'double'},
|
||||
'high' : {"ctype" : 'double'} },
|
||||
'randn' : { 'mean' : {"ctype" : 'double'},
|
||||
'stddev' : {"ctype" : 'double'} },
|
||||
'inRange' : { 'lowerb' : {"ctype" : 'Scalar'},
|
||||
'upperb' : {"ctype" : 'Scalar'} },
|
||||
'goodFeaturesToTrack' : { 'corners' : {"ctype" : 'vector_Point'} },
|
||||
'findFundamentalMat' : { 'points1' : {"ctype" : 'vector_Point2f'},
|
||||
'points2' : {"ctype" : 'vector_Point2f'} },
|
||||
'cornerSubPix' : { 'corners' : {"ctype" : 'vector_Point2f'} },
|
||||
'minEnclosingCircle' : { 'points' : {"ctype" : 'vector_Point2f'} },
|
||||
'findHomography' : { 'srcPoints' : {"ctype" : 'vector_Point2f'},
|
||||
'dstPoints' : {"ctype" : 'vector_Point2f'} },
|
||||
'solvePnP' : { 'objectPoints' : {"ctype" : 'vector_Point3f'},
|
||||
'imagePoints' : {"ctype" : 'vector_Point2f'},
|
||||
'distCoeffs' : {"ctype" : 'vector_double' } },
|
||||
'solvePnPRansac' : { 'objectPoints' : {"ctype" : 'vector_Point3f'},
|
||||
'imagePoints' : {"ctype" : 'vector_Point2f'},
|
||||
'distCoeffs' : {"ctype" : 'vector_double' } },
|
||||
'calcOpticalFlowPyrLK' : { 'prevPts' : {"ctype" : 'vector_Point2f'},
|
||||
'nextPts' : {"ctype" : 'vector_Point2f'},
|
||||
'status' : {"ctype" : 'vector_uchar'},
|
||||
'err' : {"ctype" : 'vector_float'} },
|
||||
'fitEllipse' : { 'points' : {"ctype" : 'vector_Point2f'} },
|
||||
'fillPoly' : { 'pts' : {"ctype" : 'vector_vector_Point'} },
|
||||
'polylines' : { 'pts' : {"ctype" : 'vector_vector_Point'} },
|
||||
'fillConvexPoly' : { 'points' : {"ctype" : 'vector_Point'} },
|
||||
'boundingRect' : { 'points' : {"ctype" : 'vector_Point'} },
|
||||
'approxPolyDP' : { 'curve' : {"ctype" : 'vector_Point2f'},
|
||||
'approxCurve' : {"ctype" : 'vector_Point2f'} },
|
||||
'arcLength' : { 'curve' : {"ctype" : 'vector_Point2f'} },
|
||||
'pointPolygonTest' : { 'contour' : {"ctype" : 'vector_Point2f'} },
|
||||
'minAreaRect' : { 'points' : {"ctype" : 'vector_Point2f'} },
|
||||
'getAffineTransform' : { 'src' : {"ctype" : 'vector_Point2f'},
|
||||
'dst' : {"ctype" : 'vector_Point2f'} },
|
||||
'hconcat' : { 'src' : {"ctype" : 'vector_Mat'} },
|
||||
'vconcat' : { 'src' : {"ctype" : 'vector_Mat'} },
|
||||
'undistortPoints' : { 'src' : {"ctype" : 'vector_Point2f'},
|
||||
'dst' : {"ctype" : 'vector_Point2f'} },
|
||||
'checkRange' : {'pos' : {"ctype" : '*'} },
|
||||
'meanStdDev' : { 'mean' : {"ctype" : 'vector_double'},
|
||||
'stddev' : {"ctype" : 'vector_double'} },
|
||||
'drawContours' : {'contours' : {"ctype" : 'vector_vector_Point'} },
|
||||
'findContours' : {'contours' : {"ctype" : 'vector_vector_Point'} },
|
||||
'convexityDefects' : { 'contour' : {"ctype" : 'vector_Point'},
|
||||
'convexhull' : {"ctype" : 'vector_int'},
|
||||
'convexityDefects' : {"ctype" : 'vector_Vec4i'} },
|
||||
'isContourConvex' : { 'contour' : {"ctype" : 'vector_Point'} },
|
||||
'convexHull' : { 'points' : {"ctype" : 'vector_Point'},
|
||||
'hull' : {"ctype" : 'vector_int'},
|
||||
'returnPoints' : {"ctype" : ''} },
|
||||
'projectPoints' : { 'objectPoints' : {"ctype" : 'vector_Point3f'},
|
||||
'imagePoints' : {"ctype" : 'vector_Point2f'},
|
||||
'distCoeffs' : {"ctype" : 'vector_double' } },
|
||||
'initCameraMatrix2D' : { 'objectPoints' : {"ctype" : 'vector_vector_Point3f'},
|
||||
'imagePoints' : {"ctype" : 'vector_vector_Point2f'} },
|
||||
'findChessboardCorners' : { 'corners' : {"ctype" : 'vector_Point2f'} },
|
||||
'drawChessboardCorners' : { 'corners' : {"ctype" : 'vector_Point2f'} },
|
||||
'mixChannels' : { 'dst' : {"attrib" : []} },
|
||||
}, # '', i.e. no class
|
||||
} # func_arg_fix
|
||||
func_arg_fix = {}
|
||||
|
||||
def getLibVersion(version_hpp_path):
|
||||
version_file = open(version_hpp_path, "rt").read()
|
||||
@@ -808,33 +273,15 @@ class ClassInfo(GeneralInfo):
|
||||
return ["import %s;" % c for c in sorted(self.imports) if not c.startswith('org.opencv.'+module)]
|
||||
|
||||
def addImports(self, ctype):
|
||||
if ctype.startswith('vector_vector'):
|
||||
self.imports.add("org.opencv.core.Mat")
|
||||
self.imports.add("org.opencv.utils.Converters")
|
||||
self.imports.add("java.util.List")
|
||||
self.imports.add("java.util.ArrayList")
|
||||
self.addImports(ctype.replace('vector_vector', 'vector'))
|
||||
elif ctype.startswith('Feature2D'):
|
||||
self.imports.add("org.opencv.features2d.Feature2D")
|
||||
elif ctype.startswith('vector'):
|
||||
self.imports.add("org.opencv.core.Mat")
|
||||
self.imports.add('java.util.ArrayList')
|
||||
if type_dict[ctype]['j_type'].startswith('MatOf'):
|
||||
self.imports.add("org.opencv.core." + type_dict[ctype]['j_type'])
|
||||
else:
|
||||
if ctype in type_dict:
|
||||
if "j_import" in type_dict[ctype]:
|
||||
self.imports.add(type_dict[ctype]["j_import"])
|
||||
if "v_type" in type_dict[ctype]:
|
||||
self.imports.add("java.util.List")
|
||||
self.imports.add("java.util.ArrayList")
|
||||
self.imports.add("org.opencv.utils.Converters")
|
||||
self.addImports(ctype.replace('vector_', ''))
|
||||
else:
|
||||
j_type = ''
|
||||
if ctype in type_dict:
|
||||
j_type = type_dict[ctype]['j_type']
|
||||
elif ctype in ("Algorithm"):
|
||||
j_type = ctype
|
||||
if j_type in ( "CvType", "Mat", "Point", "Point3", "Range", "Rect", "Rect2d", "RotatedRect", "Scalar", "Size", "TermCriteria", "Algorithm" ):
|
||||
self.imports.add("org.opencv.core." + j_type)
|
||||
if j_type == 'String':
|
||||
self.imports.add("java.lang.String")
|
||||
if type_dict[ctype]["v_type"] in ("Mat", "vector_Mat"):
|
||||
self.imports.add("org.opencv.core.Mat")
|
||||
|
||||
def getAllMethods(self):
|
||||
result = []
|
||||
@@ -900,10 +347,6 @@ class ArgInfo():
|
||||
if ctype.endswith("*"):
|
||||
ctype = ctype[:-1]
|
||||
self.pointer = True
|
||||
if ctype == 'vector_Point2d':
|
||||
ctype = 'vector_Point2f'
|
||||
elif ctype == 'vector_Point3d':
|
||||
ctype = 'vector_Point3f'
|
||||
self.ctype = ctype
|
||||
self.name = arg_tuple[1]
|
||||
self.defval = arg_tuple[2]
|
||||
@@ -933,7 +376,7 @@ class FuncInfo(GeneralInfo):
|
||||
self.static = ["","static"][ "/S" in decl[2] ]
|
||||
self.ctype = re.sub(r"^CvTermCriteria", "TermCriteria", decl[1] or "")
|
||||
self.args = []
|
||||
func_fix_map = func_arg_fix.get(self.classname, {}).get(self.jname, {})
|
||||
func_fix_map = func_arg_fix.get(self.jname, {})
|
||||
for a in decl[3]:
|
||||
arg = a[:]
|
||||
arg_fix_map = func_fix_map.get(arg[1], {})
|
||||
@@ -1199,46 +642,55 @@ class JavaWrapperGenerator(object):
|
||||
if not a.ctype: # hidden
|
||||
continue
|
||||
ci.addImports(a.ctype)
|
||||
if "vector" in a.ctype: # pass as Mat
|
||||
jn_args.append ( ArgInfo([ "__int64", "%s_mat.nativeObj" % a.name, "", [], "" ]) )
|
||||
jni_args.append ( ArgInfo([ "__int64", "%s_mat_nativeObj" % a.name, "", [], "" ]) )
|
||||
c_prologue.append( type_dict[a.ctype]["jni_var"] % {"n" : a.name} + ";" )
|
||||
c_prologue.append( "Mat& %(n)s_mat = *((Mat*)%(n)s_mat_nativeObj)" % {"n" : a.name} + ";" )
|
||||
if "I" in a.out or not a.out:
|
||||
if a.ctype.startswith("vector_vector_"):
|
||||
j_prologue.append( "List<Mat> %(n)s_tmplm = new ArrayList<Mat>((%(n)s != null) ? %(n)s.size() : 0);" % {"n" : a.name } )
|
||||
j_prologue.append( "Mat %(n)s_mat = Converters.%(t)s_to_Mat(%(n)s, %(n)s_tmplm);" % {"n" : a.name, "t" : a.ctype} )
|
||||
if "v_type" in type_dict[a.ctype]: # pass as vector
|
||||
if type_dict[a.ctype]["v_type"] in ("Mat", "vector_Mat"): #pass as Mat or vector_Mat
|
||||
jn_args.append ( ArgInfo([ "__int64", "%s_mat.nativeObj" % a.name, "", [], "" ]) )
|
||||
jni_args.append ( ArgInfo([ "__int64", "%s_mat_nativeObj" % a.name, "", [], "" ]) )
|
||||
c_prologue.append( type_dict[a.ctype]["jni_var"] % {"n" : a.name} + ";" )
|
||||
c_prologue.append( "Mat& %(n)s_mat = *((Mat*)%(n)s_mat_nativeObj)" % {"n" : a.name} + ";" )
|
||||
if "I" in a.out or not a.out:
|
||||
if type_dict[a.ctype]["v_type"] == "vector_Mat":
|
||||
j_prologue.append( "List<Mat> %(n)s_tmplm = new ArrayList<Mat>((%(n)s != null) ? %(n)s.size() : 0);" % {"n" : a.name } )
|
||||
j_prologue.append( "Mat %(n)s_mat = Converters.%(t)s_to_Mat(%(n)s, %(n)s_tmplm);" % {"n" : a.name, "t" : a.ctype} )
|
||||
else:
|
||||
if not type_dict[a.ctype]["j_type"].startswith("MatOf"):
|
||||
j_prologue.append( "Mat %(n)s_mat = Converters.%(t)s_to_Mat(%(n)s);" % {"n" : a.name, "t" : a.ctype} )
|
||||
else:
|
||||
j_prologue.append( "Mat %s_mat = %s;" % (a.name, a.name) )
|
||||
c_prologue.append( "Mat_to_%(t)s( %(n)s_mat, %(n)s );" % {"n" : a.name, "t" : a.ctype} )
|
||||
else:
|
||||
if not type_dict[a.ctype]["j_type"].startswith("MatOf"):
|
||||
j_prologue.append( "Mat %(n)s_mat = Converters.%(t)s_to_Mat(%(n)s);" % {"n" : a.name, "t" : a.ctype} )
|
||||
j_prologue.append( "Mat %s_mat = new Mat();" % a.name )
|
||||
else:
|
||||
j_prologue.append( "Mat %s_mat = %s;" % (a.name, a.name) )
|
||||
c_prologue.append( "Mat_to_%(t)s( %(n)s_mat, %(n)s );" % {"n" : a.name, "t" : a.ctype} )
|
||||
else:
|
||||
if not type_dict[a.ctype]["j_type"].startswith("MatOf"):
|
||||
j_prologue.append( "Mat %s_mat = new Mat();" % a.name )
|
||||
else:
|
||||
j_prologue.append( "Mat %s_mat = %s;" % (a.name, a.name) )
|
||||
if "O" in a.out:
|
||||
if not type_dict[a.ctype]["j_type"].startswith("MatOf"):
|
||||
j_epilogue.append("Converters.Mat_to_%(t)s(%(n)s_mat, %(n)s);" % {"t" : a.ctype, "n" : a.name})
|
||||
j_epilogue.append( "%s_mat.release();" % a.name )
|
||||
c_epilogue.append( "%(t)s_to_Mat( %(n)s, %(n)s_mat );" % {"n" : a.name, "t" : a.ctype} )
|
||||
if "O" in a.out:
|
||||
if not type_dict[a.ctype]["j_type"].startswith("MatOf"):
|
||||
j_epilogue.append("Converters.Mat_to_%(t)s(%(n)s_mat, %(n)s);" % {"t" : a.ctype, "n" : a.name})
|
||||
j_epilogue.append( "%s_mat.release();" % a.name )
|
||||
c_epilogue.append( "%(t)s_to_Mat( %(n)s, %(n)s_mat );" % {"n" : a.name, "t" : a.ctype} )
|
||||
else: #pass as list
|
||||
jn_args.append ( ArgInfo([ a.ctype, a.name, "", [], "" ]) )
|
||||
jni_args.append ( ArgInfo([ a.ctype, "%s_list" % a.name , "", [], "" ]) )
|
||||
c_prologue.append(type_dict[a.ctype]["jni_var"] % {"n" : a.name} + ";")
|
||||
if "I" in a.out or not a.out:
|
||||
c_prologue.append("%(n)s = List_to_%(t)s(env, %(n)s_list);" % {"n" : a.name, "t" : a.ctype})
|
||||
if "O" in a.out:
|
||||
c_epilogue.append("Copy_%s_to_List(env,%s,%s_list);" % (a.ctype, a.name, a.name))
|
||||
else:
|
||||
fields = type_dict[a.ctype].get("jn_args", ((a.ctype, ""),))
|
||||
if "I" in a.out or not a.out or self.isWrapped(a.ctype): # input arg, pass by primitive fields
|
||||
for f in fields:
|
||||
jn_args.append ( ArgInfo([ f[0], a.name + f[1], "", [], "" ]) )
|
||||
jni_args.append( ArgInfo([ f[0], a.name + f[1].replace(".","_").replace("[","").replace("]","").replace("_getNativeObjAddr()","_nativeObj"), "", [], "" ]) )
|
||||
if a.out and not self.isWrapped(a.ctype): # out arg, pass as double[]
|
||||
if "O" in a.out and not self.isWrapped(a.ctype): # out arg, pass as double[]
|
||||
jn_args.append ( ArgInfo([ "double[]", "%s_out" % a.name, "", [], "" ]) )
|
||||
jni_args.append ( ArgInfo([ "double[]", "%s_out" % a.name, "", [], "" ]) )
|
||||
j_prologue.append( "double[] %s_out = new double[%i];" % (a.name, len(fields)) )
|
||||
c_epilogue.append( \
|
||||
"jdouble tmp_%(n)s[%(cnt)i] = {%(args)s}; env->SetDoubleArrayRegion(%(n)s_out, 0, %(cnt)i, tmp_%(n)s);" %
|
||||
{ "n" : a.name, "cnt" : len(fields), "args" : ", ".join(["(jdouble)" + a.name + f[1] for f in fields]) } )
|
||||
if a.ctype in ('bool', 'int', 'long', 'float', 'double'):
|
||||
j_epilogue.append('if(%(n)s!=null) %(n)s[0] = (%(t)s)%(n)s_out[0];' % {'n':a.name,'t':a.ctype})
|
||||
if type_dict[a.ctype]["j_type"] in ('bool', 'int', 'long', 'float', 'double'):
|
||||
j_epilogue.append('if(%(n)s!=null) %(n)s[0] = (%(t)s)%(n)s_out[0];' % {'n':a.name,'t':type_dict[a.ctype]["j_type"]})
|
||||
else:
|
||||
set_vals = []
|
||||
i = 0
|
||||
@@ -1255,7 +707,7 @@ class JavaWrapperGenerator(object):
|
||||
if not a.ctype: #hidden
|
||||
continue
|
||||
jt = type_dict[a.ctype]["j_type"]
|
||||
if a.out and a.ctype in ('bool', 'int', 'long', 'float', 'double'):
|
||||
if a.out and jt in ('bool', 'int', 'long', 'float', 'double'):
|
||||
jt += '[]'
|
||||
j_args.append( jt + ' ' + a.name )
|
||||
j_signature = type_dict[fi.ctype]["j_type"] + " " + \
|
||||
@@ -1299,15 +751,16 @@ class JavaWrapperGenerator(object):
|
||||
ret_val = type_dict[ret_type]["j_type"] + " retVal = "
|
||||
tail = ""
|
||||
ret = "return retVal;"
|
||||
if ret_type.startswith('vector'):
|
||||
tail = ")"
|
||||
if "v_type" in type_dict[ret_type]:
|
||||
j_type = type_dict[ret_type]["j_type"]
|
||||
if j_type.startswith('MatOf'):
|
||||
ret_val += j_type + ".fromNativeAddr("
|
||||
else:
|
||||
ret_val = "Mat retValMat = new Mat("
|
||||
j_prologue.append( j_type + ' retVal = new Array' + j_type+'();')
|
||||
j_epilogue.append('Converters.Mat_to_' + ret_type + '(retValMat, retVal);')
|
||||
if type_dict[ret_type]["v_type"] in ("Mat", "vector_Mat"):
|
||||
tail = ")"
|
||||
if j_type.startswith('MatOf'):
|
||||
ret_val += j_type + ".fromNativeAddr("
|
||||
else:
|
||||
ret_val = "Mat retValMat = new Mat("
|
||||
j_prologue.append( j_type + ' retVal = new Array' + j_type+'();')
|
||||
j_epilogue.append('Converters.Mat_to_' + ret_type + '(retValMat, retVal);')
|
||||
elif ret_type.startswith("Ptr_"):
|
||||
ret_val = type_dict[fi.ctype]["j_type"] + " retVal = new " + type_dict[ret_type]["j_type"] + "("
|
||||
tail = ")"
|
||||
@@ -1367,8 +820,11 @@ class JavaWrapperGenerator(object):
|
||||
default = "return;"
|
||||
elif not fi.ctype: # c-tor
|
||||
ret = "return (jlong) _retval_;"
|
||||
elif fi.ctype.startswith('vector'): # c-tor
|
||||
ret = "return (jlong) _retval_;"
|
||||
elif "v_type" in type_dict[fi.ctype]: # c-tor
|
||||
if type_dict[fi.ctype]["v_type"] in ("Mat", "vector_Mat"):
|
||||
ret = "return (jlong) _retval_;"
|
||||
else: # returned as jobject
|
||||
ret = "return _retval_;"
|
||||
elif fi.ctype == "String":
|
||||
ret = "return env->NewStringUTF(_retval_.c_str());"
|
||||
default = 'return env->NewStringUTF("");'
|
||||
@@ -1396,10 +852,13 @@ class JavaWrapperGenerator(object):
|
||||
retval = ""
|
||||
elif fi.ctype == "String":
|
||||
retval = "cv::" + retval
|
||||
elif fi.ctype.startswith('vector'):
|
||||
elif "v_type" in type_dict[fi.ctype]: # vector is returned
|
||||
retval = type_dict[fi.ctype]['jni_var'] % {"n" : '_ret_val_vector_'} + " = "
|
||||
c_epilogue.append("Mat* _retval_ = new Mat();")
|
||||
c_epilogue.append(fi.ctype+"_to_Mat(_ret_val_vector_, *_retval_);")
|
||||
if type_dict[fi.ctype]["v_type"] in ("Mat", "vector_Mat"):
|
||||
c_epilogue.append("Mat* _retval_ = new Mat();")
|
||||
c_epilogue.append(fi.ctype+"_to_Mat(_ret_val_vector_, *_retval_);")
|
||||
else:
|
||||
c_epilogue.append("jobject _retval_ = " + fi.ctype + "_to_List(env, _ret_val_vector_);")
|
||||
if len(fi.classname)>0:
|
||||
if not fi.ctype: # c-tor
|
||||
retval = fi.fullClass(isCPP=True) + "* _retval_ = "
|
||||
@@ -1425,7 +884,7 @@ class JavaWrapperGenerator(object):
|
||||
if not a.ctype: # hidden
|
||||
jni_name = a.defval
|
||||
cvargs.append( type_dict[a.ctype].get("jni_name", jni_name) % {"n" : a.name})
|
||||
if "vector" not in a.ctype :
|
||||
if "v_type" not in type_dict[a.ctype]:
|
||||
if ("I" in a.out or not a.out or self.isWrapped(a.ctype)) and "jni_var" in type_dict[a.ctype]: # complex type
|
||||
c_prologue.append(type_dict[a.ctype]["jni_var"] % {"n" : a.name} + ";")
|
||||
if a.out and "I" not in a.out and not self.isWrapped(a.ctype) and a.ctype:
|
||||
@@ -1521,9 +980,9 @@ JNIEXPORT $rtype JNICALL Java_org_opencv_${module}_${clazz}_$fname
|
||||
# manual ports
|
||||
if ci.name in ManualFuncs:
|
||||
for func in ManualFuncs[ci.name].keys():
|
||||
ci.j_code.write ( ManualFuncs[ci.name][func]["j_code"] )
|
||||
ci.jn_code.write( ManualFuncs[ci.name][func]["jn_code"] )
|
||||
ci.cpp_code.write( ManualFuncs[ci.name][func]["cpp_code"] )
|
||||
ci.j_code.write ( "\n".join(ManualFuncs[ci.name][func]["j_code"]) )
|
||||
ci.jn_code.write( "\n".join(ManualFuncs[ci.name][func]["jn_code"]) )
|
||||
ci.cpp_code.write( "\n".join(ManualFuncs[ci.name][func]["cpp_code"]) )
|
||||
|
||||
if ci.name != self.Module or ci.base:
|
||||
# finalize()
|
||||
@@ -1596,30 +1055,57 @@ JNIEXPORT void JNICALL Java_org_opencv_%(module)s_%(j_cls)s_delete
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 4:
|
||||
print("Usage:\n", \
|
||||
os.path.basename(sys.argv[0]), \
|
||||
"<full path to hdr_parser.py> <module name> <C++ header> [<C++ header>...]")
|
||||
print("Current args are: ", ", ".join(["'"+a+"'" for a in sys.argv]))
|
||||
exit(0)
|
||||
|
||||
dstdir = "."
|
||||
hdr_parser_path = os.path.abspath(sys.argv[1])
|
||||
# parse command line parameters
|
||||
import argparse
|
||||
arg_parser = argparse.ArgumentParser(description='OpenCV Java Wrapper Generator')
|
||||
arg_parser.add_argument('-p', '--parser', required=True, help='OpenCV header parser')
|
||||
arg_parser.add_argument('-m', '--module', required=True, help='OpenCV module name')
|
||||
arg_parser.add_argument('-s', '--srcfiles', required=True, nargs='+', help='Source headers to be wrapped')
|
||||
arg_parser.add_argument('-c', '--common', nargs='*', help='Common headers')
|
||||
arg_parser.add_argument('-t', '--gendict', nargs='*', help='Custom module dictionaries for C++ to Java conversion')
|
||||
|
||||
args=arg_parser.parse_args()
|
||||
|
||||
# import header parser
|
||||
hdr_parser_path = os.path.abspath(args.parser)
|
||||
if hdr_parser_path.endswith(".py"):
|
||||
hdr_parser_path = os.path.dirname(hdr_parser_path)
|
||||
sys.path.append(hdr_parser_path)
|
||||
import hdr_parser
|
||||
module = sys.argv[2]
|
||||
srcfiles = sys.argv[3:]
|
||||
common_headers = []
|
||||
if '--common' in srcfiles:
|
||||
pos = srcfiles.index('--common')
|
||||
common_headers = srcfiles[pos+1:]
|
||||
srcfiles = srcfiles[:pos]
|
||||
|
||||
module = args.module
|
||||
srcfiles = args.srcfiles
|
||||
common_headers= args.common
|
||||
gen_dict_files = args.gendict
|
||||
|
||||
dstdir = "."
|
||||
|
||||
# initialize logger
|
||||
logging.basicConfig(filename='%s/%s.log' % (dstdir, module), format=None, filemode='w', level=logging.INFO)
|
||||
handler = logging.StreamHandler()
|
||||
handler.setLevel(logging.WARNING)
|
||||
logging.getLogger().addHandler(handler)
|
||||
#print("Generating module '" + module + "' from headers:\n\t" + "\n\t".join(srcfiles))
|
||||
|
||||
# load dictionaries
|
||||
for gdf in gen_dict_files:
|
||||
with open(gdf) as f:
|
||||
gen_type_dict = json.load(f)
|
||||
if "class_ignore_list" in gen_type_dict:
|
||||
class_ignore_list += gen_type_dict["class_ignore_list"]
|
||||
if "const_ignore_list" in gen_type_dict:
|
||||
const_ignore_list += gen_type_dict["const_ignore_list"]
|
||||
if "const_private_list" in gen_type_dict:
|
||||
const_private_list += gen_type_dict["const_private_list"]
|
||||
if "missing_consts" in gen_type_dict:
|
||||
missing_consts.update(gen_type_dict["missing_consts"])
|
||||
if "type_dict" in gen_type_dict:
|
||||
type_dict.update(gen_type_dict["type_dict"])
|
||||
if "ManualFuncs" in gen_type_dict:
|
||||
ManualFuncs.update(gen_type_dict["ManualFuncs"])
|
||||
if "func_arg_fix" in gen_type_dict:
|
||||
func_arg_fix.update(gen_type_dict["func_arg_fix"])
|
||||
|
||||
# launch Java Wrapper generator
|
||||
generator = JavaWrapperGenerator()
|
||||
generator.gen(srcfiles, module, dstdir, common_headers)
|
||||
|
||||
Reference in New Issue
Block a user