feat: 切换后端至PaddleOCR-NCNN,切换工程为CMake

1.项目后端整体迁移至PaddleOCR-NCNN算法,已通过基本的兼容性测试
2.工程改为使用CMake组织,后续为了更好地兼容第三方库,不再提供QMake工程
3.重整权利声明文件,重整代码工程,确保最小化侵权风险

Log: 切换后端至PaddleOCR-NCNN,切换工程为CMake
Change-Id: I4d5d2c5d37505a4a24b389b1a4c5d12f17bfa38c
This commit is contained in:
wangzhengyang
2022-05-10 09:54:44 +08:00
parent ecdd171c6f
commit 718c41634f
10018 changed files with 3593797 additions and 186748 deletions

View File

@ -0,0 +1,4 @@
include/opencv2/core/base.hpp
include/opencv2/core.hpp
include/opencv2/core/utility.hpp
misc/java/src/cpp/core_manual.hpp

View File

@ -0,0 +1,907 @@
{
"module_imports": [ "java.lang.String" ],
"module_j_code": "src/java/core+Core.jcode.in",
"class_ignore_list" : [
"FileNode",
"FileStorage",
"KDTree",
"KeyPoint",
"DMatch"
],
"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 ]
],
"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]
]
}
},
"ManualFuncs" : {
"Core" : {
"minMaxLoc" : {
"j_code" : [
"// manual port",
"public static class MinMaxLocResult {",
" public double minVal;",
" public double maxVal;",
" public Point minLoc;",
" public Point maxLoc;",
"\n",
" public MinMaxLocResult() {",
" minVal=0; maxVal=0;",
" minLoc=new Point();",
" maxLoc=new Point();",
" }",
"}",
"\n",
"// C++: minMaxLoc(Mat src, double* minVal, double* maxVal=0, Point* minLoc=0, Point* maxLoc=0, InputArray mask=noArray())",
"\n",
"//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;",
"}",
"\n",
"//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);",
"\n",
"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 */",
" }",
"\n",
" Mat& src = *((Mat*)src_nativeObj);",
"\n",
" 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);",
" }",
"\n",
" 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;",
"\n",
" env->SetDoubleArrayRegion(result, 0, 6, fill);",
"\n",
" return result;",
"\n",
" } catch(const cv::Exception& e) {",
" LOGD(\"Core::n_1minMaxLoc() caught 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() caught unknown exception (...)\");",
" jclass je = env->FindClass(\"java/lang/Exception\");",
" env->ThrowNew(je, \"Unknown exception in JNI code {core::minMaxLoc()}\");",
" return NULL;",
" }",
"}",
"\n"
]
},
"checkHardwareSupport" : {"j_code" : [""], "jn_code" : [""], "cpp_code" : [""] },
"setUseOptimized" : {"j_code" : [""], "jn_code" : [""], "cpp_code" : [""] },
"useOptimized" : {"j_code" : [""], "jn_code" : [""], "cpp_code" : [""] }
}
},
"func_arg_fix" : {
"randu" : { "low" : {"ctype" : "double"},
"high" : {"ctype" : "double"} },
"randn" : { "mean" : {"ctype" : "double"},
"stddev" : {"ctype" : "double"} },
"inRange" : { "lowerb" : {"ctype" : "Scalar"},
"upperb" : {"ctype" : "Scalar"} },
"boundingRect" : { "points" : {"ctype" : "vector_Point"} },
"hconcat" : { "src" : {"ctype" : "vector_Mat"} },
"vconcat" : { "src" : {"ctype" : "vector_Mat"} },
"checkRange" : {"pos" : {"ctype" : "*"} },
"meanStdDev" : { "mean" : {"ctype" : "vector_double"},
"stddev" : {"ctype" : "vector_double"} },
"mixChannels" : { "dst" : {"attrib" : []} }
},
"type_dict" : {
"Algorithm": {
"j_type": "Feature2D",
"jn_type": "long",
"jni_type": "jlong",
"jni_var": "Feature2D %(n)s",
"suffix": "J",
"j_import": "org.opencv.core.Algorithm"
},
"CvSlice": {
"j_type": "Range",
"jn_args": [
[
"int",
".start"
],
[
"int",
".end"
]
],
"jni_type": "jdoubleArray",
"jni_var": "Range %(n)s(%(n)s_start, %(n)s_end)",
"suffix": "II",
"j_import": "org.opencv.core.Range"
},
"CvTermCriteria": {
"j_type": "TermCriteria",
"jn_args": [
[
"int",
".type"
],
[
"int",
".maxCount"
],
[
"double",
".epsilon"
]
],
"jni_type": "jdoubleArray",
"jni_var": "TermCriteria %(n)s(%(n)s_type, %(n)s_maxCount, %(n)s_epsilon)",
"suffix": "IID",
"j_import": "org.opencv.core.TermCriteria"
},
"DMatch": {
"j_type": "DMatch",
"jn_args": [
[
"int",
"queryIdx"
],
[
"int",
"trainIdx"
],
[
"int",
"imgIdx"
],
[
"float",
"distance"
]
],
"jni_type": "jdoubleArray",
"jni_var": "DMatch %(n)s(%(n)s_queryIdx, %(n)s_trainIdx, %(n)s_imgIdx, %(n)s_distance)",
"suffix": "IIIF",
"j_import": "org.opencv.core.DMatch"
},
"KeyPoint": {
"j_type": "KeyPoint",
"jn_args": [
[
"float",
".x"
],
[
"float",
".y"
],
[
"float",
".size"
],
[
"float",
".angle"
],
[
"float",
".response"
],
[
"int",
".octave"
],
[
"int",
".class_id"
]
],
"jni_type": "jdoubleArray",
"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)",
"suffix": "FFFFFII",
"j_import": "org.opencv.core.KeyPoint"
},
"Mat": {
"j_type": "Mat",
"jn_args": [
[
"__int64",
".nativeObj"
]
],
"jn_type": "long",
"jni_type": "jlong",
"jni_var": "Mat& %(n)s = *((Mat*)%(n)s_nativeObj)",
"suffix": "J",
"j_import": "org.opencv.core.Mat"
},
"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_type": "jdoubleArray",
"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)",
"suffix": "DDDDDDDDDD"
},
"Point": {
"j_type": "Point",
"jn_args": [
[
"double",
".x"
],
[
"double",
".y"
]
],
"jni_type": "jdoubleArray",
"jni_var": "Point %(n)s((int)%(n)s_x, (int)%(n)s_y)",
"suffix": "DD",
"j_import": "org.opencv.core.Point"
},
"Point2d": {
"j_type": "Point",
"jn_args": [
[
"double",
".x"
],
[
"double",
".y"
]
],
"jni_type": "jdoubleArray",
"jni_var": "Point2d %(n)s(%(n)s_x, %(n)s_y)",
"suffix": "DD",
"j_import": "org.opencv.core.Point"
},
"Point2f": {
"j_type": "Point",
"jn_args": [
[
"double",
".x"
],
[
"double",
".y"
]
],
"jni_type": "jdoubleArray",
"jni_var": "Point2f %(n)s((float)%(n)s_x, (float)%(n)s_y)",
"suffix": "DD",
"j_import": "org.opencv.core.Point"
},
"Point3d": {
"j_type": "Point3",
"jn_args": [
[
"double",
".x"
],
[
"double",
".y"
],
[
"double",
".z"
]
],
"jni_type": "jdoubleArray",
"jni_var": "Point3d %(n)s(%(n)s_x, %(n)s_y, %(n)s_z)",
"suffix": "DDD",
"j_import": "org.opencv.core.Point3"
},
"Point3f": {
"j_type": "Point3",
"jn_args": [
[
"double",
".x"
],
[
"double",
".y"
],
[
"double",
".z"
]
],
"jni_type": "jdoubleArray",
"jni_var": "Point3f %(n)s((float)%(n)s_x, (float)%(n)s_y, (float)%(n)s_z)",
"suffix": "DDD",
"j_import": "org.opencv.core.Point3"
},
"Point3i": {
"j_type": "Point3",
"jn_args": [
[
"double",
".x"
],
[
"double",
".y"
],
[
"double",
".z"
]
],
"jni_type": "jdoubleArray",
"jni_var": "Point3i %(n)s((int)%(n)s_x, (int)%(n)s_y, (int)%(n)s_z)",
"suffix": "DDD",
"j_import": "org.opencv.core.Point3"
},
"Range": {
"j_type": "Range",
"jn_args": [
[
"int",
".start"
],
[
"int",
".end"
]
],
"jni_type": "jdoubleArray",
"jni_var": "Range %(n)s(%(n)s_start, %(n)s_end)",
"suffix": "II",
"j_import": "org.opencv.core.Range"
},
"Rect": {
"j_type": "Rect",
"jn_args": [
[
"int",
".x"
],
[
"int",
".y"
],
[
"int",
".width"
],
[
"int",
".height"
]
],
"jni_type": "jdoubleArray",
"jni_var": "Rect %(n)s(%(n)s_x, %(n)s_y, %(n)s_width, %(n)s_height)",
"suffix": "IIII",
"j_import": "org.opencv.core.Rect"
},
"Rect2d": {
"j_type": "Rect2d",
"jn_args": [
[
"double",
".x"
],
[
"double",
".y"
],
[
"double",
".width"
],
[
"double",
".height"
]
],
"jni_type": "jdoubleArray",
"jni_var": "Rect %(n)s(%(n)s_x, %(n)s_y, %(n)s_width, %(n)s_height)",
"suffix": "DDDD",
"j_import": "org.opencv.core.Rect2d"
},
"RotatedRect": {
"j_type": "RotatedRect",
"jn_args": [
[
"double",
".center.x"
],
[
"double",
".center.y"
],
[
"double",
".size.width"
],
[
"double",
".size.height"
],
[
"double",
".angle"
]
],
"jni_type": "jdoubleArray",
"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)",
"suffix": "DDDDD",
"j_import": "org.opencv.core.RotatedRect"
},
"Scalar": {
"j_type": "Scalar",
"jn_args": [
[
"double",
".val[0]"
],
[
"double",
".val[1]"
],
[
"double",
".val[2]"
],
[
"double",
".val[3]"
]
],
"jni_type": "jdoubleArray",
"jni_var": "Scalar %(n)s(%(n)s_val0, %(n)s_val1, %(n)s_val2, %(n)s_val3)",
"suffix": "DDDD",
"j_import": "org.opencv.core.Scalar"
},
"Size": {
"j_type": "Size",
"jn_args": [
[
"double",
".width"
],
[
"double",
".height"
]
],
"jni_type": "jdoubleArray",
"jni_var": "Size %(n)s((int)%(n)s_width, (int)%(n)s_height)",
"suffix": "DD",
"j_import": "org.opencv.core.Size"
},
"Size2f": {
"j_type": "Size",
"jn_args": [
[
"double",
".width"
],
[
"double",
".height"
]
],
"jni_type": "jdoubleArray",
"jni_var": "Size2f %(n)s((float)%(n)s_width, (float)%(n)s_height)",
"suffix": "DD",
"j_import": "org.opencv.core.Size"
},
"String": {
"j_type": "String",
"jn_type": "String",
"jni_name": "n_%(n)s",
"jni_type": "jstring",
"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",
"j_import": "java.lang.String"
},
"TermCriteria": {
"j_type": "TermCriteria",
"jn_args": [
[
"int",
".type"
],
[
"int",
".maxCount"
],
[
"double",
".epsilon"
]
],
"jni_type": "jdoubleArray",
"jni_var": "TermCriteria %(n)s(%(n)s_type, %(n)s_maxCount, %(n)s_epsilon)",
"suffix": "IID",
"j_import": "org.opencv.core.TermCriteria"
},
"Vec2d": {
"j_type": "double[]",
"jn_args": [
[
"double",
".val[0]"
],
[
"double",
".val[1]"
]
],
"jn_type": "double[]",
"jni_type": "jdoubleArray",
"jni_var": "Vec2d %(n)s(%(n)s_val0, %(n)s_val1)",
"suffix": "DD"
},
"Vec3d": {
"j_type": "double[]",
"jn_args": [
[
"double",
".val[0]"
],
[
"double",
".val[1]"
],
[
"double",
".val[2]"
]
],
"jn_type": "double[]",
"jni_type": "jdoubleArray",
"jni_var": "Vec3d %(n)s(%(n)s_val0, %(n)s_val1, %(n)s_val2)",
"suffix": "DDD"
},
"c_string": {
"j_type": "String",
"jn_type": "String",
"jni_name": "n_%(n)s.c_str()",
"jni_type": "jstring",
"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",
"j_import": "java.lang.String"
},
"size_t": {
"j_type": "long",
"jn_type": "long",
"jni_type": "jlong",
"suffix": "J"
},
"vector_DMatch": {
"j_type": "MatOfDMatch",
"jn_type": "long",
"jni_type": "jlong",
"jni_var": "std::vector<DMatch> %(n)s",
"suffix": "J",
"v_type": "Mat",
"j_import": "org.opencv.core.MatOfDMatch"
},
"vector_KeyPoint": {
"j_type": "MatOfKeyPoint",
"jn_type": "long",
"jni_type": "jlong",
"jni_var": "std::vector<KeyPoint> %(n)s",
"suffix": "J",
"v_type": "Mat",
"j_import": "org.opencv.core.MatOfKeyPoint"
},
"vector_Mat": {
"j_type": "List<Mat>",
"jn_type": "long",
"jni_type": "jlong",
"jni_var": "std::vector<Mat> %(n)s",
"suffix": "J",
"v_type": "Mat",
"j_import": "org.opencv.core.Mat"
},
"vector_Point": {
"j_type": "MatOfPoint",
"jn_type": "long",
"jni_type": "jlong",
"jni_var": "std::vector<Point> %(n)s",
"suffix": "J",
"v_type": "Mat",
"j_import": "org.opencv.core.MatOfPoint"
},
"vector_Point2f": {
"j_type": "MatOfPoint2f",
"jn_type": "long",
"jni_type": "jlong",
"jni_var": "std::vector<Point2f> %(n)s",
"suffix": "J",
"v_type": "Mat",
"j_import": "org.opencv.core.MatOfPoint2f"
},
"vector_Point3f": {
"j_type": "MatOfPoint3f",
"jn_type": "long",
"jni_type": "jlong",
"jni_var": "std::vector<Point3f> %(n)s",
"suffix": "J",
"v_type": "Mat",
"j_import": "org.opencv.core.MatOfPoint3f"
},
"vector_Point2d": {
"j_type": "MatOfPoint2f",
"jn_type": "long",
"jni_type": "jlong",
"jni_var": "std::vector<Point2f> %(n)s",
"suffix": "J",
"v_type": "Mat",
"j_import": "org.opencv.core.MatOfPoint2f"
},
"vector_Point3d": {
"j_type": "MatOfPoint3f",
"jn_type": "long",
"jni_type": "jlong",
"jni_var": "std::vector<Point3f> %(n)s",
"suffix": "J",
"v_type": "Mat",
"j_import": "org.opencv.core.MatOfPoint3f"
},
"vector_Point3i": {
"j_type": "MatOfPoint3",
"jn_type": "long",
"jni_type": "jlong",
"jni_var": "std::vector<Point3i> %(n)s",
"suffix": "J",
"v_type": "Mat",
"j_import": "org.opencv.core.MatOfPoint3"
},
"vector_Rect": {
"j_type": "MatOfRect",
"jn_type": "long",
"jni_type": "jlong",
"jni_var": "std::vector<Rect> %(n)s",
"suffix": "J",
"v_type": "Mat",
"j_import": "org.opencv.core.MatOfRect"
},
"vector_Rect2d": {
"j_type": "MatOfRect2d",
"jn_type": "long",
"jni_type": "jlong",
"jni_var": "std::vector<Rect2d> %(n)s",
"suffix": "J",
"v_type": "Mat",
"j_import": "org.opencv.core.MatOfRect2d"
},
"vector_RotatedRect": {
"j_type": "MatOfRotatedRect",
"jn_type": "long",
"jni_type": "jlong",
"jni_var": "std::vector< RotatedRect > %(n)s",
"suffix": "J",
"v_type": "Mat",
"j_import": "org.opencv.core.MatOfRotatedRect"
},
"vector_String": {
"j_type": "List<String>",
"jn_type": "List<String>",
"jni_type": "jobject",
"jni_var": "std::vector< String > %(n)s",
"suffix": "Ljava_util_List",
"v_type": "String",
"j_import": "java.lang.String"
},
"vector_Vec4f": {
"j_type": "MatOfFloat4",
"jn_type": "long",
"jni_type": "jlong",
"jni_var": "std::vector<Vec4f> %(n)s",
"suffix": "J",
"v_type": "Mat",
"j_import": "org.opencv.core.MatOfFloat4"
},
"vector_Vec4i": {
"j_type": "MatOfInt4",
"jn_type": "long",
"jni_type": "jlong",
"jni_var": "std::vector<Vec4i> %(n)s",
"suffix": "J",
"v_type": "Mat",
"j_import": "org.opencv.core.MatOfInt4"
},
"vector_Vec6f": {
"j_type": "MatOfFloat6",
"jn_type": "long",
"jni_type": "jlong",
"jni_var": "std::vector<Vec6f> %(n)s",
"suffix": "J",
"v_type": "Mat",
"j_import": "org.opencv.core.MatOfFloat6"
},
"vector_char": {
"j_type": "MatOfByte",
"jn_type": "long",
"jni_type": "jlong",
"jni_var": "std::vector<char> %(n)s",
"suffix": "J",
"v_type": "Mat",
"j_import": "org.opencv.core.MatOfByte"
},
"vector_double": {
"j_type": "MatOfDouble",
"jn_type": "long",
"jni_type": "jlong",
"jni_var": "std::vector<double> %(n)s",
"suffix": "J",
"v_type": "Mat",
"j_import": "org.opencv.core.MatOfDouble"
},
"vector_float": {
"j_type": "MatOfFloat",
"jn_type": "long",
"jni_type": "jlong",
"jni_var": "std::vector<float> %(n)s",
"suffix": "J",
"v_type": "Mat",
"j_import": "org.opencv.core.MatOfFloat"
},
"vector_int": {
"j_type": "MatOfInt",
"jn_type": "long",
"jni_type": "jlong",
"jni_var": "std::vector<int> %(n)s",
"suffix": "J",
"v_type": "Mat",
"j_import": "org.opencv.core.MatOfInt"
},
"vector_uchar": {
"j_type": "MatOfByte",
"jn_type": "long",
"jni_type": "jlong",
"jni_var": "std::vector<uchar> %(n)s",
"suffix": "J",
"v_type": "Mat",
"j_import": "org.opencv.core.MatOfByte"
},
"vector_vector_DMatch": {
"j_type": "List<MatOfDMatch>",
"jn_type": "long",
"jni_type": "jlong",
"jni_var": "std::vector< std::vector<DMatch> > %(n)s",
"v_type": "vector_Mat",
"j_import": "org.opencv.core.MatOfDMatch"
},
"vector_vector_KeyPoint": {
"j_type": "List<MatOfKeyPoint>",
"jn_type": "long",
"jni_type": "jlong",
"jni_var": "std::vector< std::vector<KeyPoint> > %(n)s",
"v_type": "vector_Mat",
"j_import": "org.opencv.core.MatOfKeyPoint"
},
"vector_vector_Point": {
"j_type": "List<MatOfPoint>",
"jn_type": "long",
"jni_type": "jlong",
"jni_var": "std::vector< std::vector<Point> > %(n)s",
"v_type": "vector_Mat",
"j_import": "org.opencv.core.MatOfPoint"
},
"vector_vector_Point2f": {
"j_type": "List<MatOfPoint2f>",
"jn_type": "long",
"jni_type": "jlong",
"jni_var": "std::vector< std::vector<Point2f> > %(n)s",
"v_type": "vector_Mat",
"j_import": "org.opencv.core.MatOfPoint2f"
},
"vector_vector_Point3f": {
"j_type": "List<MatOfPoint3f>",
"jn_type": "long",
"jni_type": "jlong",
"jni_var": "std::vector< std::vector<Point3f> > %(n)s",
"v_type": "vector_Mat",
"j_import": "org.opencv.core.MatOfPoint3f"
},
"vector_vector_char": {
"j_type": "List<MatOfByte>",
"jn_type": "long",
"jni_type": "jlong",
"jni_var": "std::vector< std::vector<char> > %(n)s",
"v_type": "vector_Mat",
"j_import": "org.opencv.core.MatOfByte"
}
}
}

View File

@ -0,0 +1,21 @@
#define LOG_TAG "org.opencv.core.Core"
#include "common.h"
#include "core_manual.hpp"
#include "opencv2/core/utility.hpp"
static int quietCallback( int, const char*, const char*, const char*, int, void* )
{
return 0;
}
namespace cv {
void setErrorVerbosity(bool verbose)
{
if(verbose)
cv::redirectError(0);
else
cv::redirectError((cv::ErrorCallback)quietCallback);
}
}

View File

@ -0,0 +1,33 @@
#pragma once
#include "opencv2/core.hpp"
namespace cv
{
CV_EXPORTS_W void setErrorVerbosity(bool verbose);
}
#ifdef OPENCV_BINDINGS_PARSER
namespace cv
{
CV_EXPORTS_W void add(InputArray src1, Scalar src2, OutputArray dst, InputArray mask=noArray(), int dtype=-1);
CV_EXPORTS_W void subtract(InputArray src1, Scalar src2, OutputArray dst, InputArray mask=noArray(), int dtype=-1);
CV_EXPORTS_W void multiply(InputArray src1, Scalar src2, OutputArray dst, double scale=1, int dtype=-1);
CV_EXPORTS_W void divide(InputArray src1, Scalar src2, OutputArray dst, double scale=1, int dtype=-1);
CV_EXPORTS_W void absdiff(InputArray src1, Scalar src2, OutputArray dst);
CV_EXPORTS_W void compare(InputArray src1, Scalar src2, OutputArray dst, int cmpop);
CV_EXPORTS_W void min(InputArray src1, Scalar src2, OutputArray dst);
CV_EXPORTS_W void max(InputArray src1, Scalar src2, OutputArray dst);
}
#endif

View File

@ -0,0 +1,14 @@
// these constants are wrapped inside functions to prevent inlining
private static String getVersion() { return "@OPENCV_VERSION@"; }
private static String getNativeLibraryName() { return "opencv_java@OPENCV_VERSION_MAJOR@@OPENCV_VERSION_MINOR@@OPENCV_VERSION_PATCH@"; }
private static int getVersionMajorJ() { return @OPENCV_VERSION_MAJOR@; }
private static int getVersionMinorJ() { return @OPENCV_VERSION_MINOR@; }
private static int getVersionRevisionJ() { return @OPENCV_VERSION_PATCH@; }
private static String getVersionStatusJ() { return "@OPENCV_VERSION_STATUS@"; }
public static final String VERSION = getVersion();
public static final String NATIVE_LIBRARY_NAME = getNativeLibraryName();
public static final int VERSION_MAJOR = getVersionMajorJ();
public static final int VERSION_MINOR = getVersionMinorJ();
public static final int VERSION_REVISION = getVersionRevisionJ();
public static final String VERSION_STATUS = getVersionStatusJ();

View File

@ -0,0 +1,15 @@
package org.opencv.core;
public class CvException extends RuntimeException {
private static final long serialVersionUID = 1L;
public CvException(String msg) {
super(msg);
}
@Override
public String toString() {
return "CvException [" + super.toString() + "]";
}
}

View File

@ -0,0 +1,150 @@
package org.opencv.core;
public final class CvType {
// type depth constants
public static final int
CV_8U = 0,
CV_8S = 1,
CV_16U = 2,
CV_16S = 3,
CV_32S = 4,
CV_32F = 5,
CV_64F = 6,
CV_16F = 7;
/**
* @deprecated please use {@link #CV_16F}
*/
@Deprecated
public static final int CV_USRTYPE1 = CV_16F;
// predefined type constants
public static final int
CV_8UC1 = CV_8UC(1), CV_8UC2 = CV_8UC(2), CV_8UC3 = CV_8UC(3), CV_8UC4 = CV_8UC(4),
CV_8SC1 = CV_8SC(1), CV_8SC2 = CV_8SC(2), CV_8SC3 = CV_8SC(3), CV_8SC4 = CV_8SC(4),
CV_16UC1 = CV_16UC(1), CV_16UC2 = CV_16UC(2), CV_16UC3 = CV_16UC(3), CV_16UC4 = CV_16UC(4),
CV_16SC1 = CV_16SC(1), CV_16SC2 = CV_16SC(2), CV_16SC3 = CV_16SC(3), CV_16SC4 = CV_16SC(4),
CV_32SC1 = CV_32SC(1), CV_32SC2 = CV_32SC(2), CV_32SC3 = CV_32SC(3), CV_32SC4 = CV_32SC(4),
CV_32FC1 = CV_32FC(1), CV_32FC2 = CV_32FC(2), CV_32FC3 = CV_32FC(3), CV_32FC4 = CV_32FC(4),
CV_64FC1 = CV_64FC(1), CV_64FC2 = CV_64FC(2), CV_64FC3 = CV_64FC(3), CV_64FC4 = CV_64FC(4),
CV_16FC1 = CV_16FC(1), CV_16FC2 = CV_16FC(2), CV_16FC3 = CV_16FC(3), CV_16FC4 = CV_16FC(4);
private static final int CV_CN_MAX = 512, CV_CN_SHIFT = 3, CV_DEPTH_MAX = (1 << CV_CN_SHIFT);
public static final int makeType(int depth, int channels) {
if (channels <= 0 || channels >= CV_CN_MAX) {
throw new UnsupportedOperationException(
"Channels count should be 1.." + (CV_CN_MAX - 1));
}
if (depth < 0 || depth >= CV_DEPTH_MAX) {
throw new UnsupportedOperationException(
"Data type depth should be 0.." + (CV_DEPTH_MAX - 1));
}
return (depth & (CV_DEPTH_MAX - 1)) + ((channels - 1) << CV_CN_SHIFT);
}
public static final int CV_8UC(int ch) {
return makeType(CV_8U, ch);
}
public static final int CV_8SC(int ch) {
return makeType(CV_8S, ch);
}
public static final int CV_16UC(int ch) {
return makeType(CV_16U, ch);
}
public static final int CV_16SC(int ch) {
return makeType(CV_16S, ch);
}
public static final int CV_32SC(int ch) {
return makeType(CV_32S, ch);
}
public static final int CV_32FC(int ch) {
return makeType(CV_32F, ch);
}
public static final int CV_64FC(int ch) {
return makeType(CV_64F, ch);
}
public static final int CV_16FC(int ch) {
return makeType(CV_16F, ch);
}
public static final int channels(int type) {
return (type >> CV_CN_SHIFT) + 1;
}
public static final int depth(int type) {
return type & (CV_DEPTH_MAX - 1);
}
public static final boolean isInteger(int type) {
return depth(type) < CV_32F;
}
public static final int ELEM_SIZE(int type) {
switch (depth(type)) {
case CV_8U:
case CV_8S:
return channels(type);
case CV_16U:
case CV_16S:
case CV_16F:
return 2 * channels(type);
case CV_32S:
case CV_32F:
return 4 * channels(type);
case CV_64F:
return 8 * channels(type);
default:
throw new UnsupportedOperationException(
"Unsupported CvType value: " + type);
}
}
public static final String typeToString(int type) {
String s;
switch (depth(type)) {
case CV_8U:
s = "CV_8U";
break;
case CV_8S:
s = "CV_8S";
break;
case CV_16U:
s = "CV_16U";
break;
case CV_16S:
s = "CV_16S";
break;
case CV_32S:
s = "CV_32S";
break;
case CV_32F:
s = "CV_32F";
break;
case CV_64F:
s = "CV_64F";
break;
case CV_16F:
s = "CV_16F";
break;
default:
throw new UnsupportedOperationException(
"Unsupported CvType value: " + type);
}
int ch = channels(type);
if (ch <= 4)
return s + "C" + ch;
else
return s + "C(" + ch + ")";
}
}

View File

@ -0,0 +1,58 @@
package org.opencv.core;
//C++: class DMatch
/**
* Structure for matching: query descriptor index, train descriptor index, train
* image index and distance between descriptors.
*/
public class DMatch {
/**
* Query descriptor index.
*/
public int queryIdx;
/**
* Train descriptor index.
*/
public int trainIdx;
/**
* Train image index.
*/
public int imgIdx;
// javadoc: DMatch::distance
public float distance;
// javadoc: DMatch::DMatch()
public DMatch() {
this(-1, -1, Float.MAX_VALUE);
}
// javadoc: DMatch::DMatch(_queryIdx, _trainIdx, _distance)
public DMatch(int _queryIdx, int _trainIdx, float _distance) {
queryIdx = _queryIdx;
trainIdx = _trainIdx;
imgIdx = -1;
distance = _distance;
}
// javadoc: DMatch::DMatch(_queryIdx, _trainIdx, _imgIdx, _distance)
public DMatch(int _queryIdx, int _trainIdx, int _imgIdx, float _distance) {
queryIdx = _queryIdx;
trainIdx = _trainIdx;
imgIdx = _imgIdx;
distance = _distance;
}
public boolean lessThan(DMatch it) {
return distance < it.distance;
}
@Override
public String toString() {
return "DMatch [queryIdx=" + queryIdx + ", trainIdx=" + trainIdx
+ ", imgIdx=" + imgIdx + ", distance=" + distance + "]";
}
}

View File

@ -0,0 +1,77 @@
package org.opencv.core;
import org.opencv.core.Point;
//javadoc: KeyPoint
public class KeyPoint {
/**
* Coordinates of the keypoint.
*/
public Point pt;
/**
* Diameter of the useful keypoint adjacent area.
*/
public float size;
/**
* Computed orientation of the keypoint (-1 if not applicable).
*/
public float angle;
/**
* The response, by which the strongest keypoints have been selected. Can
* be used for further sorting or subsampling.
*/
public float response;
/**
* Octave (pyramid layer), from which the keypoint has been extracted.
*/
public int octave;
/**
* Object ID, that can be used to cluster keypoints by an object they
* belong to.
*/
public int class_id;
// javadoc:KeyPoint::KeyPoint(x,y,_size,_angle,_response,_octave,_class_id)
public KeyPoint(float x, float y, float _size, float _angle, float _response, int _octave, int _class_id) {
pt = new Point(x, y);
size = _size;
angle = _angle;
response = _response;
octave = _octave;
class_id = _class_id;
}
// javadoc: KeyPoint::KeyPoint()
public KeyPoint() {
this(0, 0, 0, -1, 0, 0, -1);
}
// javadoc: KeyPoint::KeyPoint(x, y, _size, _angle, _response, _octave)
public KeyPoint(float x, float y, float _size, float _angle, float _response, int _octave) {
this(x, y, _size, _angle, _response, _octave, -1);
}
// javadoc: KeyPoint::KeyPoint(x, y, _size, _angle, _response)
public KeyPoint(float x, float y, float _size, float _angle, float _response) {
this(x, y, _size, _angle, _response, 0, -1);
}
// javadoc: KeyPoint::KeyPoint(x, y, _size, _angle)
public KeyPoint(float x, float y, float _size, float _angle) {
this(x, y, _size, _angle, 0, 0, -1);
}
// javadoc: KeyPoint::KeyPoint(x, y, _size)
public KeyPoint(float x, float y, float _size) {
this(x, y, _size, -1, 0, 0, -1);
}
@Override
public String toString() {
return "KeyPoint [pt=" + pt + ", size=" + size + ", angle=" + angle
+ ", response=" + response + ", octave=" + octave
+ ", class_id=" + class_id + "]";
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,160 @@
package org.opencv.core
import org.opencv.core.Mat.*
import java.lang.RuntimeException
fun Mat.get(row: Int, col: Int, data: UByteArray) = this.get(row, col, data.asByteArray())
fun Mat.get(indices: IntArray, data: UByteArray) = this.get(indices, data.asByteArray())
fun Mat.put(row: Int, col: Int, data: UByteArray) = this.put(row, col, data.asByteArray())
fun Mat.put(indices: IntArray, data: UByteArray) = this.put(indices, data.asByteArray())
fun Mat.get(row: Int, col: Int, data: UShortArray) = this.get(row, col, data.asShortArray())
fun Mat.get(indices: IntArray, data: UShortArray) = this.get(indices, data.asShortArray())
fun Mat.put(row: Int, col: Int, data: UShortArray) = this.put(row, col, data.asShortArray())
fun Mat.put(indices: IntArray, data: UShortArray) = this.put(indices, data.asShortArray())
/***
* Example use:
*
* val (b, g, r) = mat.at<UByte>(50, 50).v3c
* mat.at<UByte>(50, 50).val = T3(245u, 113u, 34u)
*
*/
@Suppress("UNCHECKED_CAST")
inline fun <reified T> Mat.at(row: Int, col: Int) : Atable<T> =
when (T::class) {
Byte::class, Double::class, Float::class, Int::class, Short::class -> this.at(
T::class.java,
row,
col
)
UByte::class -> AtableUByte(this, row, col) as Atable<T>
UShort::class -> AtableUShort(this, row, col) as Atable<T>
else -> throw RuntimeException("Unsupported class type")
}
@Suppress("UNCHECKED_CAST")
inline fun <reified T> Mat.at(idx: IntArray) : Atable<T> =
when (T::class) {
Byte::class, Double::class, Float::class, Int::class, Short::class -> this.at(
T::class.java,
idx
)
UByte::class -> AtableUByte(this, idx) as Atable<T>
UShort::class -> AtableUShort(this, idx) as Atable<T>
else -> throw RuntimeException("Unsupported class type")
}
class AtableUByte(val mat: Mat, val indices: IntArray): Atable<UByte> {
constructor(mat: Mat, row: Int, col: Int) : this(mat, intArrayOf(row, col))
override fun getV(): UByte {
val data = UByteArray(1)
mat.get(indices, data)
return data[0]
}
override fun setV(v: UByte) {
val data = ubyteArrayOf(v)
mat.put(indices, data)
}
override fun getV2c(): Tuple2<UByte> {
val data = UByteArray(2)
mat.get(indices, data)
return Tuple2(data[0], data[1])
}
override fun setV2c(v: Tuple2<UByte>) {
val data = ubyteArrayOf(v._0, v._1)
mat.put(indices, data)
}
override fun getV3c(): Tuple3<UByte> {
val data = UByteArray(3)
mat.get(indices, data)
return Tuple3(data[0], data[1], data[2])
}
override fun setV3c(v: Tuple3<UByte>) {
val data = ubyteArrayOf(v._0, v._1, v._2)
mat.put(indices, data)
}
override fun getV4c(): Tuple4<UByte> {
val data = UByteArray(4)
mat.get(indices, data)
return Tuple4(data[0], data[1], data[2], data[3])
}
override fun setV4c(v: Tuple4<UByte>) {
val data = ubyteArrayOf(v._0, v._1, v._2, v._3)
mat.put(indices, data)
}
}
class AtableUShort(val mat: Mat, val indices: IntArray): Atable<UShort> {
constructor(mat: Mat, row: Int, col: Int) : this(mat, intArrayOf(row, col))
override fun getV(): UShort {
val data = UShortArray(1)
mat.get(indices, data)
return data[0]
}
override fun setV(v: UShort) {
val data = ushortArrayOf(v)
mat.put(indices, data)
}
override fun getV2c(): Tuple2<UShort> {
val data = UShortArray(2)
mat.get(indices, data)
return Tuple2(data[0], data[1])
}
override fun setV2c(v: Tuple2<UShort>) {
val data = ushortArrayOf(v._0, v._1)
mat.put(indices, data)
}
override fun getV3c(): Tuple3<UShort> {
val data = UShortArray(3)
mat.get(indices, data)
return Tuple3(data[0], data[1], data[2])
}
override fun setV3c(v: Tuple3<UShort>) {
val data = ushortArrayOf(v._0, v._1, v._2)
mat.put(indices, data)
}
override fun getV4c(): Tuple4<UShort> {
val data = UShortArray(4)
mat.get(indices, data)
return Tuple4(data[0], data[1], data[2], data[3])
}
override fun setV4c(v: Tuple4<UShort>) {
val data = ushortArrayOf(v._0, v._1, v._2, v._3)
mat.put(indices, data)
}
}
operator fun <T> Tuple2<T>.component1(): T = this._0
operator fun <T> Tuple2<T>.component2(): T = this._1
operator fun <T> Tuple3<T>.component1(): T = this._0
operator fun <T> Tuple3<T>.component2(): T = this._1
operator fun <T> Tuple3<T>.component3(): T = this._2
operator fun <T> Tuple4<T>.component1(): T = this._0
operator fun <T> Tuple4<T>.component2(): T = this._1
operator fun <T> Tuple4<T>.component3(): T = this._2
operator fun <T> Tuple4<T>.component4(): T = this._3
fun <T> T2(_0: T, _1: T) : Tuple2<T> = Tuple2(_0, _1)
fun <T> T3(_0: T, _1: T, _2: T) : Tuple3<T> = Tuple3(_0, _1, _2)
fun <T> T4(_0: T, _1: T, _2: T, _3: T) : Tuple4<T> = Tuple4(_0, _1, _2, _3)

View File

@ -0,0 +1,3 @@
package org.opencv.core
operator fun Mat.times(other: Mat): Mat = this.matMul(other)

View File

@ -0,0 +1,98 @@
package org.opencv.core;
import java.util.Arrays;
import java.util.List;
public class MatOfByte extends Mat {
// 8UC(x)
private static final int _depth = CvType.CV_8U;
private static final int _channels = 1;
public MatOfByte() {
super();
}
protected MatOfByte(long addr) {
super(addr);
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public static MatOfByte fromNativeAddr(long addr) {
return new MatOfByte(addr);
}
public MatOfByte(Mat m) {
super(m, Range.all());
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public MatOfByte(byte...a) {
super();
fromArray(a);
}
public MatOfByte(int offset, int length, byte...a) {
super();
fromArray(offset, length, a);
}
public void alloc(int elemNumber) {
if(elemNumber>0)
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
}
public void fromArray(byte...a) {
if(a==null || a.length==0)
return;
int num = a.length / _channels;
alloc(num);
put(0, 0, a); //TODO: check ret val!
}
public void fromArray(int offset, int length, byte...a) {
if (offset < 0)
throw new IllegalArgumentException("offset < 0");
if (a == null)
throw new NullPointerException();
if (length < 0 || length + offset > a.length)
throw new IllegalArgumentException("invalid 'length' parameter: " + Integer.toString(length));
if (a.length == 0)
return;
int num = length / _channels;
alloc(num);
put(0, 0, a, offset, length); //TODO: check ret val!
}
public byte[] toArray() {
int num = checkVector(_channels, _depth);
if(num < 0)
throw new RuntimeException("Native Mat has unexpected type or size: " + toString());
byte[] a = new byte[num * _channels];
if(num == 0)
return a;
get(0, 0, a); //TODO: check ret val!
return a;
}
public void fromList(List<Byte> lb) {
if(lb==null || lb.size()==0)
return;
Byte ab[] = lb.toArray(new Byte[0]);
byte a[] = new byte[ab.length];
for(int i=0; i<ab.length; i++)
a[i] = ab[i];
fromArray(a);
}
public List<Byte> toList() {
byte[] a = toArray();
Byte ab[] = new Byte[a.length];
for(int i=0; i<a.length; i++)
ab[i] = a[i];
return Arrays.asList(ab);
}
}

View File

@ -0,0 +1,83 @@
package org.opencv.core;
import java.util.Arrays;
import java.util.List;
import org.opencv.core.DMatch;
public class MatOfDMatch extends Mat {
// 32FC4
private static final int _depth = CvType.CV_32F;
private static final int _channels = 4;
public MatOfDMatch() {
super();
}
protected MatOfDMatch(long addr) {
super(addr);
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat: " + toString());
//FIXME: do we need release() here?
}
public static MatOfDMatch fromNativeAddr(long addr) {
return new MatOfDMatch(addr);
}
public MatOfDMatch(Mat m) {
super(m, Range.all());
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat: " + toString());
//FIXME: do we need release() here?
}
public MatOfDMatch(DMatch...ap) {
super();
fromArray(ap);
}
public void alloc(int elemNumber) {
if(elemNumber>0)
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
}
public void fromArray(DMatch...a) {
if(a==null || a.length==0)
return;
int num = a.length;
alloc(num);
float buff[] = new float[num * _channels];
for(int i=0; i<num; i++) {
DMatch m = a[i];
buff[_channels*i+0] = m.queryIdx;
buff[_channels*i+1] = m.trainIdx;
buff[_channels*i+2] = m.imgIdx;
buff[_channels*i+3] = m.distance;
}
put(0, 0, buff); //TODO: check ret val!
}
public DMatch[] toArray() {
int num = (int) total();
DMatch[] a = new DMatch[num];
if(num == 0)
return a;
float buff[] = new float[num * _channels];
get(0, 0, buff); //TODO: check ret val!
for(int i=0; i<num; i++)
a[i] = new DMatch((int) buff[_channels*i+0], (int) buff[_channels*i+1], (int) buff[_channels*i+2], buff[_channels*i+3]);
return a;
}
public void fromList(List<DMatch> ldm) {
DMatch adm[] = ldm.toArray(new DMatch[0]);
fromArray(adm);
}
public List<DMatch> toList() {
DMatch[] adm = toArray();
return Arrays.asList(adm);
}
}

View File

@ -0,0 +1,79 @@
package org.opencv.core;
import java.util.Arrays;
import java.util.List;
public class MatOfDouble extends Mat {
// 64FC(x)
private static final int _depth = CvType.CV_64F;
private static final int _channels = 1;
public MatOfDouble() {
super();
}
protected MatOfDouble(long addr) {
super(addr);
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public static MatOfDouble fromNativeAddr(long addr) {
return new MatOfDouble(addr);
}
public MatOfDouble(Mat m) {
super(m, Range.all());
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public MatOfDouble(double...a) {
super();
fromArray(a);
}
public void alloc(int elemNumber) {
if(elemNumber>0)
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
}
public void fromArray(double...a) {
if(a==null || a.length==0)
return;
int num = a.length / _channels;
alloc(num);
put(0, 0, a); //TODO: check ret val!
}
public double[] toArray() {
int num = checkVector(_channels, _depth);
if(num < 0)
throw new RuntimeException("Native Mat has unexpected type or size: " + toString());
double[] a = new double[num * _channels];
if(num == 0)
return a;
get(0, 0, a); //TODO: check ret val!
return a;
}
public void fromList(List<Double> lb) {
if(lb==null || lb.size()==0)
return;
Double ab[] = lb.toArray(new Double[0]);
double a[] = new double[ab.length];
for(int i=0; i<ab.length; i++)
a[i] = ab[i];
fromArray(a);
}
public List<Double> toList() {
double[] a = toArray();
Double ab[] = new Double[a.length];
for(int i=0; i<a.length; i++)
ab[i] = a[i];
return Arrays.asList(ab);
}
}

View File

@ -0,0 +1,79 @@
package org.opencv.core;
import java.util.Arrays;
import java.util.List;
public class MatOfFloat extends Mat {
// 32FC1
private static final int _depth = CvType.CV_32F;
private static final int _channels = 1;
public MatOfFloat() {
super();
}
protected MatOfFloat(long addr) {
super(addr);
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public static MatOfFloat fromNativeAddr(long addr) {
return new MatOfFloat(addr);
}
public MatOfFloat(Mat m) {
super(m, Range.all());
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public MatOfFloat(float...a) {
super();
fromArray(a);
}
public void alloc(int elemNumber) {
if(elemNumber>0)
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
}
public void fromArray(float...a) {
if(a==null || a.length==0)
return;
int num = a.length / _channels;
alloc(num);
put(0, 0, a); //TODO: check ret val!
}
public float[] toArray() {
int num = checkVector(_channels, _depth);
if(num < 0)
throw new RuntimeException("Native Mat has unexpected type or size: " + toString());
float[] a = new float[num * _channels];
if(num == 0)
return a;
get(0, 0, a); //TODO: check ret val!
return a;
}
public void fromList(List<Float> lb) {
if(lb==null || lb.size()==0)
return;
Float ab[] = lb.toArray(new Float[0]);
float a[] = new float[ab.length];
for(int i=0; i<ab.length; i++)
a[i] = ab[i];
fromArray(a);
}
public List<Float> toList() {
float[] a = toArray();
Float ab[] = new Float[a.length];
for(int i=0; i<a.length; i++)
ab[i] = a[i];
return Arrays.asList(ab);
}
}

View File

@ -0,0 +1,79 @@
package org.opencv.core;
import java.util.Arrays;
import java.util.List;
public class MatOfFloat4 extends Mat {
// 32FC4
private static final int _depth = CvType.CV_32F;
private static final int _channels = 4;
public MatOfFloat4() {
super();
}
protected MatOfFloat4(long addr) {
super(addr);
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public static MatOfFloat4 fromNativeAddr(long addr) {
return new MatOfFloat4(addr);
}
public MatOfFloat4(Mat m) {
super(m, Range.all());
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public MatOfFloat4(float...a) {
super();
fromArray(a);
}
public void alloc(int elemNumber) {
if(elemNumber>0)
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
}
public void fromArray(float...a) {
if(a==null || a.length==0)
return;
int num = a.length / _channels;
alloc(num);
put(0, 0, a); //TODO: check ret val!
}
public float[] toArray() {
int num = checkVector(_channels, _depth);
if(num < 0)
throw new RuntimeException("Native Mat has unexpected type or size: " + toString());
float[] a = new float[num * _channels];
if(num == 0)
return a;
get(0, 0, a); //TODO: check ret val!
return a;
}
public void fromList(List<Float> lb) {
if(lb==null || lb.size()==0)
return;
Float ab[] = lb.toArray(new Float[0]);
float a[] = new float[ab.length];
for(int i=0; i<ab.length; i++)
a[i] = ab[i];
fromArray(a);
}
public List<Float> toList() {
float[] a = toArray();
Float ab[] = new Float[a.length];
for(int i=0; i<a.length; i++)
ab[i] = a[i];
return Arrays.asList(ab);
}
}

View File

@ -0,0 +1,79 @@
package org.opencv.core;
import java.util.Arrays;
import java.util.List;
public class MatOfFloat6 extends Mat {
// 32FC6
private static final int _depth = CvType.CV_32F;
private static final int _channels = 6;
public MatOfFloat6() {
super();
}
protected MatOfFloat6(long addr) {
super(addr);
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public static MatOfFloat6 fromNativeAddr(long addr) {
return new MatOfFloat6(addr);
}
public MatOfFloat6(Mat m) {
super(m, Range.all());
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public MatOfFloat6(float...a) {
super();
fromArray(a);
}
public void alloc(int elemNumber) {
if(elemNumber>0)
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
}
public void fromArray(float...a) {
if(a==null || a.length==0)
return;
int num = a.length / _channels;
alloc(num);
put(0, 0, a); //TODO: check ret val!
}
public float[] toArray() {
int num = checkVector(_channels, _depth);
if(num < 0)
throw new RuntimeException("Native Mat has unexpected type or size: " + toString());
float[] a = new float[num * _channels];
if(num == 0)
return a;
get(0, 0, a); //TODO: check ret val!
return a;
}
public void fromList(List<Float> lb) {
if(lb==null || lb.size()==0)
return;
Float ab[] = lb.toArray(new Float[0]);
float a[] = new float[ab.length];
for(int i=0; i<ab.length; i++)
a[i] = ab[i];
fromArray(a);
}
public List<Float> toList() {
float[] a = toArray();
Float ab[] = new Float[a.length];
for(int i=0; i<a.length; i++)
ab[i] = a[i];
return Arrays.asList(ab);
}
}

View File

@ -0,0 +1,80 @@
package org.opencv.core;
import java.util.Arrays;
import java.util.List;
public class MatOfInt extends Mat {
// 32SC1
private static final int _depth = CvType.CV_32S;
private static final int _channels = 1;
public MatOfInt() {
super();
}
protected MatOfInt(long addr) {
super(addr);
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public static MatOfInt fromNativeAddr(long addr) {
return new MatOfInt(addr);
}
public MatOfInt(Mat m) {
super(m, Range.all());
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public MatOfInt(int...a) {
super();
fromArray(a);
}
public void alloc(int elemNumber) {
if(elemNumber>0)
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
}
public void fromArray(int...a) {
if(a==null || a.length==0)
return;
int num = a.length / _channels;
alloc(num);
put(0, 0, a); //TODO: check ret val!
}
public int[] toArray() {
int num = checkVector(_channels, _depth);
if(num < 0)
throw new RuntimeException("Native Mat has unexpected type or size: " + toString());
int[] a = new int[num * _channels];
if(num == 0)
return a;
get(0, 0, a); //TODO: check ret val!
return a;
}
public void fromList(List<Integer> lb) {
if(lb==null || lb.size()==0)
return;
Integer ab[] = lb.toArray(new Integer[0]);
int a[] = new int[ab.length];
for(int i=0; i<ab.length; i++)
a[i] = ab[i];
fromArray(a);
}
public List<Integer> toList() {
int[] a = toArray();
Integer ab[] = new Integer[a.length];
for(int i=0; i<a.length; i++)
ab[i] = a[i];
return Arrays.asList(ab);
}
}

View File

@ -0,0 +1,80 @@
package org.opencv.core;
import java.util.Arrays;
import java.util.List;
public class MatOfInt4 extends Mat {
// 32SC4
private static final int _depth = CvType.CV_32S;
private static final int _channels = 4;
public MatOfInt4() {
super();
}
protected MatOfInt4(long addr) {
super(addr);
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public static MatOfInt4 fromNativeAddr(long addr) {
return new MatOfInt4(addr);
}
public MatOfInt4(Mat m) {
super(m, Range.all());
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public MatOfInt4(int...a) {
super();
fromArray(a);
}
public void alloc(int elemNumber) {
if(elemNumber>0)
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
}
public void fromArray(int...a) {
if(a==null || a.length==0)
return;
int num = a.length / _channels;
alloc(num);
put(0, 0, a); //TODO: check ret val!
}
public int[] toArray() {
int num = checkVector(_channels, _depth);
if(num < 0)
throw new RuntimeException("Native Mat has unexpected type or size: " + toString());
int[] a = new int[num * _channels];
if(num == 0)
return a;
get(0, 0, a); //TODO: check ret val!
return a;
}
public void fromList(List<Integer> lb) {
if(lb==null || lb.size()==0)
return;
Integer ab[] = lb.toArray(new Integer[0]);
int a[] = new int[ab.length];
for(int i=0; i<ab.length; i++)
a[i] = ab[i];
fromArray(a);
}
public List<Integer> toList() {
int[] a = toArray();
Integer ab[] = new Integer[a.length];
for(int i=0; i<a.length; i++)
ab[i] = a[i];
return Arrays.asList(ab);
}
}

View File

@ -0,0 +1,86 @@
package org.opencv.core;
import java.util.Arrays;
import java.util.List;
import org.opencv.core.KeyPoint;
public class MatOfKeyPoint extends Mat {
// 32FC7
private static final int _depth = CvType.CV_32F;
private static final int _channels = 7;
public MatOfKeyPoint() {
super();
}
protected MatOfKeyPoint(long addr) {
super(addr);
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public static MatOfKeyPoint fromNativeAddr(long addr) {
return new MatOfKeyPoint(addr);
}
public MatOfKeyPoint(Mat m) {
super(m, Range.all());
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public MatOfKeyPoint(KeyPoint...a) {
super();
fromArray(a);
}
public void alloc(int elemNumber) {
if(elemNumber>0)
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
}
public void fromArray(KeyPoint...a) {
if(a==null || a.length==0)
return;
int num = a.length;
alloc(num);
float buff[] = new float[num * _channels];
for(int i=0; i<num; i++) {
KeyPoint kp = a[i];
buff[_channels*i+0] = (float) kp.pt.x;
buff[_channels*i+1] = (float) kp.pt.y;
buff[_channels*i+2] = kp.size;
buff[_channels*i+3] = kp.angle;
buff[_channels*i+4] = kp.response;
buff[_channels*i+5] = kp.octave;
buff[_channels*i+6] = kp.class_id;
}
put(0, 0, buff); //TODO: check ret val!
}
public KeyPoint[] toArray() {
int num = (int) total();
KeyPoint[] a = new KeyPoint[num];
if(num == 0)
return a;
float buff[] = new float[num * _channels];
get(0, 0, buff); //TODO: check ret val!
for(int i=0; i<num; i++)
a[i] = new KeyPoint( buff[_channels*i+0], buff[_channels*i+1], buff[_channels*i+2], buff[_channels*i+3],
buff[_channels*i+4], (int) buff[_channels*i+5], (int) buff[_channels*i+6] );
return a;
}
public void fromList(List<KeyPoint> lkp) {
KeyPoint akp[] = lkp.toArray(new KeyPoint[0]);
fromArray(akp);
}
public List<KeyPoint> toList() {
KeyPoint[] akp = toArray();
return Arrays.asList(akp);
}
}

View File

@ -0,0 +1,78 @@
package org.opencv.core;
import java.util.Arrays;
import java.util.List;
public class MatOfPoint extends Mat {
// 32SC2
private static final int _depth = CvType.CV_32S;
private static final int _channels = 2;
public MatOfPoint() {
super();
}
protected MatOfPoint(long addr) {
super(addr);
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public static MatOfPoint fromNativeAddr(long addr) {
return new MatOfPoint(addr);
}
public MatOfPoint(Mat m) {
super(m, Range.all());
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public MatOfPoint(Point...a) {
super();
fromArray(a);
}
public void alloc(int elemNumber) {
if(elemNumber>0)
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
}
public void fromArray(Point...a) {
if(a==null || a.length==0)
return;
int num = a.length;
alloc(num);
int buff[] = new int[num * _channels];
for(int i=0; i<num; i++) {
Point p = a[i];
buff[_channels*i+0] = (int) p.x;
buff[_channels*i+1] = (int) p.y;
}
put(0, 0, buff); //TODO: check ret val!
}
public Point[] toArray() {
int num = (int) total();
Point[] ap = new Point[num];
if(num == 0)
return ap;
int buff[] = new int[num * _channels];
get(0, 0, buff); //TODO: check ret val!
for(int i=0; i<num; i++)
ap[i] = new Point(buff[i*_channels], buff[i*_channels+1]);
return ap;
}
public void fromList(List<Point> lp) {
Point ap[] = lp.toArray(new Point[0]);
fromArray(ap);
}
public List<Point> toList() {
Point[] ap = toArray();
return Arrays.asList(ap);
}
}

View File

@ -0,0 +1,78 @@
package org.opencv.core;
import java.util.Arrays;
import java.util.List;
public class MatOfPoint2f extends Mat {
// 32FC2
private static final int _depth = CvType.CV_32F;
private static final int _channels = 2;
public MatOfPoint2f() {
super();
}
protected MatOfPoint2f(long addr) {
super(addr);
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public static MatOfPoint2f fromNativeAddr(long addr) {
return new MatOfPoint2f(addr);
}
public MatOfPoint2f(Mat m) {
super(m, Range.all());
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public MatOfPoint2f(Point...a) {
super();
fromArray(a);
}
public void alloc(int elemNumber) {
if(elemNumber>0)
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
}
public void fromArray(Point...a) {
if(a==null || a.length==0)
return;
int num = a.length;
alloc(num);
float buff[] = new float[num * _channels];
for(int i=0; i<num; i++) {
Point p = a[i];
buff[_channels*i+0] = (float) p.x;
buff[_channels*i+1] = (float) p.y;
}
put(0, 0, buff); //TODO: check ret val!
}
public Point[] toArray() {
int num = (int) total();
Point[] ap = new Point[num];
if(num == 0)
return ap;
float buff[] = new float[num * _channels];
get(0, 0, buff); //TODO: check ret val!
for(int i=0; i<num; i++)
ap[i] = new Point(buff[i*_channels], buff[i*_channels+1]);
return ap;
}
public void fromList(List<Point> lp) {
Point ap[] = lp.toArray(new Point[0]);
fromArray(ap);
}
public List<Point> toList() {
Point[] ap = toArray();
return Arrays.asList(ap);
}
}

View File

@ -0,0 +1,79 @@
package org.opencv.core;
import java.util.Arrays;
import java.util.List;
public class MatOfPoint3 extends Mat {
// 32SC3
private static final int _depth = CvType.CV_32S;
private static final int _channels = 3;
public MatOfPoint3() {
super();
}
protected MatOfPoint3(long addr) {
super(addr);
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public static MatOfPoint3 fromNativeAddr(long addr) {
return new MatOfPoint3(addr);
}
public MatOfPoint3(Mat m) {
super(m, Range.all());
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public MatOfPoint3(Point3...a) {
super();
fromArray(a);
}
public void alloc(int elemNumber) {
if(elemNumber>0)
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
}
public void fromArray(Point3...a) {
if(a==null || a.length==0)
return;
int num = a.length;
alloc(num);
int buff[] = new int[num * _channels];
for(int i=0; i<num; i++) {
Point3 p = a[i];
buff[_channels*i+0] = (int) p.x;
buff[_channels*i+1] = (int) p.y;
buff[_channels*i+2] = (int) p.z;
}
put(0, 0, buff); //TODO: check ret val!
}
public Point3[] toArray() {
int num = (int) total();
Point3[] ap = new Point3[num];
if(num == 0)
return ap;
int buff[] = new int[num * _channels];
get(0, 0, buff); //TODO: check ret val!
for(int i=0; i<num; i++)
ap[i] = new Point3(buff[i*_channels], buff[i*_channels+1], buff[i*_channels+2]);
return ap;
}
public void fromList(List<Point3> lp) {
Point3 ap[] = lp.toArray(new Point3[0]);
fromArray(ap);
}
public List<Point3> toList() {
Point3[] ap = toArray();
return Arrays.asList(ap);
}
}

View File

@ -0,0 +1,79 @@
package org.opencv.core;
import java.util.Arrays;
import java.util.List;
public class MatOfPoint3f extends Mat {
// 32FC3
private static final int _depth = CvType.CV_32F;
private static final int _channels = 3;
public MatOfPoint3f() {
super();
}
protected MatOfPoint3f(long addr) {
super(addr);
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public static MatOfPoint3f fromNativeAddr(long addr) {
return new MatOfPoint3f(addr);
}
public MatOfPoint3f(Mat m) {
super(m, Range.all());
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public MatOfPoint3f(Point3...a) {
super();
fromArray(a);
}
public void alloc(int elemNumber) {
if(elemNumber>0)
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
}
public void fromArray(Point3...a) {
if(a==null || a.length==0)
return;
int num = a.length;
alloc(num);
float buff[] = new float[num * _channels];
for(int i=0; i<num; i++) {
Point3 p = a[i];
buff[_channels*i+0] = (float) p.x;
buff[_channels*i+1] = (float) p.y;
buff[_channels*i+2] = (float) p.z;
}
put(0, 0, buff); //TODO: check ret val!
}
public Point3[] toArray() {
int num = (int) total();
Point3[] ap = new Point3[num];
if(num == 0)
return ap;
float buff[] = new float[num * _channels];
get(0, 0, buff); //TODO: check ret val!
for(int i=0; i<num; i++)
ap[i] = new Point3(buff[i*_channels], buff[i*_channels+1], buff[i*_channels+2]);
return ap;
}
public void fromList(List<Point3> lp) {
Point3 ap[] = lp.toArray(new Point3[0]);
fromArray(ap);
}
public List<Point3> toList() {
Point3[] ap = toArray();
return Arrays.asList(ap);
}
}

View File

@ -0,0 +1,81 @@
package org.opencv.core;
import java.util.Arrays;
import java.util.List;
public class MatOfRect extends Mat {
// 32SC4
private static final int _depth = CvType.CV_32S;
private static final int _channels = 4;
public MatOfRect() {
super();
}
protected MatOfRect(long addr) {
super(addr);
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public static MatOfRect fromNativeAddr(long addr) {
return new MatOfRect(addr);
}
public MatOfRect(Mat m) {
super(m, Range.all());
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public MatOfRect(Rect...a) {
super();
fromArray(a);
}
public void alloc(int elemNumber) {
if(elemNumber>0)
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
}
public void fromArray(Rect...a) {
if(a==null || a.length==0)
return;
int num = a.length;
alloc(num);
int buff[] = new int[num * _channels];
for(int i=0; i<num; i++) {
Rect r = a[i];
buff[_channels*i+0] = (int) r.x;
buff[_channels*i+1] = (int) r.y;
buff[_channels*i+2] = (int) r.width;
buff[_channels*i+3] = (int) r.height;
}
put(0, 0, buff); //TODO: check ret val!
}
public Rect[] toArray() {
int num = (int) total();
Rect[] a = new Rect[num];
if(num == 0)
return a;
int buff[] = new int[num * _channels];
get(0, 0, buff); //TODO: check ret val!
for(int i=0; i<num; i++)
a[i] = new Rect(buff[i*_channels], buff[i*_channels+1], buff[i*_channels+2], buff[i*_channels+3]);
return a;
}
public void fromList(List<Rect> lr) {
Rect ap[] = lr.toArray(new Rect[0]);
fromArray(ap);
}
public List<Rect> toList() {
Rect[] ar = toArray();
return Arrays.asList(ar);
}
}

View File

@ -0,0 +1,81 @@
package org.opencv.core;
import java.util.Arrays;
import java.util.List;
public class MatOfRect2d extends Mat {
// 64FC4
private static final int _depth = CvType.CV_64F;
private static final int _channels = 4;
public MatOfRect2d() {
super();
}
protected MatOfRect2d(long addr) {
super(addr);
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public static MatOfRect2d fromNativeAddr(long addr) {
return new MatOfRect2d(addr);
}
public MatOfRect2d(Mat m) {
super(m, Range.all());
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public MatOfRect2d(Rect2d...a) {
super();
fromArray(a);
}
public void alloc(int elemNumber) {
if(elemNumber>0)
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
}
public void fromArray(Rect2d...a) {
if(a==null || a.length==0)
return;
int num = a.length;
alloc(num);
double buff[] = new double[num * _channels];
for(int i=0; i<num; i++) {
Rect2d r = a[i];
buff[_channels*i+0] = (double) r.x;
buff[_channels*i+1] = (double) r.y;
buff[_channels*i+2] = (double) r.width;
buff[_channels*i+3] = (double) r.height;
}
put(0, 0, buff); //TODO: check ret val!
}
public Rect2d[] toArray() {
int num = (int) total();
Rect2d[] a = new Rect2d[num];
if(num == 0)
return a;
double buff[] = new double[num * _channels];
get(0, 0, buff); //TODO: check ret val!
for(int i=0; i<num; i++)
a[i] = new Rect2d(buff[i*_channels], buff[i*_channels+1], buff[i*_channels+2], buff[i*_channels+3]);
return a;
}
public void fromList(List<Rect2d> lr) {
Rect2d ap[] = lr.toArray(new Rect2d[0]);
fromArray(ap);
}
public List<Rect2d> toList() {
Rect2d[] ar = toArray();
return Arrays.asList(ar);
}
}

View File

@ -0,0 +1,86 @@
package org.opencv.core;
import java.util.Arrays;
import java.util.List;
import org.opencv.core.RotatedRect;
public class MatOfRotatedRect extends Mat {
// 32FC5
private static final int _depth = CvType.CV_32F;
private static final int _channels = 5;
public MatOfRotatedRect() {
super();
}
protected MatOfRotatedRect(long addr) {
super(addr);
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public static MatOfRotatedRect fromNativeAddr(long addr) {
return new MatOfRotatedRect(addr);
}
public MatOfRotatedRect(Mat m) {
super(m, Range.all());
if( !empty() && checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incompatible Mat");
//FIXME: do we need release() here?
}
public MatOfRotatedRect(RotatedRect...a) {
super();
fromArray(a);
}
public void alloc(int elemNumber) {
if(elemNumber>0)
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
}
public void fromArray(RotatedRect...a) {
if(a==null || a.length==0)
return;
int num = a.length;
alloc(num);
float buff[] = new float[num * _channels];
for(int i=0; i<num; i++) {
RotatedRect r = a[i];
buff[_channels*i+0] = (float) r.center.x;
buff[_channels*i+1] = (float) r.center.y;
buff[_channels*i+2] = (float) r.size.width;
buff[_channels*i+3] = (float) r.size.height;
buff[_channels*i+4] = (float) r.angle;
}
put(0, 0, buff); //TODO: check ret val!
}
public RotatedRect[] toArray() {
int num = (int) total();
RotatedRect[] a = new RotatedRect[num];
if(num == 0)
return a;
float buff[] = new float[_channels];
for(int i=0; i<num; i++) {
get(i, 0, buff); //TODO: check ret val!
a[i] = new RotatedRect(new Point(buff[0],buff[1]),new Size(buff[2],buff[3]),buff[4]);
}
return a;
}
public void fromList(List<RotatedRect> lr) {
RotatedRect ap[] = lr.toArray(new RotatedRect[0]);
fromArray(ap);
}
public List<RotatedRect> toList() {
RotatedRect[] ar = toArray();
return Arrays.asList(ar);
}
}

View File

@ -0,0 +1,68 @@
package org.opencv.core;
//javadoc:Point_
public class Point {
public double x, y;
public Point(double x, double y) {
this.x = x;
this.y = y;
}
public Point() {
this(0, 0);
}
public Point(double[] vals) {
this();
set(vals);
}
public void set(double[] vals) {
if (vals != null) {
x = vals.length > 0 ? vals[0] : 0;
y = vals.length > 1 ? vals[1] : 0;
} else {
x = 0;
y = 0;
}
}
public Point clone() {
return new Point(x, y);
}
public double dot(Point p) {
return x * p.x + y * p.y;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(x);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(y);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof Point)) return false;
Point it = (Point) obj;
return x == it.x && y == it.y;
}
public boolean inside(Rect r) {
return r.contains(this);
}
@Override
public String toString() {
return "{" + x + ", " + y + "}";
}
}

View File

@ -0,0 +1,79 @@
package org.opencv.core;
//javadoc:Point3_
public class Point3 {
public double x, y, z;
public Point3(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
}
public Point3() {
this(0, 0, 0);
}
public Point3(Point p) {
x = p.x;
y = p.y;
z = 0;
}
public Point3(double[] vals) {
this();
set(vals);
}
public void set(double[] vals) {
if (vals != null) {
x = vals.length > 0 ? vals[0] : 0;
y = vals.length > 1 ? vals[1] : 0;
z = vals.length > 2 ? vals[2] : 0;
} else {
x = 0;
y = 0;
z = 0;
}
}
public Point3 clone() {
return new Point3(x, y, z);
}
public double dot(Point3 p) {
return x * p.x + y * p.y + z * p.z;
}
public Point3 cross(Point3 p) {
return new Point3(y * p.z - z * p.y, z * p.x - x * p.z, x * p.y - y * p.x);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(x);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(y);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(z);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof Point3)) return false;
Point3 it = (Point3) obj;
return x == it.x && y == it.y && z == it.z;
}
@Override
public String toString() {
return "{" + x + ", " + y + ", " + z + "}";
}
}

View File

@ -0,0 +1,82 @@
package org.opencv.core;
//javadoc:Range
public class Range {
public int start, end;
public Range(int s, int e) {
this.start = s;
this.end = e;
}
public Range() {
this(0, 0);
}
public Range(double[] vals) {
set(vals);
}
public void set(double[] vals) {
if (vals != null) {
start = vals.length > 0 ? (int) vals[0] : 0;
end = vals.length > 1 ? (int) vals[1] : 0;
} else {
start = 0;
end = 0;
}
}
public int size() {
return empty() ? 0 : end - start;
}
public boolean empty() {
return end <= start;
}
public static Range all() {
return new Range(Integer.MIN_VALUE, Integer.MAX_VALUE);
}
public Range intersection(Range r1) {
Range r = new Range(Math.max(r1.start, this.start), Math.min(r1.end, this.end));
r.end = Math.max(r.end, r.start);
return r;
}
public Range shift(int delta) {
return new Range(start + delta, end + delta);
}
public Range clone() {
return new Range(start, end);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(start);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(end);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof Range)) return false;
Range it = (Range) obj;
return start == it.start && end == it.end;
}
@Override
public String toString() {
return "[" + start + ", " + end + ")";
}
}

View File

@ -0,0 +1,104 @@
package org.opencv.core;
//javadoc:Rect_
public class Rect {
public int x, y, width, height;
public Rect(int x, int y, int width, int height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
public Rect() {
this(0, 0, 0, 0);
}
public Rect(Point p1, Point p2) {
x = (int) (p1.x < p2.x ? p1.x : p2.x);
y = (int) (p1.y < p2.y ? p1.y : p2.y);
width = (int) (p1.x > p2.x ? p1.x : p2.x) - x;
height = (int) (p1.y > p2.y ? p1.y : p2.y) - y;
}
public Rect(Point p, Size s) {
this((int) p.x, (int) p.y, (int) s.width, (int) s.height);
}
public Rect(double[] vals) {
set(vals);
}
public void set(double[] vals) {
if (vals != null) {
x = vals.length > 0 ? (int) vals[0] : 0;
y = vals.length > 1 ? (int) vals[1] : 0;
width = vals.length > 2 ? (int) vals[2] : 0;
height = vals.length > 3 ? (int) vals[3] : 0;
} else {
x = 0;
y = 0;
width = 0;
height = 0;
}
}
public Rect clone() {
return new Rect(x, y, width, height);
}
public Point tl() {
return new Point(x, y);
}
public Point br() {
return new Point(x + width, y + height);
}
public Size size() {
return new Size(width, height);
}
public double area() {
return width * height;
}
public boolean empty() {
return width <= 0 || height <= 0;
}
public boolean contains(Point p) {
return x <= p.x && p.x < x + width && y <= p.y && p.y < y + height;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(height);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(width);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(x);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(y);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof Rect)) return false;
Rect it = (Rect) obj;
return x == it.x && y == it.y && width == it.width && height == it.height;
}
@Override
public String toString() {
return "{" + x + ", " + y + ", " + width + "x" + height + "}";
}
}

View File

@ -0,0 +1,104 @@
package org.opencv.core;
//javadoc:Rect2d_
public class Rect2d {
public double x, y, width, height;
public Rect2d(double x, double y, double width, double height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
public Rect2d() {
this(0, 0, 0, 0);
}
public Rect2d(Point p1, Point p2) {
x = (double) (p1.x < p2.x ? p1.x : p2.x);
y = (double) (p1.y < p2.y ? p1.y : p2.y);
width = (double) (p1.x > p2.x ? p1.x : p2.x) - x;
height = (double) (p1.y > p2.y ? p1.y : p2.y) - y;
}
public Rect2d(Point p, Size s) {
this((double) p.x, (double) p.y, (double) s.width, (double) s.height);
}
public Rect2d(double[] vals) {
set(vals);
}
public void set(double[] vals) {
if (vals != null) {
x = vals.length > 0 ? (double) vals[0] : 0;
y = vals.length > 1 ? (double) vals[1] : 0;
width = vals.length > 2 ? (double) vals[2] : 0;
height = vals.length > 3 ? (double) vals[3] : 0;
} else {
x = 0;
y = 0;
width = 0;
height = 0;
}
}
public Rect2d clone() {
return new Rect2d(x, y, width, height);
}
public Point tl() {
return new Point(x, y);
}
public Point br() {
return new Point(x + width, y + height);
}
public Size size() {
return new Size(width, height);
}
public double area() {
return width * height;
}
public boolean empty() {
return width <= 0 || height <= 0;
}
public boolean contains(Point p) {
return x <= p.x && p.x < x + width && y <= p.y && p.y < y + height;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(height);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(width);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(x);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(y);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof Rect2d)) return false;
Rect2d it = (Rect2d) obj;
return x == it.x && y == it.y && width == it.width && height == it.height;
}
@Override
public String toString() {
return "{" + x + ", " + y + ", " + width + "x" + height + "}";
}
}

View File

@ -0,0 +1,113 @@
package org.opencv.core;
//javadoc:RotatedRect_
public class RotatedRect {
public Point center;
public Size size;
public double angle;
public RotatedRect() {
this.center = new Point();
this.size = new Size();
this.angle = 0;
}
public RotatedRect(Point c, Size s, double a) {
this.center = c.clone();
this.size = s.clone();
this.angle = a;
}
public RotatedRect(double[] vals) {
this();
set(vals);
}
public void set(double[] vals) {
if (vals != null) {
center.x = vals.length > 0 ? (double) vals[0] : 0;
center.y = vals.length > 1 ? (double) vals[1] : 0;
size.width = vals.length > 2 ? (double) vals[2] : 0;
size.height = vals.length > 3 ? (double) vals[3] : 0;
angle = vals.length > 4 ? (double) vals[4] : 0;
} else {
center.x = 0;
center.y = 0;
size.width = 0;
size.height = 0;
angle = 0;
}
}
public void points(Point pt[])
{
double _angle = angle * Math.PI / 180.0;
double b = (double) Math.cos(_angle) * 0.5f;
double a = (double) Math.sin(_angle) * 0.5f;
pt[0] = new Point(
center.x - a * size.height - b * size.width,
center.y + b * size.height - a * size.width);
pt[1] = new Point(
center.x + a * size.height - b * size.width,
center.y - b * size.height - a * size.width);
pt[2] = new Point(
2 * center.x - pt[0].x,
2 * center.y - pt[0].y);
pt[3] = new Point(
2 * center.x - pt[1].x,
2 * center.y - pt[1].y);
}
public Rect boundingRect()
{
Point pt[] = new Point[4];
points(pt);
Rect r = new Rect((int) Math.floor(Math.min(Math.min(Math.min(pt[0].x, pt[1].x), pt[2].x), pt[3].x)),
(int) Math.floor(Math.min(Math.min(Math.min(pt[0].y, pt[1].y), pt[2].y), pt[3].y)),
(int) Math.ceil(Math.max(Math.max(Math.max(pt[0].x, pt[1].x), pt[2].x), pt[3].x)),
(int) Math.ceil(Math.max(Math.max(Math.max(pt[0].y, pt[1].y), pt[2].y), pt[3].y)));
r.width -= r.x - 1;
r.height -= r.y - 1;
return r;
}
public RotatedRect clone() {
return new RotatedRect(center, size, angle);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(center.x);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(center.y);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(size.width);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(size.height);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(angle);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof RotatedRect)) return false;
RotatedRect it = (RotatedRect) obj;
return center.equals(it.center) && size.equals(it.size) && angle == it.angle;
}
@Override
public String toString() {
return "{ " + center + " " + size + " * " + angle + " }";
}
}

View File

@ -0,0 +1,90 @@
package org.opencv.core;
//javadoc:Scalar_
public class Scalar {
public double val[];
public Scalar(double v0, double v1, double v2, double v3) {
val = new double[] { v0, v1, v2, v3 };
}
public Scalar(double v0, double v1, double v2) {
val = new double[] { v0, v1, v2, 0 };
}
public Scalar(double v0, double v1) {
val = new double[] { v0, v1, 0, 0 };
}
public Scalar(double v0) {
val = new double[] { v0, 0, 0, 0 };
}
public Scalar(double[] vals) {
if (vals != null && vals.length == 4)
val = vals.clone();
else {
val = new double[4];
set(vals);
}
}
public void set(double[] vals) {
if (vals != null) {
val[0] = vals.length > 0 ? vals[0] : 0;
val[1] = vals.length > 1 ? vals[1] : 0;
val[2] = vals.length > 2 ? vals[2] : 0;
val[3] = vals.length > 3 ? vals[3] : 0;
} else
val[0] = val[1] = val[2] = val[3] = 0;
}
public static Scalar all(double v) {
return new Scalar(v, v, v, v);
}
public Scalar clone() {
return new Scalar(val);
}
public Scalar mul(Scalar it, double scale) {
return new Scalar(val[0] * it.val[0] * scale, val[1] * it.val[1] * scale,
val[2] * it.val[2] * scale, val[3] * it.val[3] * scale);
}
public Scalar mul(Scalar it) {
return mul(it, 1);
}
public Scalar conj() {
return new Scalar(val[0], -val[1], -val[2], -val[3]);
}
public boolean isReal() {
return val[1] == 0 && val[2] == 0 && val[3] == 0;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + java.util.Arrays.hashCode(val);
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof Scalar)) return false;
Scalar it = (Scalar) obj;
if (!java.util.Arrays.equals(val, it.val)) return false;
return true;
}
@Override
public String toString() {
return "[" + val[0] + ", " + val[1] + ", " + val[2] + ", " + val[3] + "]";
}
}

View File

@ -0,0 +1,73 @@
package org.opencv.core;
//javadoc:Size_
public class Size {
public double width, height;
public Size(double width, double height) {
this.width = width;
this.height = height;
}
public Size() {
this(0, 0);
}
public Size(Point p) {
width = p.x;
height = p.y;
}
public Size(double[] vals) {
set(vals);
}
public void set(double[] vals) {
if (vals != null) {
width = vals.length > 0 ? vals[0] : 0;
height = vals.length > 1 ? vals[1] : 0;
} else {
width = 0;
height = 0;
}
}
public double area() {
return width * height;
}
public boolean empty() {
return width <= 0 || height <= 0;
}
public Size clone() {
return new Size(width, height);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(height);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(width);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof Size)) return false;
Size it = (Size) obj;
return width == it.width && height == it.height;
}
@Override
public String toString() {
return (int)width + "x" + (int)height;
}
}

View File

@ -0,0 +1,92 @@
package org.opencv.core;
//javadoc:TermCriteria
public class TermCriteria {
/**
* The maximum number of iterations or elements to compute
*/
public static final int COUNT = 1;
/**
* The maximum number of iterations or elements to compute
*/
public static final int MAX_ITER = COUNT;
/**
* The desired accuracy threshold or change in parameters at which the iterative algorithm is terminated.
*/
public static final int EPS = 2;
public int type;
public int maxCount;
public double epsilon;
/**
* Termination criteria for iterative algorithms.
*
* @param type
* the type of termination criteria: COUNT, EPS or COUNT + EPS.
* @param maxCount
* the maximum number of iterations/elements.
* @param epsilon
* the desired accuracy.
*/
public TermCriteria(int type, int maxCount, double epsilon) {
this.type = type;
this.maxCount = maxCount;
this.epsilon = epsilon;
}
/**
* Termination criteria for iterative algorithms.
*/
public TermCriteria() {
this(0, 0, 0.0);
}
public TermCriteria(double[] vals) {
set(vals);
}
public void set(double[] vals) {
if (vals != null) {
type = vals.length > 0 ? (int) vals[0] : 0;
maxCount = vals.length > 1 ? (int) vals[1] : 0;
epsilon = vals.length > 2 ? (double) vals[2] : 0;
} else {
type = 0;
maxCount = 0;
epsilon = 0;
}
}
public TermCriteria clone() {
return new TermCriteria(type, maxCount, epsilon);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(type);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(maxCount);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(epsilon);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof TermCriteria)) return false;
TermCriteria it = (TermCriteria) obj;
return type == it.type && maxCount == it.maxCount && epsilon == it.epsilon;
}
@Override
public String toString() {
return "{ type: " + type + ", maxCount: " + maxCount + ", epsilon: " + epsilon + "}";
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,71 @@
package org.opencv.test.core;
import org.opencv.core.CvType;
import org.opencv.test.OpenCVTestCase;
public class CvTypeTest extends OpenCVTestCase {
public void testMakeType() {
assertEquals(CvType.CV_8UC4, CvType.makeType(CvType.CV_8U, 4));
}
public void testCV_8UC() {
assertEquals(CvType.CV_8UC4, CvType.CV_8UC(4));
}
public void testCV_8SC() {
assertEquals(CvType.CV_8SC4, CvType.CV_8SC(4));
}
public void testCV_16UC() {
assertEquals(CvType.CV_16UC4, CvType.CV_16UC(4));
}
public void testCV_16SC() {
assertEquals(CvType.CV_16SC4, CvType.CV_16SC(4));
}
public void testCV_32SC() {
assertEquals(CvType.CV_32SC4, CvType.CV_32SC(4));
}
public void testCV_32FC() {
assertEquals(CvType.CV_32FC4, CvType.CV_32FC(4));
}
public void testCV_64FC() {
assertEquals(CvType.CV_64FC4, CvType.CV_64FC(4));
}
public void testCV_16FC() {
assertEquals(CvType.CV_16FC1, CvType.CV_16FC(1));
assertEquals(CvType.CV_16FC2, CvType.CV_16FC(2));
assertEquals(CvType.CV_16FC3, CvType.CV_16FC(3));
assertEquals(CvType.CV_16FC4, CvType.CV_16FC(4));
}
public void testChannels() {
assertEquals(1, CvType.channels(CvType.CV_64F));
}
public void testDepth() {
assertEquals(CvType.CV_64F, CvType.depth(CvType.CV_64FC3));
}
public void testIsInteger() {
assertFalse(CvType.isInteger(CvType.CV_32FC3));
assertTrue(CvType.isInteger(CvType.CV_16S));
}
public void testELEM_SIZE() {
assertEquals(3 * 8, CvType.ELEM_SIZE(CvType.CV_64FC3));
assertEquals(3 * 2, CvType.ELEM_SIZE(CvType.CV_16FC3));
}
public void testTypeToString() {
assertEquals("CV_32FC1", CvType.typeToString(CvType.CV_32F));
assertEquals("CV_32FC3", CvType.typeToString(CvType.CV_32FC3));
assertEquals("CV_32FC(128)", CvType.typeToString(CvType.CV_32FC(128)));
}
}

View File

@ -0,0 +1,44 @@
package org.opencv.test.core;
import org.opencv.core.DMatch;
import junit.framework.TestCase;
public class DMatchTest extends TestCase {
public void testDMatch() {
new DMatch();
}
public void testDMatchIntIntFloat() {
DMatch dm1 = new DMatch(1, 4, 4.0f);
assertEquals(1, dm1.queryIdx);
assertEquals(4, dm1.trainIdx);
assertEquals(4.0f, dm1.distance);
}
public void testDMatchIntIntIntFloat() {
DMatch dm2 = new DMatch(2, 6, -1, 8.0f);
assertEquals(2, dm2.queryIdx);
assertEquals(6, dm2.trainIdx);
assertEquals(-1, dm2.imgIdx);
assertEquals(8.0f, dm2.distance);
}
public void testLessThan() {
DMatch dm1 = new DMatch(1, 4, 4.0f);
DMatch dm2 = new DMatch(2, 6, -1, 8.0f);
assertTrue(dm1.lessThan(dm2));
}
public void testToString() {
DMatch dm2 = new DMatch(2, 6, -1, 8.0f);
String actual = dm2.toString();
String expected = "DMatch [queryIdx=2, trainIdx=6, imgIdx=-1, distance=8.0]";
assertEquals(expected, actual);
}
}

View File

@ -0,0 +1,71 @@
package org.opencv.test.core;
import org.opencv.core.Point;
import org.opencv.core.KeyPoint;
import org.opencv.test.OpenCVTestCase;
public class KeyPointTest extends OpenCVTestCase {
private float angle;
private int classId;
private KeyPoint keyPoint;
private int octave;
private float response;
private float size;
private float x;
private float y;
@Override
protected void setUp() throws Exception {
super.setUp();
keyPoint = null;
x = 1.0f;
y = 2.0f;
size = 3.0f;
angle = 30.0f;
response = 2.0f;
octave = 1;
classId = 1;
}
public void testKeyPoint() {
keyPoint = new KeyPoint();
assertPointEquals(new Point(0, 0), keyPoint.pt, EPS);
}
public void testKeyPointFloatFloatFloat() {
keyPoint = new KeyPoint(x, y, size);
assertPointEquals(new Point(1, 2), keyPoint.pt, EPS);
}
public void testKeyPointFloatFloatFloatFloat() {
keyPoint = new KeyPoint(x, y, size, 10.0f);
assertEquals(10.0f, keyPoint.angle);
}
public void testKeyPointFloatFloatFloatFloatFloat() {
keyPoint = new KeyPoint(x, y, size, 1.0f, 1.0f);
assertEquals(1.0f, keyPoint.response);
}
public void testKeyPointFloatFloatFloatFloatFloatInt() {
keyPoint = new KeyPoint(x, y, size, 1.0f, 1.0f, 1);
assertEquals(1, keyPoint.octave);
}
public void testKeyPointFloatFloatFloatFloatFloatIntInt() {
keyPoint = new KeyPoint(x, y, size, 1.0f, 1.0f, 1, 1);
assertEquals(1, keyPoint.class_id);
}
public void testToString() {
keyPoint = new KeyPoint(x, y, size, angle, response, octave, classId);
String actual = keyPoint.toString();
String expected = "KeyPoint [pt={1.0, 2.0}, size=3.0, angle=30.0, response=2.0, octave=1, class_id=1]";
assertEquals(expected, actual);
}
}

View File

@ -0,0 +1,70 @@
package org.opencv.test.core;
import java.util.Arrays;
import org.opencv.core.Core;
import org.opencv.core.CvException;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.MatOfByte;
import org.opencv.core.MatOfDouble;
import org.opencv.test.OpenCVTestCase;
import org.opencv.imgcodecs.Imgcodecs;
public class MatOfByteTest extends OpenCVTestCase {
public void testMatOfSubByteArray() {
byte[] inputBytes = { 1,2,3,4,5 };
MatOfByte m0 = new MatOfByte(inputBytes);
MatOfByte m1 = new MatOfByte(0, inputBytes.length, inputBytes);
MatOfByte m2 = new MatOfByte(1, inputBytes.length - 2, inputBytes);
assertEquals(5.0, m0.size().height);
assertEquals(1.0, m0.size().width);
assertEquals(m0.get(0, 0)[0], m1.get(0, 0)[0]);
assertEquals(m0.get((int) m0.size().height - 1, 0)[0], m1.get((int) m1.size().height - 1, 0)[0]);
assertEquals(3.0, m2.size().height);
assertEquals(1.0, m2.size().width);
assertEquals(2.0, m2.get(0, 0)[0]);
assertEquals(3.0, m2.get(1, 0)[0]);
assertEquals(4.0, m2.get(2, 0)[0]);
}
public void testMatOfSubByteArray_BadArg() {
byte[] inputBytes = { 1,2,3,4,5 };
try {
MatOfByte m1 = new MatOfByte(-1, inputBytes.length, inputBytes);
fail("Missing check: offset < 0");
} catch (IllegalArgumentException e) {
// pass
}
try {
MatOfByte m1 = new MatOfByte(0, inputBytes.length, null);
fail("Missing check: NullPointerException");
} catch (NullPointerException e) {
// pass
}
try {
MatOfByte m1 = new MatOfByte(0, -1, inputBytes);
fail("Missing check: length < 0");
} catch (IllegalArgumentException e) {
// pass
}
try {
MatOfByte m1 = new MatOfByte(1, inputBytes.length, inputBytes);
fail("Missing check: buffer bounds");
} catch (IllegalArgumentException e) {
// pass
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,107 @@
package org.opencv.test.core;
import org.opencv.core.Point;
import org.opencv.core.Point3;
import org.opencv.test.OpenCVTestCase;
public class Point3Test extends OpenCVTestCase {
private Point3 p1;
private Point3 p2;
@Override
protected void setUp() throws Exception {
super.setUp();
p1 = new Point3(2, 2, 2);
p2 = new Point3(1, 1, 1);
}
public void testClone() {
Point3 truth = new Point3(1, 1, 1);
p1 = truth.clone();
assertEquals(truth, p1);
}
public void testCross() {
Point3 dstPoint = p1.cross(p2);
Point3 truth = new Point3(0, 0, 0);
assertEquals(truth, dstPoint);
}
public void testDot() {
double result = p1.dot(p2);
assertEquals(6.0, result);
}
public void testEqualsObject() {
boolean flag = p1.equals(p1);
assertTrue(flag);
flag = p1.equals(p2);
assertFalse(flag);
}
public void testHashCode() {
assertEquals(p1.hashCode(), p1.hashCode());
}
public void testPoint3() {
p1 = new Point3();
assertNotNull(p1);
assertTrue(0 == p1.x);
assertTrue(0 == p1.y);
assertTrue(0 == p1.z);
}
public void testPoint3DoubleArray() {
double[] vals = { 1, 2, 3 };
p1 = new Point3(vals);
assertTrue(1 == p1.x);
assertTrue(2 == p1.y);
assertTrue(3 == p1.z);
}
public void testPoint3DoubleDoubleDouble() {
p1 = new Point3(1, 2, 3);
assertEquals(1., p1.x);
assertEquals(2., p1.y);
assertEquals(3., p1.z);
}
public void testPoint3Point() {
Point p = new Point(2, 3);
p1 = new Point3(p);
assertEquals(2., p1.x);
assertEquals(3., p1.y);
assertEquals(0., p1.z);
}
public void testSet() {
double[] vals1 = {};
p1.set(vals1);
assertEquals(0., p1.x);
assertEquals(0., p1.y);
assertEquals(0., p1.z);
double[] vals2 = { 3, 6, 10 };
p1.set(vals2);
assertEquals(3., p1.x);
assertEquals(6., p1.y);
assertEquals(10., p1.z);
}
public void testToString() {
String actual = p1.toString();
String expected = "{2.0, 2.0, 2.0}";
assertEquals(expected, actual);
}
}

View File

@ -0,0 +1,93 @@
package org.opencv.test.core;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.test.OpenCVTestCase;
public class PointTest extends OpenCVTestCase {
private Point p1;
private Point p2;
@Override
protected void setUp() throws Exception {
super.setUp();
p1 = new Point(2, 2);
p2 = new Point(1, 1);
}
public void testClone() {
Point truth = new Point(1, 1);
Point dstPoint = truth.clone();
assertEquals(truth, dstPoint);
}
public void testDot() {
double result = p1.dot(p2);
assertEquals(4.0, result);
}
public void testEqualsObject() {
boolean flag = p1.equals(p1);
assertTrue(flag);
flag = p1.equals(p2);
assertFalse(flag);
}
public void testHashCode() {
assertEquals(p1.hashCode(), p1.hashCode());
}
public void testInside() {
Rect rect = new Rect(0, 0, 5, 3);
assertTrue(p1.inside(rect));
Point p2 = new Point(3, 3);
assertFalse(p2.inside(rect));
}
public void testPoint() {
Point p = new Point();
assertNotNull(p);
assertEquals(0.0, p.x);
assertEquals(0.0, p.y);
}
public void testPointDoubleArray() {
double[] vals = { 2, 4 };
Point p = new Point(vals);
assertEquals(2.0, p.x);
assertEquals(4.0, p.y);
}
public void testPointDoubleDouble() {
p1 = new Point(7, 5);
assertNotNull(p1);
assertEquals(7.0, p1.x);
assertEquals(5.0, p1.y);
}
public void testSet() {
double[] vals1 = {};
p1.set(vals1);
assertEquals(0.0, p1.x);
assertEquals(0.0, p1.y);
double[] vals2 = { 6, 10 };
p2.set(vals2);
assertEquals(6.0, p2.x);
assertEquals(10.0, p2.y);
}
public void testToString() {
String actual = p1.toString();
String expected = "{2.0, 2.0}";
assertEquals(expected, actual);
}
}

View File

@ -0,0 +1,113 @@
package org.opencv.test.core;
import org.opencv.core.Range;
import org.opencv.test.OpenCVTestCase;
public class RangeTest extends OpenCVTestCase {
Range r1;
Range r2;
Range range;
@Override
protected void setUp() throws Exception {
super.setUp();
range = new Range();
r1 = new Range(1, 11);
r2 = new Range(1, 1);
}
public void testAll() {
range = Range.all();
assertEquals(Integer.MIN_VALUE, range.start);
assertEquals(Integer.MAX_VALUE, range.end);
}
public void testClone() {
Range dstRange = new Range();
dstRange = r1.clone();
assertEquals(r1, dstRange);
}
public void testEmpty() {
boolean flag;
flag = r1.empty();
assertFalse(flag);
flag = r2.empty();
assertTrue(flag);
}
public void testEqualsObject() {
assertFalse(r2.equals(r1));
range = r1.clone();
assertTrue(r1.equals(range));
}
public void testHashCode() {
assertEquals(r1.hashCode(), r1.hashCode());
}
public void testIntersection() {
range = r1.intersection(r2);
assertEquals(r2, range);
}
public void testRange() {
range = new Range();
assertNotNull(range);
assertEquals(0, range.start);
assertEquals(0, range.end);
}
public void testRangeDoubleArray() {
double[] vals = { 2, 4 };
Range r = new Range(vals);
assertTrue(2 == r.start);
assertTrue(4 == r.end);
}
public void testRangeIntInt() {
r1 = new Range(12, 13);
assertNotNull(r1);
assertEquals(12, r1.start);
assertEquals(13, r1.end);
}
public void testSet() {
double[] vals1 = {};
r1.set(vals1);
assertEquals(0, r1.start);
assertEquals(0, r1.end);
double[] vals2 = { 6, 10 };
r2.set(vals2);
assertEquals(6, r2.start);
assertEquals(10, r2.end);
}
public void testShift() {
int delta = 1;
range = range.shift(delta);
assertEquals(r2, range);
}
public void testSize() {
assertEquals(10, r1.size());
assertEquals(0, r2.size());
}
public void testToString() {
String actual = r1.toString();
String expected = "[1, 11)";
assertEquals(expected, actual);
}
}

View File

@ -0,0 +1,163 @@
package org.opencv.test.core;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.core.Size;
import org.opencv.test.OpenCVTestCase;
public class RectTest extends OpenCVTestCase {
private Rect r;
private Rect rect;
@Override
protected void setUp() throws Exception {
super.setUp();
r = new Rect();
rect = new Rect(0, 0, 10, 10);
}
public void testArea() {
double area;
area = rect.area();
assertEquals(100.0, area);
}
public void testBr() {
Point p_br = new Point();
p_br = rect.br();
Point truth = new Point(10, 10);
assertEquals(truth, p_br);
}
public void testClone() {
r = rect.clone();
assertEquals(rect, r);
}
public void testContains() {
Rect rect = new Rect(0, 0, 10, 10);
Point p_inner = new Point(5, 5);
Point p_outer = new Point(5, 55);
Point p_bl = new Point(0, 0);
Point p_br = new Point(10, 0);
Point p_tl = new Point(0, 10);
Point p_tr = new Point(10, 10);
assertTrue(rect.contains(p_inner));
assertTrue(rect.contains(p_bl));
assertFalse(rect.contains(p_outer));
assertFalse(rect.contains(p_br));
assertFalse(rect.contains(p_tl));
assertFalse(rect.contains(p_tr));
}
public void testEqualsObject() {
boolean flag;
flag = rect.equals(r);
assertFalse(flag);
r = rect.clone();
flag = rect.equals(r);
assertTrue(flag);
}
public void testHashCode() {
assertEquals(rect.hashCode(), rect.hashCode());
}
public void testRect() {
r = new Rect();
assertEquals(0, r.x);
assertEquals(0, r.y);
assertEquals(0, r.width);
assertEquals(0, r.height);
}
public void testRectDoubleArray() {
double[] vals = { 1, 3, 5, 2 };
r = new Rect(vals);
assertEquals(1, r.x);
assertEquals(3, r.y);
assertEquals(5, r.width);
assertEquals(2, r.height);
}
public void testRectIntIntIntInt() {
r = new Rect(1, 3, 5, 2);
assertNotNull(rect);
assertEquals(0, rect.x);
assertEquals(0, rect.y);
assertEquals(10, rect.width);
assertEquals(10, rect.height);
}
public void testRectPointPoint() {
Point p1 = new Point(4, 4);
Point p2 = new Point(2, 3);
r = new Rect(p1, p2);
assertNotNull(r);
assertEquals(2, r.x);
assertEquals(3, r.y);
assertEquals(2, r.width);
assertEquals(1, r.height);
}
public void testRectPointSize() {
Point p1 = new Point(4, 4);
Size sz = new Size(3, 1);
r = new Rect(p1, sz);
assertEquals(4, r.x);
assertEquals(4, r.y);
assertEquals(3, r.width);
assertEquals(1, r.height);
}
public void testSet() {
double[] vals1 = {};
Rect r1 = new Rect(vals1);
assertEquals(0, r1.x);
assertEquals(0, r1.y);
assertEquals(0, r1.width);
assertEquals(0, r1.height);
double[] vals2 = { 2, 2, 10, 5 };
r = new Rect(vals2);
assertEquals(2, r.x);
assertEquals(2, r.y);
assertEquals(10, r.width);
assertEquals(5, r.height);
}
public void testSize() {
Size s1 = new Size(0, 0);
assertEquals(s1, r.size());
Size s2 = new Size(10, 10);
assertEquals(s2, rect.size());
}
public void testTl() {
Point p_tl = new Point();
p_tl = rect.tl();
Point truth = new Point(0, 0);
assertEquals(truth, p_tl);
}
public void testToString() {
String actual = rect.toString();
String expected = "{0, 0, 10x10}";
assertEquals(expected, actual);
}
}

View File

@ -0,0 +1,213 @@
package org.opencv.test.core;
import org.opencv.core.CvType;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.core.RotatedRect;
import org.opencv.core.MatOfRotatedRect;
import org.opencv.core.Size;
import org.opencv.test.OpenCVTestCase;
import java.util.Arrays;
import java.util.List;
public class RotatedRectTest extends OpenCVTestCase {
private double angle;
private Point center;
private Size size;
@Override
protected void setUp() throws Exception {
super.setUp();
center = new Point(matSize / 2, matSize / 2);
size = new Size(matSize / 4, matSize / 2);
angle = 40;
}
public void testBoundingRect() {
size = new Size(matSize / 2, matSize / 2);
assertEquals(size.height, size.width);
double length = size.height;
angle = 45;
RotatedRect rr = new RotatedRect(center, size, angle);
Rect r = rr.boundingRect();
double halfDiagonal = length * Math.sqrt(2) / 2;
assertTrue((r.x == Math.floor(center.x - halfDiagonal)) && (r.y == Math.floor(center.y - halfDiagonal)));
assertTrue((r.br().x >= Math.ceil(center.x + halfDiagonal)) && (r.br().y >= Math.ceil(center.y + halfDiagonal)));
assertTrue((r.br().x - Math.ceil(center.x + halfDiagonal)) <= 1 && (r.br().y - Math.ceil(center.y + halfDiagonal)) <= 1);
}
public void testClone() {
RotatedRect rrect = new RotatedRect(center, size, angle);
RotatedRect clone = rrect.clone();
assertNotNull(clone);
assertTrue(rrect.center.equals(clone.center));
assertTrue(rrect.size.equals(clone.size));
assertTrue(rrect.angle == clone.angle);
}
public void testEqualsObject() {
Point center2 = new Point(matSize / 3, matSize / 1.5);
Size size2 = new Size(matSize / 2, matSize / 4);
double angle2 = 0;
RotatedRect rrect1 = new RotatedRect(center, size, angle);
RotatedRect rrect2 = new RotatedRect(center2, size2, angle2);
RotatedRect rrect3 = rrect1;
RotatedRect clone1 = rrect1.clone();
RotatedRect clone2 = rrect2.clone();
assertTrue(rrect1.equals(rrect3));
assertFalse(rrect1.equals(rrect2));
assertTrue(rrect2.equals(clone2));
clone2.angle = 10;
assertFalse(rrect2.equals(clone2));
assertTrue(rrect1.equals(clone1));
clone1.center.x += 1;
assertFalse(rrect1.equals(clone1));
clone1.center.x -= 1;
assertTrue(rrect1.equals(clone1));
clone1.size.width += 1;
assertFalse(rrect1.equals(clone1));
assertFalse(rrect1.equals(size));
}
public void testHashCode() {
RotatedRect rr = new RotatedRect(center, size, angle);
assertEquals(rr.hashCode(), rr.hashCode());
}
public void testPoints() {
RotatedRect rrect = new RotatedRect(center, size, angle);
Point p[] = new Point[4];
rrect.points(p);
boolean is_p0_irrational = (100 * p[0].x != (int) (100 * p[0].x)) && (100 * p[0].y != (int) (100 * p[0].y));
boolean is_p1_irrational = (100 * p[1].x != (int) (100 * p[1].x)) && (100 * p[1].y != (int) (100 * p[1].y));
boolean is_p2_irrational = (100 * p[2].x != (int) (100 * p[2].x)) && (100 * p[2].y != (int) (100 * p[2].y));
boolean is_p3_irrational = (100 * p[3].x != (int) (100 * p[3].x)) && (100 * p[3].y != (int) (100 * p[3].y));
assertTrue(is_p0_irrational && is_p1_irrational && is_p2_irrational && is_p3_irrational);
assertTrue("Symmetric points 0 and 2",
Math.abs((p[0].x + p[2].x) / 2 - center.x) + Math.abs((p[0].y + p[2].y) / 2 - center.y) < EPS);
assertTrue("Symmetric points 1 and 3",
Math.abs((p[1].x + p[3].x) / 2 - center.x) + Math.abs((p[1].y + p[3].y) / 2 - center.y) < EPS);
assertTrue("Orthogonal vectors 01 and 12",
Math.abs((p[1].x - p[0].x) * (p[2].x - p[1].x) +
(p[1].y - p[0].y) * (p[2].y - p[1].y)) < EPS);
assertTrue("Orthogonal vectors 12 and 23",
Math.abs((p[2].x - p[1].x) * (p[3].x - p[2].x) +
(p[2].y - p[1].y) * (p[3].y - p[2].y)) < EPS);
assertTrue("Orthogonal vectors 23 and 30",
Math.abs((p[3].x - p[2].x) * (p[0].x - p[3].x) +
(p[3].y - p[2].y) * (p[0].y - p[3].y)) < EPS);
assertTrue("Orthogonal vectors 30 and 01",
Math.abs((p[0].x - p[3].x) * (p[1].x - p[0].x) +
(p[0].y - p[3].y) * (p[1].y - p[0].y)) < EPS);
assertTrue("Length of the vector 01",
Math.abs((p[1].x - p[0].x) * (p[1].x - p[0].x) +
(p[1].y - p[0].y) * (p[1].y - p[0].y) - size.height * size.height) < EPS);
assertTrue("Length of the vector 21",
Math.abs((p[1].x - p[2].x) * (p[1].x - p[2].x) +
(p[1].y - p[2].y) * (p[1].y - p[2].y) - size.width * size.width) < EPS);
assertTrue("Angle of the vector 21 with the axes", Math.abs((p[2].x - p[1].x) / size.width - Math.cos(angle * Math.PI / 180)) < EPS);
}
public void testRotatedRect() {
RotatedRect rr = new RotatedRect();
assertNotNull(rr);
assertNotNull(rr.center);
assertNotNull(rr.size);
assertEquals(0.0, rr.angle);
}
public void testRotatedRectDoubleArray() {
double[] vals = { 1.5, 2.6, 3.7, 4.2, 5.1 };
RotatedRect rr = new RotatedRect(vals);
assertNotNull(rr);
assertEquals(1.5, rr.center.x);
assertEquals(2.6, rr.center.y);
assertEquals(3.7, rr.size.width);
assertEquals(4.2, rr.size.height);
assertEquals(5.1, rr.angle);
}
public void testRotatedRectPointSizeDouble() {
RotatedRect rr = new RotatedRect(center, size, 40);
assertNotNull(rr);
assertNotNull(rr.center);
assertNotNull(rr.size);
assertEquals(40.0, rr.angle);
}
public void testSet() {
double[] vals1 = {};
RotatedRect r1 = new RotatedRect(center, size, 40);
r1.set(vals1);
assertEquals(0., r1.angle);
assertPointEquals(new Point(0, 0), r1.center, EPS);
assertSizeEquals(new Size(0, 0), r1.size, EPS);
double[] vals2 = { 1, 2, 3, 4, 5 };
RotatedRect r2 = new RotatedRect(center, size, 40);
r2.set(vals2);
assertEquals(5., r2.angle);
assertPointEquals(new Point(1, 2), r2.center, EPS);
assertSizeEquals(new Size(3, 4), r2.size, EPS);
}
public void testToString() {
String actual = new RotatedRect(new Point(1, 2), new Size(10, 12), 4.5).toString();
String expected = "{ {1.0, 2.0} 10x12 * 4.5 }";
assertEquals(expected, actual);
}
public void testMatOfRotatedRect() {
RotatedRect a = new RotatedRect(new Point(1,2),new Size(3,4),5.678);
RotatedRect b = new RotatedRect(new Point(9,8),new Size(7,6),5.432);
MatOfRotatedRect m = new MatOfRotatedRect(a,b,a,b,a,b,a,b);
assertEquals(m.rows(), 8);
assertEquals(m.cols(), 1);
assertEquals(m.type(), CvType.CV_32FC(5));
RotatedRect[] arr = m.toArray();
assertEquals(arr[2].angle, a.angle, EPS);
assertEquals(arr[3].center.x, b.center.x);
assertEquals(arr[3].size.width, b.size.width);
List<RotatedRect> li = m.toList();
assertEquals(li.size(), 8);
RotatedRect rr = li.get(7);
assertEquals(rr.angle, b.angle, EPS);
assertEquals(rr.center.y, b.center.y);
}
}

View File

@ -0,0 +1,110 @@
package org.opencv.test.core;
import org.opencv.core.Scalar;
import org.opencv.test.OpenCVTestCase;
public class ScalarTest extends OpenCVTestCase {
private Scalar dstScalar;
private Scalar s1;
private Scalar s2;
@Override
protected void setUp() throws Exception {
super.setUp();
s1 = new Scalar(1.0);
s2 = Scalar.all(1.0);
dstScalar = null;
}
public void testAll() {
dstScalar = Scalar.all(2.0);
Scalar truth = new Scalar(2.0, 2.0, 2.0, 2.0);
assertEquals(truth, dstScalar);
}
public void testClone() {
dstScalar = s2.clone();
assertEquals(s2, dstScalar);
}
public void testConj() {
dstScalar = s2.conj();
Scalar truth = new Scalar(1, -1, -1, -1);
assertEquals(truth, dstScalar);
}
public void testEqualsObject() {
dstScalar = s2.clone();
assertTrue(s2.equals(dstScalar));
assertFalse(s2.equals(s1));
}
public void testHashCode() {
assertEquals(s2.hashCode(), s2.hashCode());
}
public void testIsReal() {
assertTrue(s1.isReal());
assertFalse(s2.isReal());
}
public void testMulScalar() {
dstScalar = s2.mul(s1);
assertEquals(s1, dstScalar);
}
public void testMulScalarDouble() {
double multiplier = 2.0;
dstScalar = s2.mul(s1, multiplier);
Scalar truth = new Scalar(2);
assertEquals(truth, dstScalar);
}
public void testScalarDouble() {
Scalar truth = new Scalar(1);
assertEquals(truth, s1);
}
public void testScalarDoubleArray() {
double[] vals = { 2.0, 4.0, 5.0, 3.0 };
dstScalar = new Scalar(vals);
Scalar truth = new Scalar(2.0, 4.0, 5.0, 3.0);
assertEquals(truth, dstScalar);
}
public void testScalarDoubleDouble() {
dstScalar = new Scalar(2, 5);
Scalar truth = new Scalar(2.0, 5.0, 0.0, 0.0);
assertEquals(truth, dstScalar);
}
public void testScalarDoubleDoubleDouble() {
dstScalar = new Scalar(2.0, 5.0, 5.0);
Scalar truth = new Scalar(2.0, 5.0, 5.0, 0.0);
assertEquals(truth, dstScalar);
}
public void testScalarDoubleDoubleDoubleDouble() {
dstScalar = new Scalar(2.0, 5.0, 5.0, 9.0);
Scalar truth = new Scalar(2.0, 5.0, 5.0, 9.0);
assertEquals(truth, dstScalar);
}
public void testSet() {
double[] vals = { 1.0, 1.0, 1.0, 1.0 };
s1.set(vals);
assertEquals(s2, s1);
}
public void testToString() {
String actual = s2.toString();
String expected = "[1.0, 1.0, 1.0, 1.0]";
assertEquals(expected, actual);
}
}

View File

@ -0,0 +1,93 @@
package org.opencv.test.core;
import org.opencv.core.Point;
import org.opencv.core.Size;
import org.opencv.test.OpenCVTestCase;
public class SizeTest extends OpenCVTestCase {
Size dstSize;
Size sz1;
Size sz2;
@Override
protected void setUp() throws Exception {
super.setUp();
sz1 = new Size(10.0, 10.0);
sz2 = new Size(-1, -1);
dstSize = null;
}
public void testArea() {
double area = sz1.area();
assertEquals(100.0, area);
}
public void testClone() {
dstSize = sz1.clone();
assertEquals(sz1, dstSize);
}
public void testEqualsObject() {
assertFalse(sz1.equals(sz2));
sz2 = sz1.clone();
assertTrue(sz1.equals(sz2));
}
public void testHashCode() {
assertEquals(sz1.hashCode(), sz1.hashCode());
}
public void testSet() {
double[] vals1 = {};
sz2.set(vals1);
assertEquals(0., sz2.width);
assertEquals(0., sz2.height);
double[] vals2 = { 9, 12 };
sz1.set(vals2);
assertEquals(9., sz1.width);
assertEquals(12., sz1.height);
}
public void testSize() {
dstSize = new Size();
assertNotNull(dstSize);
assertEquals(0., dstSize.width);
assertEquals(0., dstSize.height);
}
public void testSizeDoubleArray() {
double[] vals = { 10, 20 };
sz2 = new Size(vals);
assertEquals(10., sz2.width);
assertEquals(20., sz2.height);
}
public void testSizeDoubleDouble() {
assertNotNull(sz1);
assertEquals(10.0, sz1.width);
assertEquals(10.0, sz1.height);
}
public void testSizePoint() {
Point p = new Point(2, 4);
sz1 = new Size(p);
assertNotNull(sz1);
assertEquals(2.0, sz1.width);
assertEquals(4.0, sz1.height);
}
public void testToString() {
String actual = sz1.toString();
String expected = "10x10";
assertEquals(expected, actual);
}
}

View File

@ -0,0 +1,86 @@
package org.opencv.test.core;
import org.opencv.core.TermCriteria;
import org.opencv.test.OpenCVTestCase;
public class TermCriteriaTest extends OpenCVTestCase {
private TermCriteria tc1;
private TermCriteria tc2;
@Override
protected void setUp() throws Exception {
super.setUp();
tc1 = new TermCriteria();
tc2 = new TermCriteria(2, 4, EPS);
}
public void testClone() {
tc1 = tc2.clone();
assertEquals(tc2, tc1);
}
public void testEqualsObject() {
assertFalse(tc2.equals(tc1));
tc1 = tc2.clone();
assertTrue(tc2.equals(tc1));
}
public void testHashCode() {
assertEquals(tc2.hashCode(), tc2.hashCode());
}
public void testSet() {
double[] vals1 = {};
tc1.set(vals1);
assertEquals(0, tc1.type);
assertEquals(0, tc1.maxCount);
assertEquals(0.0, tc1.epsilon);
double[] vals2 = { 9, 8, 0.002 };
tc2.set(vals2);
assertEquals(9, tc2.type);
assertEquals(8, tc2.maxCount);
assertEquals(0.002, tc2.epsilon);
}
public void testTermCriteria() {
tc1 = new TermCriteria();
assertNotNull(tc1);
assertEquals(0, tc1.type);
assertEquals(0, tc1.maxCount);
assertEquals(0.0, tc1.epsilon);
}
public void testTermCriteriaDoubleArray() {
double[] vals = { 3, 2, 0.007 };
tc1 = new TermCriteria(vals);
assertEquals(3, tc1.type);
assertEquals(2, tc1.maxCount);
assertEquals(0.007, tc1.epsilon);
}
public void testTermCriteriaIntIntDouble() {
tc1 = new TermCriteria(2, 4, EPS);
assertNotNull(tc2);
assertEquals(2, tc2.type);
assertEquals(4, tc2.maxCount);
assertEquals(EPS, tc2.epsilon);
}
public void testToString() {
String actual = tc2.toString();
double eps = EPS;
String expected = "{ type: 2, maxCount: 4, epsilon: " + eps + "}";
assertEquals(expected, actual);
}
}

View File

@ -0,0 +1,16 @@
//
// ArrayUtil.h
//
// Created by Giles Payne on 2020/02/09.
//
#pragma once
#import <Foundation/Foundation.h>
/**
* Utility function to create and populate an NSMutableArray with a specific size
* @param size Size of array to create
* @param val Value with which to initialize array elements
*/
NSMutableArray* createArrayWithSize(int size, NSObject* val);

View File

@ -0,0 +1,15 @@
//
// ArrayUtil.mm
//
// Created by Giles Payne on 2020/02/09.
//
#import "ArrayUtil.h"
NSMutableArray* createArrayWithSize(int size, NSObject* val) {
NSMutableArray *array = [NSMutableArray arrayWithCapacity:size];
for (int i = 0; i < size; i++){
[array addObject:val];
}
return array;
}

View File

@ -0,0 +1,89 @@
//
// ByteVector.h
//
// Created by Giles Payne on 2020/01/04.
//
#pragma once
#import <Foundation/Foundation.h>
#ifdef __cplusplus
#import <vector>
#endif
#import "CVObjcUtil.h"
NS_ASSUME_NONNULL_BEGIN
/**
* Utility class to wrap a `std::vector<char>`
*/
CV_EXPORTS @interface ByteVector : NSObject
#pragma mark - Constructors
/**
* Create ByteVector and initialize with the contents of an NSData object
* @param data NSData containing raw byte array
*/
-(instancetype)initWithData:(NSData*)data;
/**
* Create ByteVector and initialize with the contents of another ByteVector object
* @param src ByteVector containing data to copy
*/
-(instancetype)initWithVector:(ByteVector*)src;
#ifdef __OBJC__
/**
* Create ByteVector from raw C array
* @param array The raw C array
* @elements elements The number of elements in the array
*/
-(instancetype)initWithNativeArray:(char*)array elements:(NSInteger)elements;
#endif
#ifdef __cplusplus
/**
* Create ByteVector from std::vector<char>
* @param src The std::vector<char> object to wrap
*/
-(instancetype)initWithStdVector:(std::vector<char>&)src;
+(instancetype)fromNative:(std::vector<char>&)src;
#endif
#pragma mark - Properties
/**
* Length of the vector
*/
@property(readonly) NSInteger length;
#ifdef __OBJC__
/**
* Raw C array
*/
@property(readonly) char* nativeArray;
#endif
#ifdef __cplusplus
/**
* The wrapped std::vector<char> object
*/
@property(readonly) std::vector<char>& nativeRef;
#endif
/**
* NSData object containing the raw byte data
*/
@property(readonly) NSData* data;
#pragma mark - Accessor method
/**
* Return array element
* @param index Index of the array element to return
*/
-(char)get:(NSInteger)index;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,76 @@
//
// ByteVector.m
//
// Created by Giles Payne on 2020/01/04.
//
#import "ByteVector.h"
#import <vector>
@implementation ByteVector {
std::vector<char> v;
}
-(instancetype)initWithData:(NSData*)data {
self = [super init];
if (self) {
if (data.length % sizeof(char) != 0) {
@throw [NSException exceptionWithName:NSInvalidArgumentException reason:@"Invalid data length" userInfo:nil];
}
v.insert(v.begin(), (char*)data.bytes, (char*)data.bytes + data.length/sizeof(char));
}
return self;
}
-(instancetype)initWithVector:(ByteVector*)src {
self = [super init];
if (self) {
v.insert(v.begin(), src.nativeRef.begin(), src.nativeRef.end());
}
return self;
}
-(NSInteger)length {
return v.size();
}
-(char*)nativeArray {
return (char*)v.data();
}
-(instancetype)initWithNativeArray:(char*)array elements:(NSInteger)elements {
self = [super init];
if (self) {
v.insert(v.begin(), array, array + elements);
}
return self;
}
- (std::vector<char>&)nativeRef {
return v;
}
-(instancetype)initWithStdVector:(std::vector<char>&)src {
self = [super init];
if (self) {
v.insert(v.begin(), src.begin(), src.end());
}
return self;
}
+(instancetype)fromNative:(std::vector<char>&)src {
return [[ByteVector alloc] initWithStdVector:src];
}
-(char)get:(NSInteger)index {
if (index < 0 || index >= (long)v.size()) {
@throw [NSException exceptionWithName:NSRangeException reason:@"Invalid data length" userInfo:nil];
}
return v[index];
}
-(NSData*)data {
return [NSData dataWithBytesNoCopy:v.data() length:(v.size() * sizeof(char)) freeWhenDone:NO];
}
@end

View File

@ -0,0 +1,66 @@
//
// ByteVectorExt.swift
//
// Created by Giles Payne on 2020/01/04.
//
import Foundation
public extension ByteVector {
convenience init(_ array:[Int8]) {
let data = array.withUnsafeBufferPointer { Data(buffer: $0) }
self.init(data:data);
}
convenience init(_ array:[UInt8]) {
let data = array.withUnsafeBufferPointer { Data(buffer: $0) }
self.init(data:data);
}
subscript(index: Int) -> Int8 {
get {
return self.get(index)
}
}
var array: [Int8] {
get {
var ret = Array<Int8>(repeating: 0, count: data.count/MemoryLayout<Int8>.stride)
_ = ret.withUnsafeMutableBytes { data.copyBytes(to: $0) }
return ret
}
}
var unsignedArray: [UInt8] {
get {
var ret = Array<UInt8>(repeating: 0, count: data.count/MemoryLayout<UInt8>.stride)
_ = ret.withUnsafeMutableBytes { data.copyBytes(to: $0) }
return ret
}
}
}
extension ByteVector : Sequence {
public typealias Iterator = ByteVectorIterator
public func makeIterator() -> ByteVectorIterator {
return ByteVectorIterator(self)
}
}
public struct ByteVectorIterator: IteratorProtocol {
public typealias Element = Int8
let byteVector: ByteVector
var pos = 0
init(_ byteVector: ByteVector) {
self.byteVector = byteVector
}
mutating public func next() -> Int8? {
guard pos >= 0 && pos < byteVector.length
else { return nil }
pos += 1
return byteVector.get(pos - 1)
}
}

View File

@ -0,0 +1,85 @@
//
// CVObjcUtil.h
//
// Created by Giles Payne on 2020/01/02.
//
#pragma once
#ifndef CV_EXPORTS
#ifdef __cplusplus
#define CV_EXPORTS __attribute__ ((visibility ("default")))
#else
#define CV_EXPORTS
#endif
#endif
#ifdef __cplusplus
#import <vector>
template <typename CV, typename OBJC> std::vector<CV> objc2cv(NSArray<OBJC*>* _Nonnull array, CV& (* _Nonnull converter)(OBJC* _Nonnull)) {
std::vector<CV> ret;
for (OBJC* obj in array) {
ret.push_back(converter(obj));
}
return ret;
}
#define OBJC2CV(CV_CLASS, OBJC_CLASS, v, a) \
std::vector<CV_CLASS> v = objc2cv<CV_CLASS, OBJC_CLASS>(a, [](OBJC_CLASS* objc) -> CV_CLASS& { return objc.nativeRef; })
#define OBJC2CV_CUSTOM(CV_CLASS, OBJC_CLASS, v, a, CONV) \
std::vector<CV_CLASS> v; \
for (OBJC_CLASS* obj in a) { \
CV_CLASS tmp = CONV(obj); \
v.push_back(tmp); \
}
template <typename CV, typename OBJC> void cv2objc(std::vector<CV>& vector, NSMutableArray<OBJC*>* _Nonnull array, OBJC* _Nonnull (* _Nonnull converter)(CV&)) {
[array removeAllObjects];
for (size_t index = 0; index < vector.size(); index++) {
[array addObject:converter(vector[index])];
}
}
#define CV2OBJC(CV_CLASS, OBJC_CLASS, v, a) \
cv2objc<CV_CLASS, OBJC_CLASS>(v, a, [](CV_CLASS& cv) -> OBJC_CLASS* { return [OBJC_CLASS fromNative:cv]; })
#define CV2OBJC_CUSTOM(CV_CLASS, OBJC_CLASS, v, a, UNCONV) \
[a removeAllObjects]; \
for (size_t index = 0; index < v.size(); index++) { \
OBJC_CLASS *tmp = UNCONV(v[index]); \
[a addObject:tmp]; \
}
template <typename CV, typename OBJC> std::vector<std::vector<CV>> objc2cv2(NSArray<NSArray<OBJC*>*>* _Nonnull array, CV& (* _Nonnull converter)(OBJC* _Nonnull)) {
std::vector<std::vector<CV>> ret;
for (NSArray<OBJC*>* innerArray in array) {
std::vector<CV> innerVector;
for (OBJC* obj in innerArray) {
innerVector.push_back(converter(obj));
}
ret.push_back(innerVector);
}
return ret;
}
#define OBJC2CV2(CV_CLASS, OBJC_CLASS, v, a) \
std::vector<std::vector<CV_CLASS>> v = objc2cv2<CV_CLASS, OBJC_CLASS>(a, [](OBJC_CLASS* objc) -> CV_CLASS& { return objc.nativeRef; })
template <typename CV, typename OBJC> void cv2objc2(std::vector<std::vector<CV>>& vector, NSMutableArray<NSMutableArray<OBJC*>*>* _Nonnull array, OBJC* _Nonnull (* _Nonnull converter)(CV&)) {
[array removeAllObjects];
for (size_t index = 0; index < vector.size(); index++) {
std::vector<CV>& innerVector = vector[index];
NSMutableArray<OBJC*>* innerArray = [NSMutableArray arrayWithCapacity:innerVector.size()];
for (size_t index2 = 0; index2 < innerVector.size(); index2++) {
[innerArray addObject:converter(innerVector[index2])];
}
[array addObject:innerArray];
}
}
#define CV2OBJC2(CV_CLASS, OBJC_CLASS, v, a) \
cv2objc2<CV_CLASS, OBJC_CLASS>(v, a, [](CV_CLASS& cv) -> OBJC_CLASS* { return [OBJC_CLASS fromNative:cv]; })
#endif

View File

@ -0,0 +1,100 @@
//
// Converters.h
//
// Created by Giles Payne on 2020/03/03.
//
#pragma once
#ifdef __cplusplus
#import <opencv2/core.hpp>
#else
#define CV_EXPORTS
#endif
#import <Foundation/Foundation.h>
#import "Mat.h"
#import "CvType.h"
#import "Point2i.h"
#import "Point2f.h"
#import "Point2d.h"
#import "Point3i.h"
#import "Point3f.h"
#import "Point3d.h"
#import "Rect2i.h"
#import "Rect2d.h"
#import "KeyPoint.h"
#import "DMatch.h"
#import "RotatedRect.h"
NS_ASSUME_NONNULL_BEGIN
CV_EXPORTS @interface Converters : NSObject
+ (Mat*)vector_Point_to_Mat:(NSArray<Point2i*>*)pts NS_SWIFT_NAME(vector_Point_to_Mat(_:));
+ (NSArray<Point2i*>*)Mat_to_vector_Point:(Mat*)mat NS_SWIFT_NAME(Mat_to_vector_Point(_:));
+ (Mat*)vector_Point2f_to_Mat:(NSArray<Point2f*>*)pts NS_SWIFT_NAME(vector_Point2f_to_Mat(_:));
+ (NSArray<Point2f*>*)Mat_to_vector_Point2f:(Mat*)mat NS_SWIFT_NAME(Mat_to_vector_Point2f(_:));
+ (Mat*)vector_Point2d_to_Mat:(NSArray<Point2d*>*)pts NS_SWIFT_NAME(vector_Point2d_to_Mat(_:));
+ (NSArray<Point2d*>*)Mat_to_vector_Point2d:(Mat*)mat NS_SWIFT_NAME(Mat_to_vector_Point2d(_:));
+ (Mat*)vector_Point3i_to_Mat:(NSArray<Point3i*>*)pts NS_SWIFT_NAME(vector_Point3i_to_Mat(_:));
+ (NSArray<Point3i*>*)Mat_to_vector_Point3i:(Mat*)mat NS_SWIFT_NAME(Mat_to_vector_Point3i(_:));
+ (Mat*)vector_Point3f_to_Mat:(NSArray<Point3f*>*)pts NS_SWIFT_NAME(vector_Point3f_to_Mat(_:));
+ (NSArray<Point3f*>*)Mat_to_vector_Point3f:(Mat*)mat NS_SWIFT_NAME(Mat_to_vector_Point3f(_:));
+ (Mat*)vector_Point3d_to_Mat:(NSArray<Point3d*>*)pts NS_SWIFT_NAME(vector_Point3d_to_Mat(_:));
+ (NSArray<Point3d*>*)Mat_to_vector_Point3d:(Mat*)mat NS_SWIFT_NAME(Mat_to_vector_Point3d(_:));
+ (Mat*)vector_float_to_Mat:(NSArray<NSNumber*>*)fs NS_SWIFT_NAME(vector_float_to_Mat(_:));
+ (NSArray<NSNumber*>*)Mat_to_vector_float:(Mat*)mat NS_SWIFT_NAME(Mat_to_vector_float(_:));
+ (Mat*)vector_uchar_to_Mat:(NSArray<NSNumber*>*)us NS_SWIFT_NAME(vector_uchar_to_Mat(_:));
+ (NSArray<NSNumber*>*)Mat_to_vector_uchar:(Mat*)mat NS_SWIFT_NAME(Mat_to_vector_uchar(_:));
+ (Mat*)vector_char_to_Mat:(NSArray<NSNumber*>*)cs NS_SWIFT_NAME(vector_char_to_Mat(_:));
+ (NSArray<NSNumber*>*)Mat_to_vector_char:(Mat*)mat NS_SWIFT_NAME(Mat_to_vector_char(_:));
+ (Mat*)vector_int_to_Mat:(NSArray<NSNumber*>*)is NS_SWIFT_NAME(vector_int_to_Mat(_:));
+ (NSArray<NSNumber*>*)Mat_to_vector_int:(Mat*)mat NS_SWIFT_NAME(Mat_to_vector_int(_:));
+ (Mat*)vector_Rect_to_Mat:(NSArray<Rect2i*>*)rs NS_SWIFT_NAME(vector_Rect_to_Mat(_:));
+ (NSArray<Rect2i*>*)Mat_to_vector_Rect:(Mat*)mat NS_SWIFT_NAME(Mat_to_vector_Rect(_:));
+ (Mat*)vector_Rect2d_to_Mat:(NSArray<Rect2d*>*)rs NS_SWIFT_NAME(vector_Rect2d_to_Mat(_:));
+ (NSArray<Rect2d*>*)Mat_to_vector_Rect2d:(Mat*)mat NS_SWIFT_NAME(Mat_to_vector_Rect2d(_:));
+ (Mat*)vector_KeyPoint_to_Mat:(NSArray<KeyPoint*>*)kps NS_SWIFT_NAME(vector_KeyPoint_to_Mat(_:));
+ (NSArray<KeyPoint*>*)Mat_to_vector_KeyPoint:(Mat*)mat NS_SWIFT_NAME(Mat_to_vector_KeyPoint(_:));
+ (Mat*)vector_double_to_Mat:(NSArray<NSNumber*>*)ds NS_SWIFT_NAME(vector_double_to_Mat(_:));
+ (NSArray<NSNumber*>*)Mat_to_vector_double:(Mat*)mat NS_SWIFT_NAME(Mat_to_vector_double(_:));
+ (Mat*)vector_DMatch_to_Mat:(NSArray<DMatch*>*)matches NS_SWIFT_NAME(vector_DMatch_to_Mat(_:));
+ (NSArray<DMatch*>*)Mat_to_vector_DMatch:(Mat*)mat NS_SWIFT_NAME(Mat_to_vector_DMatch(_:));
+ (Mat*)vector_RotatedRect_to_Mat:(NSArray<RotatedRect*>*)rs NS_SWIFT_NAME(vector_RotatedRect_to_Mat(_:));
+ (NSArray<RotatedRect*>*)Mat_to_vector_RotatedRect:(Mat*)mat NS_SWIFT_NAME(Mat_to_vector_RotatedRect(_:));
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,205 @@
//
// Converters.mm
//
// Created by Giles Payne on 31/05/2020.
//
#import "Converters.h"
#import "ArrayUtil.h"
#import "MatOfPoint2i.h"
#import "MatOfPoint2f.h"
#import "MatOfPoint3.h"
#import "MatOfPoint3f.h"
#import "MatOfFloat.h"
#import "MatOfByte.h"
#import "MatOfInt.h"
#import "MatOfDouble.h"
#import "MatOfRect2i.h"
#import "MatOfRect2d.h"
#import "MatOfKeyPoint.h"
#import "MatOfDMatch.h"
#import "MatOfRotatedRect.h"
@implementation Converters
+ (Mat*)vector_Point_to_Mat:(NSArray<Point2i*>*)pts {
return [[MatOfPoint2i alloc] initWithArray:pts];
}
+ (NSArray<Point2i*>*)Mat_to_vector_Point:(Mat*)mat {
return [[[MatOfPoint2i alloc] initWithMat:mat] toArray];
}
+ (Mat*)vector_Point2f_to_Mat:(NSArray<Point2f*>*)pts {
return [[MatOfPoint2f alloc] initWithArray:pts];
}
+ (NSArray<Point2f*>*)Mat_to_vector_Point2f:(Mat*)mat {
return [[[MatOfPoint2f alloc] initWithMat:mat] toArray];
}
+ (Mat*)vector_Point2d_to_Mat:(NSArray<Point2d*>*)pts {
Mat* res = [[Mat alloc] initWithRows:(int)pts.count cols:1 type:CV_64FC2];
NSMutableArray<NSNumber*>* buff = [NSMutableArray arrayWithCapacity:pts.count*2];
for (Point2d* pt in pts) {
[buff addObject:[NSNumber numberWithDouble:pt.x]];
[buff addObject:[NSNumber numberWithDouble:pt.y]];
}
[res put:0 col:0 data:buff];
return res;
}
+ (NSArray<Point2d*>*)Mat_to_vector_Point2d:(Mat*)mat {
if (mat.cols != 1 || mat.type != CV_64FC2) {
NSException* exception = [NSException
exceptionWithName:@"UnsupportedOperationException"
reason:[NSString stringWithFormat:@"Invalid Mat. Mat must be of type CV_64FC2 and have 1 column."]
userInfo:nil];
@throw exception;
}
NSMutableArray<Point2d*>* ret = [NSMutableArray new];
NSMutableArray<NSNumber*>* buff = createArrayWithSize(mat.rows*2, [NSNumber numberWithInt:0]);
[mat get:0 col:0 data:buff];
for (int i = 0; i < mat.rows; i++) {
[ret addObject:[[Point2d alloc] initWithX:buff[i * 2].doubleValue y:buff[i * 2 + 1].doubleValue]];
}
return ret;
}
+ (Mat*)vector_Point3i_to_Mat:(NSArray<Point3i*>*)pts {
return [[MatOfPoint3 alloc] initWithArray:pts];
}
+ (NSArray<Point3i*>*)Mat_to_vector_Point3i:(Mat*)mat {
return [[[MatOfPoint3 alloc] initWithMat:mat] toArray];
}
+ (Mat*)vector_Point3f_to_Mat:(NSArray<Point3f*>*)pts {
return [[MatOfPoint3f alloc] initWithArray:pts];
}
+ (NSArray<Point3f*>*)Mat_to_vector_Point3f:(Mat*)mat {
return [[[MatOfPoint3f alloc] initWithMat:mat] toArray];
}
+ (Mat*)vector_Point3d_to_Mat:(NSArray<Point3d*>*)pts {
Mat* res = [[Mat alloc] initWithRows:(int)pts.count cols:1 type:CV_64FC3];
NSMutableArray<NSNumber*>* buff = [NSMutableArray arrayWithCapacity:pts.count*3];
for (Point3d* pt in pts) {
[buff addObject:[NSNumber numberWithDouble:pt.x]];
[buff addObject:[NSNumber numberWithDouble:pt.y]];
[buff addObject:[NSNumber numberWithDouble:pt.z]];
}
[res put:0 col:0 data:buff];
return res;
}
+ (NSArray<Point3d*>*)Mat_to_vector_Point3d:(Mat*)mat {
if (mat.cols != 1 || mat.type != CV_64FC3) {
NSException* exception = [NSException
exceptionWithName:@"UnsupportedOperationException"
reason:[NSString stringWithFormat:@"Invalid Mat. Mat must be of type CV_64FC3 and have 1 column."]
userInfo:nil];
@throw exception;
}
NSMutableArray<Point3d*>* ret = [NSMutableArray new];
NSMutableArray<NSNumber*>* buff = createArrayWithSize(mat.rows*3, [NSNumber numberWithInt:0]);
[mat get:0 col:0 data:buff];
for (int i = 0; i < mat.rows; i++) {
[ret addObject:[[Point3d alloc] initWithX:buff[i * 3].doubleValue y:buff[i * 3 + 1].doubleValue z:buff[i * 3 + 2].doubleValue]];
}
return ret;
}
+ (Mat*)vector_float_to_Mat:(NSArray<NSNumber*>*)fs {
return [[MatOfFloat alloc] initWithArray:fs];
}
+ (NSArray<NSNumber*>*)Mat_to_vector_float:(Mat*)mat {
return [[[MatOfFloat alloc] initWithMat:mat] toArray];
}
+ (Mat*)vector_uchar_to_Mat:(NSArray<NSNumber*>*)us {
return [[MatOfByte alloc] initWithArray:us];
}
+ (NSArray<NSNumber*>*)Mat_to_vector_uchar:(Mat*)mat {
return [[[MatOfByte alloc] initWithMat:mat] toArray];
}
+ (Mat*)vector_char_to_Mat:(NSArray<NSNumber*>*)cs {
Mat* res = [[Mat alloc] initWithRows:(int)cs.count cols:1 type:CV_8S];
[res put:0 col:0 data:cs];
return res;
}
+ (NSArray<NSNumber*>*)Mat_to_vector_char:(Mat*)mat {
if (mat.cols != 1 || mat.type != CV_8S) {
NSException* exception = [NSException
exceptionWithName:@"UnsupportedOperationException"
reason:[NSString stringWithFormat:@"Invalid Mat. Mat must be of type CV_8S and have 1 column."]
userInfo:nil];
@throw exception;
}
NSMutableArray<NSNumber*>* ret = createArrayWithSize(mat.rows, @0);
[mat get:0 col:0 data:ret];
return ret;
}
+ (Mat*)vector_int_to_Mat:(NSArray<NSNumber*>*)is {
return [[MatOfInt alloc] initWithArray:is];
}
+ (NSArray<NSNumber*>*)Mat_to_vector_int:(Mat*)mat {
return [[[MatOfInt alloc] initWithMat:mat] toArray];
}
+ (Mat*)vector_Rect_to_Mat:(NSArray<Rect2i*>*)rs {
return [[MatOfRect2i alloc] initWithArray:rs];
}
+ (NSArray<Rect2i*>*)Mat_to_vector_Rect:(Mat*)mat {
return [[[MatOfRect2i alloc] initWithMat:mat] toArray];
}
+ (Mat*)vector_Rect2d_to_Mat:(NSArray<Rect2d*>*)rs {
return [[MatOfRect2d alloc] initWithArray:rs];
}
+ (NSArray<Rect2d*>*)Mat_to_vector_Rect2d:(Mat*)mat {
return [[[MatOfRect2d alloc] initWithMat:mat] toArray];
}
+ (Mat*)vector_KeyPoint_to_Mat:(NSArray<KeyPoint*>*)kps {
return [[MatOfKeyPoint alloc] initWithArray:kps];
}
+ (NSArray<KeyPoint*>*)Mat_to_vector_KeyPoint:(Mat*)mat {
return [[[MatOfKeyPoint alloc] initWithMat:mat] toArray];
}
+ (Mat*)vector_double_to_Mat:(NSArray<NSNumber*>*)ds {
return [[MatOfDouble alloc] initWithArray:ds];
}
+ (NSArray<NSNumber*>*)Mat_to_vector_double:(Mat*)mat {
return [[[MatOfDouble alloc] initWithMat:mat] toArray];
}
+ (Mat*)vector_DMatch_to_Mat:(NSArray<DMatch*>*)matches {
return [[MatOfDMatch alloc] initWithArray:matches];
}
+ (NSArray<DMatch*>*)Mat_to_vector_DMatch:(Mat*)mat {
return [[[MatOfDMatch alloc] initWithMat:mat] toArray];
}
+ (Mat*)vector_RotatedRect_to_Mat:(NSArray<RotatedRect*>*)rs {
return [[MatOfRotatedRect alloc] initWithArray:rs];
}
+ (NSArray<RotatedRect*>*)Mat_to_vector_RotatedRect:(Mat*)mat {
return [[[MatOfRotatedRect alloc] initWithMat:mat] toArray];
}
@end

View File

@ -0,0 +1,69 @@
//
// CvType.h
//
// Created by Giles Payne on 2019/10/13.
//
#ifdef __cplusplus
#import "opencv2/core.hpp"
#else
#define CV_EXPORTS
#endif
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/**
* Utility functions for handling CvType values
*/
CV_EXPORTS @interface CvType : NSObject
#pragma mark - Type Utility functions
/**
* Create CvType value from depth and channel values
* @param depth Depth value. One of CV_8U, CV_8S, CV_16U, CV_16S, CV_32S, CV_32F or CV_64F
* @param channels Number of channels (from 1 to (CV_CN_MAX - 1))
*/
+ (int)makeType:(int)depth channels:(int)channels;
/**
* Get number of channels for type
* @param type Type value
*/
+ (int)channels:(int)type;
/**
* Get depth for type
* @param type Type value
*/
+ (int)depth:(int)type;
/**
* Get raw type size in bytes for type
* @param type Type value
*/
+ (int)rawTypeSize:(int)type;
/**
* Returns true if the raw type is an integer type (if depth is CV_8U, CV_8S, CV_16U, CV_16S or CV_32S)
* @param type Type value
*/
+ (BOOL)isInteger:(int)type;
/**
* Get element size in bytes for type
* @param type Type value
*/
+ (int)ELEM_SIZE:(int)type NS_SWIFT_NAME(elemSize(_:));
/**
* Get the string name for type
* @param type Type value
*/
+ (NSString*)typeToString:(int)type;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,105 @@
//
// CvType.m
//
// Created by Giles Payne on 2019/10/13.
//
#import "CvType.h"
@implementation CvType
+ (int)makeType:(int)depth channels:(int)channels {
if (channels <= 0 || channels >= CV_CN_MAX) {
NSException* exception = [NSException
exceptionWithName:@"UnsupportedOperationException"
reason:[NSString stringWithFormat:@"Channels count should be 1..%d", CV_CN_MAX - 1]
userInfo:nil];
@throw exception;
}
if (depth < 0 || depth >= CV_DEPTH_MAX) {
NSException* exception = [NSException
exceptionWithName:@"UnsupportedOperationException"
reason:[NSString stringWithFormat:@"Data type depth should be 0..%d", CV_DEPTH_MAX - 1]
userInfo:nil];
@throw exception;
}
return (depth & (CV_DEPTH_MAX - 1)) + ((channels - 1) << CV_CN_SHIFT);
}
+ (int)channels:(int)type {
return (type >> CV_CN_SHIFT) + 1;
}
+ (int)depth:(int)type {
return type & (CV_DEPTH_MAX - 1);
}
+ (BOOL)isInteger:(int)type {
return [CvType depth:type] < CV_32F;
}
+ (int)typeSizeBits:(int)type {
int depth = [CvType depth:type];
switch (depth) {
case CV_8U:
case CV_8S:
return 8;
case CV_16U:
case CV_16S:
case CV_16F:
return 16;
case CV_32S:
case CV_32F:
return 32;
case CV_64F:
return 64;
default:
NSException* exception = [NSException
exceptionWithName:@"UnsupportedOperationException"
reason:[NSString stringWithFormat:@"Unsupported CvType value: %d", type]
userInfo:nil];
@throw exception;
}
}
+ (int)rawTypeSize:(int)type {
return [CvType typeSizeBits:type] >> 3;
}
+ (char)typeMnenomic:(int)type {
int depth = [CvType depth:type];
switch (depth) {
case CV_8U:
case CV_16U:
return 'U';
case CV_8S:
case CV_16S:
case CV_32S:
return 'S';
case CV_16F:
case CV_32F:
case CV_64F:
return 'F';
default:
NSException* exception = [NSException
exceptionWithName:@"UnsupportedOperationException"
reason:[NSString stringWithFormat:@"Unsupported CvType value: %d", type]
userInfo:nil];
@throw exception;
}
}
+ (int)ELEM_SIZE:(int)type {
int typeSizeBytes = [CvType rawTypeSize:type];
return typeSizeBytes * [CvType channels:type];
}
+ (NSString*)typeToString:(int)type {
int typeSizeBits = [CvType typeSizeBits:type];
char typeMnenomic = [CvType typeMnenomic:type];
int channels = [CvType channels:type];
NSString* channelsSuffix = [NSString stringWithFormat:(channels <= 4)?@"%d":@"(%d)", channels];
return [NSString stringWithFormat:@"CV_%d%cC%@", typeSizeBits, typeMnenomic, channelsSuffix];
}
@end

View File

@ -0,0 +1,90 @@
//
// CvTypeExt.swift
//
// Created by Giles Payne on 2020/01/19.
//
import Foundation
public extension CvType {
static let CV_8U: Int32 = 0
static let CV_8S: Int32 = 1
static let CV_16U: Int32 = 2
static let CV_16S: Int32 = 3
static let CV_32S: Int32 = 4
static let CV_32F: Int32 = 5
static let CV_64F: Int32 = 6
static let CV_16F: Int32 = 7
static let CV_8UC1: Int32 = CV_8UC(1)
static let CV_8UC2: Int32 = CV_8UC(2)
static let CV_8UC3: Int32 = CV_8UC(3)
static let CV_8UC4: Int32 = CV_8UC(4)
static let CV_8SC1: Int32 = CV_8SC(1)
static let CV_8SC2: Int32 = CV_8SC(2)
static let CV_8SC3: Int32 = CV_8SC(3)
static let CV_8SC4: Int32 = CV_8SC(4)
static let CV_16UC1: Int32 = CV_16UC(1)
static let CV_16UC2: Int32 = CV_16UC(2)
static let CV_16UC3: Int32 = CV_16UC(3)
static let CV_16UC4: Int32 = CV_16UC(4)
static let CV_16SC1: Int32 = CV_16SC(1)
static let CV_16SC2: Int32 = CV_16SC(2)
static let CV_16SC3: Int32 = CV_16SC(3)
static let CV_16SC4: Int32 = CV_16SC(4)
static let CV_32SC1: Int32 = CV_32SC(1)
static let CV_32SC2: Int32 = CV_32SC(2)
static let CV_32SC3: Int32 = CV_32SC(3)
static let CV_32SC4: Int32 = CV_32SC(4)
static let CV_32FC1: Int32 = CV_32FC(1)
static let CV_32FC2: Int32 = CV_32FC(2)
static let CV_32FC3: Int32 = CV_32FC(3)
static let CV_32FC4: Int32 = CV_32FC(4)
static let CV_64FC1: Int32 = CV_64FC(1)
static let CV_64FC2: Int32 = CV_64FC(2)
static let CV_64FC3: Int32 = CV_64FC(3)
static let CV_64FC4: Int32 = CV_64FC(4)
static let CV_16FC1: Int32 = CV_16FC(1)
static let CV_16FC2: Int32 = CV_16FC(2)
static let CV_16FC3: Int32 = CV_16FC(3)
static let CV_16FC4: Int32 = CV_16FC(4)
static let CV_CN_MAX = 512
static let CV_CN_SHIFT = 3
static let CV_DEPTH_MAX = 1 << CV_CN_SHIFT
static func CV_8UC(_ channels:Int32) -> Int32 {
return make(CV_8U, channels: channels)
}
static func CV_8SC(_ channels:Int32) -> Int32 {
return make(CV_8S, channels: channels)
}
static func CV_16UC(_ channels:Int32) -> Int32 {
return make(CV_16U, channels: channels)
}
static func CV_16SC(_ channels:Int32) -> Int32 {
return make(CV_16S, channels: channels)
}
static func CV_32SC(_ channels:Int32) -> Int32 {
return make(CV_32S, channels: channels)
}
static func CV_32FC(_ channels:Int32) -> Int32 {
return make(CV_32F, channels: channels)
}
static func CV_64FC(_ channels:Int32) -> Int32 {
return make(CV_64F, channels: channels)
}
static func CV_16FC(_ channels:Int32) -> Int32 {
return make(CV_16F, channels: channels)
}
}

View File

@ -0,0 +1,84 @@
//
// DMatch.h
//
// Created by Giles Payne on 2019/12/25.
//
#pragma once
#ifdef __cplusplus
#import "opencv2/core.hpp"
#else
#define CV_EXPORTS
#endif
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/**
* Structure for matching: query descriptor index, train descriptor index, train
* image index and distance between descriptors.
*/
CV_EXPORTS @interface DMatch : NSObject
/**
* Query descriptor index.
*/
@property int queryIdx;
/**
* Train descriptor index.
*/
@property int trainIdx;
/**
* Train image index.
*/
@property int imgIdx;
/**
* Distance
*/
@property float distance;
#ifdef __cplusplus
@property(readonly) cv::DMatch& nativeRef;
#endif
- (instancetype)init;
- (instancetype)initWithQueryIdx:(int)queryIdx trainIdx:(int)trainIdx distance:(float)distance;
- (instancetype)initWithQueryIdx:(int)queryIdx trainIdx:(int)trainIdx imgIdx:(int)imgIdx distance:(float)distance;
#ifdef __cplusplus
+ (instancetype)fromNative:(cv::DMatch&)dMatch;
#endif
/**
* Distance comparison
* @param it DMatch object to compare
*/
- (BOOL)lessThan:(DMatch*)it;
/**
* Clone object
*/
- (DMatch*)clone;
/**
* Compare for equality
* @param other Object to compare
*/
- (BOOL)isEqual:(nullable id)other;
/**
* Calculate hash for this object
*/
- (NSUInteger)hash;
/**
* Returns a string that describes the contents of the object
*/
- (NSString*)description;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,108 @@
//
// DMatch.m
//
// Created by Giles Payne on 2019/12/25.
//
#import "DMatch.h"
@implementation DMatch {
cv::DMatch native;
}
- (int)queryIdx {
return native.queryIdx;
}
- (void)setQueryIdx:(int)queryIdx {
native.queryIdx = queryIdx;
}
- (int)trainIdx {
return native.trainIdx;
}
- (void)setTrainIdx:(int)trainIdx {
native.trainIdx = trainIdx;
}
- (int)imgIdx {
return native.imgIdx;
}
- (void)setImgIdx:(int)imgIdx {
native.imgIdx = imgIdx;
}
- (float)distance {
return native.distance;
}
- (void)setDistance:(float)distance {
native.distance = distance;
}
- (cv::DMatch&)nativeRef {
return native;
}
- (instancetype)init {
return [self initWithQueryIdx:-1 trainIdx:-1 distance:FLT_MAX];
}
- (instancetype)initWithQueryIdx:(int)queryIdx trainIdx:(int)trainIdx distance:(float)distance {
return [self initWithQueryIdx:queryIdx trainIdx:trainIdx imgIdx:-1 distance:distance];
}
- (instancetype)initWithQueryIdx:(int)queryIdx trainIdx:(int)trainIdx imgIdx:(int)imgIdx distance:(float)distance {
self = [super init];
if (self != nil) {
self.queryIdx = queryIdx;
self.trainIdx = trainIdx;
self.imgIdx = imgIdx;
self.distance = distance;
}
return self;
}
+ (instancetype)fromNative:(cv::DMatch&)dMatch {
return [[DMatch alloc] initWithQueryIdx:dMatch.queryIdx trainIdx:dMatch.trainIdx imgIdx:dMatch.imgIdx distance:dMatch.distance];
}
- (BOOL)lessThan:(DMatch*)it {
return self.distance < it.distance;
}
- (DMatch*)clone {
return [[DMatch alloc] initWithQueryIdx:self.queryIdx trainIdx:self.trainIdx imgIdx:self.imgIdx distance:self.distance];
}
- (BOOL)isEqual:(id)other {
if (other == self) {
return YES;
} else if (![other isKindOfClass:[DMatch class]]) {
return NO;
} else {
DMatch* dMatch = (DMatch*)other;
return self.queryIdx == dMatch.queryIdx && self.trainIdx == dMatch.trainIdx && self.imgIdx == dMatch.imgIdx && self.distance == dMatch.distance;
}
}
#define FLOAT_TO_BITS(x) ((Cv32suf){ .f = x }).i
- (NSUInteger)hash {
int prime = 31;
uint32_t result = 1;
result = prime * result + self.queryIdx;
result = prime * result + self.trainIdx;
result = prime * result + self.imgIdx;
result = prime * result + FLOAT_TO_BITS(self.distance);
return result;
}
- (NSString *)description {
return [NSString stringWithFormat:@"DMatch { queryIdx: %d, trainIdx: %d, imgIdx: %d, distance: %f}", self.queryIdx, self.trainIdx, self.imgIdx, self.distance];
}
@end

View File

@ -0,0 +1,90 @@
//
// Double2.h
//
// Created by Giles Payne on 2020/05/22.
//
#pragma once
#ifdef __cplusplus
#import "opencv2/core.hpp"
#else
#define CV_EXPORTS
#endif
#import <Foundation/Foundation.h>
@class Mat;
NS_ASSUME_NONNULL_BEGIN
/**
* Simple wrapper for a vector of two `double`
*/
CV_EXPORTS @interface Double2 : NSObject
#pragma mark - Properties
/**
* First vector element
*/
@property double v0;
/**
* Second vector element
*/
@property double v1;
#ifdef __cplusplus
/**
* The wrapped vector
*/
@property(readonly) cv::Vec2d& nativeRef;
#endif
#pragma mark - Constructors
/**
* Create zero-initialize vecior
*/
-(instancetype)init;
/**
* Create vector with specified element values
* @param v0 First element
* @param v1 Second element
*/
-(instancetype)initWithV0:(double)v0 v1:(double)v1;
/**
* Create vector with specified element values
* @param vals array of element values
*/
-(instancetype)initWithVals:(NSArray<NSNumber*>*)vals;
#ifdef __cplusplus
+(instancetype)fromNative:(cv::Vec2d&)vec2d;
#endif
/**
* Update vector with specified element values
* @param vals array of element values
*/
-(void)set:(NSArray<NSNumber*>*)vals NS_SWIFT_NAME(set(vals:));
/**
* Get vector as an array
*/
-(NSArray<NSNumber*>*)get;
#pragma mark - Common Methods
/**
* Compare for equality
* @param other Object to compare
*/
-(BOOL)isEqual:(nullable id)other;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,75 @@
//
// Double2.mm
//
// Created by Giles Payne on 2020/05/22.
//
#import "Double2.h"
#import "Mat.h"
@implementation Double2 {
cv::Vec2d native;
}
-(double)v0 {
return native[0];
}
-(void)setV0:(double)v {
native[0] = v;
}
-(double)v1 {
return native[1];
}
-(void)setV1:(double)v {
native[1] = v;
}
-(instancetype)init {
return [self initWithV0:0 v1:0];
}
-(instancetype)initWithV0:(double)v0 v1:(double)v1 {
self = [super init];
if (self) {
self.v0 = v0;
self.v1 = v1;
}
return self;
}
-(instancetype)initWithVals:(NSArray<NSNumber*>*)vals {
self = [super init];
if (self) {
[self set:vals];
}
return self;
}
+(instancetype)fromNative:(cv::Vec2d&)vec2d {
return [[Double2 alloc] initWithV0:vec2d[0] v1:vec2d[1]];
}
-(void)set:(NSArray<NSNumber*>*)vals {
self.v0 = (vals != nil && vals.count > 0) ? vals[0].doubleValue : 0;
self.v1 = (vals != nil && vals.count > 1) ? vals[1].doubleValue : 0;
}
-(NSArray<NSNumber*>*)get {
return @[[NSNumber numberWithFloat:native[0]], [NSNumber numberWithFloat:native[1]]];
}
- (BOOL)isEqual:(id)other {
if (other == self) {
return YES;
} else if (![other isKindOfClass:[Double2 class]]) {
return NO;
} else {
Double2* d2 = (Double2*)other;
return self.v0 == d2.v0 && self.v1 == d2.v1;
}
}
@end

View File

@ -0,0 +1,96 @@
//
// Double3.h
//
// Created by Giles Payne on 2020/05/22.
//
#pragma once
#ifdef __cplusplus
#import "opencv2/core.hpp"
#else
#define CV_EXPORTS
#endif
#import <Foundation/Foundation.h>
@class Mat;
NS_ASSUME_NONNULL_BEGIN
/**
* Simple wrapper for a vector of three `double`
*/
CV_EXPORTS @interface Double3 : NSObject
#pragma mark - Properties
/**
* First vector element
*/
@property double v0;
/**
* Second vector element
*/
@property double v1;
/**
* Third vector element
*/
@property double v2;
#ifdef __cplusplus
/**
* The wrapped vector
*/
@property(readonly) cv::Vec3d& nativeRef;
#endif
#pragma mark - Constructors
/**
* Create zero-initialize vecior
*/
-(instancetype)init;
/**
* Create vector with specified element values
* @param v0 First element
* @param v1 Second element
* @param v2 Third element
*/
-(instancetype)initWithV0:(double)v0 v1:(double)v1 v2:(double)v2;
/**
* Create vector with specified element values
* @param vals array of element values
*/
-(instancetype)initWithVals:(NSArray<NSNumber*>*)vals;
#ifdef __cplusplus
+(instancetype)fromNative:(cv::Vec3d&)vec3d;
#endif
/**
* Update vector with specified element values
* @param vals array of element values
*/
-(void)set:(NSArray<NSNumber*>*)vals NS_SWIFT_NAME(set(vals:));
/**
* Get vector as an array
*/
-(NSArray<NSNumber*>*)get;
#pragma mark - Common Methods
/**
* Compare for equality
* @param other Object to compare
*/
-(BOOL)isEqual:(nullable id)other;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,85 @@
//
// Double3.mm
//
// Created by Giles Payne on 2020/05/22.
//
#import "Double3.h"
#import "Mat.h"
@implementation Double3 {
cv::Vec3d native;
}
-(double)v0 {
return native[0];
}
-(void)setV0:(double)v {
native[0] = v;
}
-(double)v1 {
return native[1];
}
-(void)setV1:(double)v {
native[1] = v;
}
-(double)v2 {
return native[2];
}
-(void)setV2:(double)v {
native[2] = v;
}
-(instancetype)init {
return [self initWithV0:0 v1:0 v2:0];
}
-(instancetype)initWithV0:(double)v0 v1:(double)v1 v2:(double)v2 {
self = [super init];
if (self) {
self.v0 = v0;
self.v1 = v1;
self.v2 = v2;
}
return self;
}
-(instancetype)initWithVals:(NSArray<NSNumber*>*)vals {
self = [super init];
if (self) {
[self set:vals];
}
return self;
}
+(instancetype)fromNative:(cv::Vec3d&)vec3d {
return [[Double3 alloc] initWithV0:vec3d[0] v1:vec3d[1] v2:vec3d[2]];
}
-(void)set:(NSArray<NSNumber*>*)vals {
self.v0 = (vals != nil && vals.count > 0) ? vals[0].doubleValue : 0;
self.v1 = (vals != nil && vals.count > 1) ? vals[1].doubleValue : 0;
self.v2 = (vals != nil && vals.count > 2) ? vals[2].doubleValue : 0;
}
-(NSArray<NSNumber*>*)get {
return @[[NSNumber numberWithFloat:native[0]], [NSNumber numberWithFloat:native[1]], [NSNumber numberWithFloat:native[2]]];
}
- (BOOL)isEqual:(id)other {
if (other == self) {
return YES;
} else if (![other isKindOfClass:[Double3 class]]) {
return NO;
} else {
Double3* d3 = (Double3*)other;
return self.v0 == d3.v0 && self.v1 == d3.v1 && self.v2 == d3.v2;
}
}
@end

View File

@ -0,0 +1,89 @@
//
// DoubleVector.h
//
// Created by Giles Payne on 2020/01/04.
//
#pragma once
#import <Foundation/Foundation.h>
#ifdef __cplusplus
#import <vector>
#endif
#import "CVObjcUtil.h"
NS_ASSUME_NONNULL_BEGIN
/**
* Utility class to wrap a `std::vector<double>`
*/
CV_EXPORTS @interface DoubleVector : NSObject
#pragma mark - Constructors
/**
* Create DoubleVector and initialize with the contents of an NSData object
* @param data NSData containing raw double array
*/
-(instancetype)initWithData:(NSData*)data;
/**
* Create DoubleVector and initialize with the contents of another DoubleVector object
* @param src DoubleVector containing data to copy
*/
-(instancetype)initWithVector:(DoubleVector*)src;
#ifdef __OBJC__
/**
* Create DoubleVector from raw C array
* @param array The raw C array
* @elements elements The number of elements in the array
*/
-(instancetype)initWithNativeArray:(double*)array elements:(int)elements;
#endif
#ifdef __cplusplus
/**
* Create DoubleVector from std::vector<double>
* @param src The std::vector<double> object to wrap
*/
-(instancetype)initWithStdVector:(std::vector<double>&)src;
+(instancetype)fromNative:(std::vector<double>&)src;
#endif
#pragma mark - Properties
/**
* Length of the vector
*/
@property(readonly) size_t length;
#ifdef __OBJC__
/**
* Raw C array
*/
@property(readonly) double* nativeArray;
#endif
#ifdef __cplusplus
/**
* The wrapped std::vector<double> object
*/
@property(readonly) std::vector<double>& nativeRef;
#endif
/**
* NSData object containing the raw double data
*/
@property(readonly) NSData* data;
#pragma mark - Accessor method
/**
* Return array element
* @param index Index of the array element to return
*/
-(double)get:(NSInteger)index;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,76 @@
//
// DoubleVector.m
//
// Created by Giles Payne on 2020/01/04.
//
#import "DoubleVector.h"
#import <vector>
@implementation DoubleVector {
std::vector<double> v;
}
-(instancetype)initWithData:(NSData*)data {
self = [super init];
if (self) {
if (data.length % sizeof(double) != 0) {
@throw [NSException exceptionWithName:NSInvalidArgumentException reason:@"Invalid data length" userInfo:nil];
}
v.insert(v.begin(), (double*)data.bytes, (double*)data.bytes + data.length/sizeof(double));
}
return self;
}
-(instancetype)initWithVector:(DoubleVector*)src {
self = [super init];
if (self) {
v.insert(v.begin(), src.nativeRef.begin(), src.nativeRef.end());
}
return self;
}
-(size_t)length {
return v.size();
}
-(double*)nativeArray {
return (double*)v.data();
}
-(instancetype)initWithNativeArray:(double*)array elements:(int)elements {
self = [super init];
if (self) {
v.insert(v.begin(), array, array + elements);
}
return self;
}
- (std::vector<double>&)nativeRef {
return v;
}
-(instancetype)initWithStdVector:(std::vector<double>&)src {
self = [super init];
if (self) {
v.insert(v.begin(), src.begin(), src.end());
}
return self;
}
+(instancetype)fromNative:(std::vector<double>&)src {
return [[DoubleVector alloc] initWithStdVector:src];
}
-(double)get:(NSInteger)index {
if (index < 0 || index >= (long)v.size()) {
@throw [NSException exceptionWithName:NSRangeException reason:@"Invalid data length" userInfo:nil];
}
return v[index];
}
-(NSData*)data {
return [NSData dataWithBytesNoCopy:v.data() length:(v.size() * sizeof(double)) freeWhenDone:NO];
}
@end

View File

@ -0,0 +1,53 @@
//
// DoubleVectorExt.swift
//
// Created by Giles Payne on 2020/01/04.
//
import Foundation
public extension DoubleVector {
convenience init(_ array:[Double]) {
let data = array.withUnsafeBufferPointer { Data(buffer: $0) }
self.init(data:data);
}
subscript(index: Int) -> Double {
get {
return self.get(index)
}
}
var array: [Double] {
get {
var ret = Array<Double>(repeating: 0, count: data.count/MemoryLayout<Double>.stride)
_ = ret.withUnsafeMutableBytes { data.copyBytes(to: $0) }
return ret
}
}
}
extension DoubleVector : Sequence {
public typealias Iterator = DoubleVectorIterator
public func makeIterator() -> DoubleVectorIterator {
return DoubleVectorIterator(self)
}
}
public struct DoubleVectorIterator: IteratorProtocol {
public typealias Element = Double
let doubleVector: DoubleVector
var pos = 0
init(_ doubleVector: DoubleVector) {
self.doubleVector = doubleVector
}
mutating public func next() -> Double? {
guard pos >= 0 && pos < doubleVector.length
else { return nil }
pos += 1
return doubleVector.get(pos - 1)
}
}

View File

@ -0,0 +1,101 @@
//
// Float4.h
//
// Created by Giles Payne on 2020/02/05.
//
#pragma once
#ifdef __cplusplus
#import "opencv2/core.hpp"
#else
#define CV_EXPORTS
#endif
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@class Mat;
/**
* Simple wrapper for a vector of four `float`
*/
CV_EXPORTS @interface Float4 : NSObject
#pragma mark - Properties
/**
* First vector element
*/
@property float v0;
/**
* Second vector element
*/
@property float v1;
/**
* Third vector element
*/
@property float v2;
/**
* Fourth vector element
*/
@property float v3;
#ifdef __cplusplus
/**
* The wrapped vector
*/
@property(readonly) cv::Vec4f& nativeRef;
#endif
#pragma mark - Constructors
/**
* Create zero-initialize vecior
*/
-(instancetype)init;
/**
* Create vector with specified element values
* @param v0 First element
* @param v1 Second element
* @param v2 Third element
* @param v3 Fourth element
*/
-(instancetype)initWithV0:(float)v0 v1:(float)v1 v2:(float)v2 v3:(float)v3;
/**
* Create vector with specified element values
* @param vals array of element values
*/
-(instancetype)initWithVals:(NSArray<NSNumber*>*)vals;
#ifdef __cplusplus
+(instancetype)fromNative:(cv::Vec4f&)vec4f;
#endif
/**
* Update vector with specified element values
* @param vals array of element values
*/
-(void)set:(NSArray<NSNumber*>*)vals NS_SWIFT_NAME(set(vals:));
/**
* Get vector as an array
*/
-(NSArray<NSNumber*>*)get;
#pragma mark - Common Methods
/**
* Compare for equality
* @param other Object to compare
*/
-(BOOL)isEqual:(nullable id)other;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,95 @@
//
// Float4.mm
//
// Created by Giles Payne on 2020/02/05.
//
#import "Float4.h"
#import "Mat.h"
@implementation Float4 {
cv::Vec4f native;
}
-(float)v0 {
return native[0];
}
-(void)setV0:(float)v {
native[0] = v;
}
-(float)v1 {
return native[1];
}
-(void)setV1:(float)v {
native[1] = v;
}
-(float)v2 {
return native[2];
}
-(void)setV2:(float)v {
native[2] = v;
}
-(float)v3 {
return native[3];
}
-(void)setV3:(float)v {
native[3] = v;
}
-(instancetype)init {
return [self initWithV0:0.0 v1:0.0 v2:0.0 v3:0.0];
}
-(instancetype)initWithV0:(float)v0 v1:(float)v1 v2:(float)v2 v3:(float)v3 {
self = [super init];
if (self) {
self.v0 = v0;
self.v1 = v1;
self.v2 = v2;
self.v3 = v3;
}
return self;
}
-(instancetype)initWithVals:(NSArray<NSNumber*>*)vals {
self = [super init];
if (self) {
[self set:vals];
}
return self;
}
+(instancetype)fromNative:(cv::Vec4f&)vec4f {
return [[Float4 alloc] initWithV0:vec4f[0] v1:vec4f[1] v2:vec4f[2] v3:vec4f[3]];
}
-(void)set:(NSArray<NSNumber*>*)vals {
self.v0 = (vals != nil && vals.count > 0) ? vals[0].floatValue : 0;
self.v1 = (vals != nil && vals.count > 1) ? vals[1].floatValue : 0;
self.v2 = (vals != nil && vals.count > 2) ? vals[2].floatValue : 0;
self.v3 = (vals != nil && vals.count > 3) ? vals[3].floatValue : 0;
}
-(NSArray<NSNumber*>*)get {
return @[[NSNumber numberWithFloat:native[0]], [NSNumber numberWithFloat:native[1]], [NSNumber numberWithFloat:native[2]], [NSNumber numberWithFloat:native[3]]];
}
- (BOOL)isEqual:(id)other {
if (other == self) {
return YES;
} else if (![other isKindOfClass:[Float4 class]]) {
return NO;
} else {
Float4* point = (Float4*)other;
return self.v0 == point.v0 && self.v1 == point.v1 && self.v2 == point.v2 && self.v3 == point.v3;
}
}
@end

View File

@ -0,0 +1,114 @@
//
// Float6.h
//
// Created by Giles Payne on 2020/02/05.
//
#pragma once
#ifdef __cplusplus
#import "opencv2/core.hpp"
#else
#define CV_EXPORTS
#endif
#import <Foundation/Foundation.h>
@class Mat;
NS_ASSUME_NONNULL_BEGIN
/**
* Simple wrapper for a vector of six `float`
*/
CV_EXPORTS @interface Float6 : NSObject
#pragma mark - Properties
/**
* First vector element
*/
@property float v0;
/**
* Second vector element
*/
@property float v1;
/**
* Third vector element
*/
@property float v2;
/**
* Fourth vector element
*/
@property float v3;
/**
* Fifth vector element
*/
@property float v4;
/**
* Sixth vector element
*/
@property float v5;
#ifdef __cplusplus
/**
* The wrapped vector
*/
@property(readonly) cv::Vec6f& nativeRef;
#endif
#pragma mark - Constructors
/**
* Create zero-initialize vecior
*/
-(instancetype)init;
/**
* Create vector with specified element values
* @param v0 First element
* @param v1 Second element
* @param v2 Third element
* @param v3 Fourth element
* @param v4 Fifth element
* @param v5 Sixth element
*/
-(instancetype)initWithV0:(float)v0 v1:(float)v1 v2:(float)v2 v3:(float)v3 v4:(float)v4 v5:(float)v5;
/**
* Create vector with specified element values
* @param vals array of element values
*/
-(instancetype)initWithVals:(NSArray<NSNumber*>*)vals;
#ifdef __cplusplus
+(instancetype)fromNative:(cv::Vec6f&)vec6f;
#endif
/**
* Update vector with specified element values
* @param vals array of element values
*/
-(void)set:(NSArray<NSNumber*>*)vals NS_SWIFT_NAME(set(vals:));
/**
* Get vector as an array
*/
-(NSArray<NSNumber*>*)get;
#pragma mark - Common Methods
/**
* Compare for equality
* @param other Object to compare
*/
-(BOOL)isEqual:(nullable id)other;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,115 @@
//
// Float6.mm
//
// Created by Giles Payne on 2020/02/05.
//
#import "Float6.h"
#import "Mat.h"
@implementation Float6 {
cv::Vec6f native;
}
-(float)v0 {
return native[0];
}
-(void)setV0:(float)v {
native[0] = v;
}
-(float)v1 {
return native[1];
}
-(void)setV1:(float)v {
native[1] = v;
}
-(float)v2 {
return native[2];
}
-(void)setV2:(float)v {
native[2] = v;
}
-(float)v3 {
return native[3];
}
-(void)setV3:(float)v {
native[3] = v;
}
-(float)v4 {
return native[4];
}
-(void)setV4:(float)v {
native[4] = v;
}
-(float)v5 {
return native[5];
}
-(void)setV5:(float)v {
native[5] = v;
}
-(instancetype)init {
return [self initWithV0:0.0 v1:0.0 v2:0.0 v3:0.0 v4:0.0 v5:0.0];
}
-(instancetype)initWithV0:(float)v0 v1:(float)v1 v2:(float)v2 v3:(float)v3 v4:(float)v4 v5:(float)v5 {
self = [super init];
if (self) {
self.v0 = v0;
self.v1 = v1;
self.v2 = v2;
self.v3 = v3;
self.v4 = v4;
self.v5 = v5;
}
return self;
}
-(instancetype)initWithVals:(NSArray<NSNumber*>*)vals {
self = [super init];
if (self) {
[self set:vals];
}
return self;
}
+(instancetype)fromNative:(cv::Vec6f&)vec6f {
return [[Float6 alloc] initWithV0:vec6f[0] v1:vec6f[1] v2:vec6f[2] v3:vec6f[3] v4:vec6f[4] v5:vec6f[5]];
}
-(void)set:(NSArray<NSNumber*>*)vals {
self.v0 = (vals != nil && vals.count > 0) ? vals[0].floatValue : 0.0;
self.v1 = (vals != nil && vals.count > 1) ? vals[1].floatValue : 0.0;
self.v2 = (vals != nil && vals.count > 2) ? vals[2].floatValue : 0.0;
self.v3 = (vals != nil && vals.count > 3) ? vals[3].floatValue : 0.0;
self.v4 = (vals != nil && vals.count > 4) ? vals[4].floatValue : 0.0;
self.v5 = (vals != nil && vals.count > 5) ? vals[5].floatValue : 0.0;
}
-(NSArray<NSNumber*>*)get {
return @[[NSNumber numberWithFloat:native[0]], [NSNumber numberWithFloat:native[1]], [NSNumber numberWithFloat:native[2]], [NSNumber numberWithFloat:native[3]], [NSNumber numberWithFloat:native[4]], [NSNumber numberWithFloat:native[5]]];
}
- (BOOL)isEqual:(id)other {
if (other == self) {
return YES;
} else if (![other isKindOfClass:[Float6 class]]) {
return NO;
} else {
Float6* point = (Float6*)other;
return self.v0 == point.v0 && self.v1 == point.v1 && self.v2 == point.v2 && self.v3 == point.v3 && self.v4 == point.v4 && self.v5 == point.v5;
}
}
@end

View File

@ -0,0 +1,89 @@
//
// FloatVector.h
//
// Created by Giles Payne on 2020/01/04.
//
#pragma once
#import <Foundation/Foundation.h>
#ifdef __cplusplus
#import <vector>
#endif
#import "CVObjcUtil.h"
NS_ASSUME_NONNULL_BEGIN
/**
* Utility class to wrap a `std::vector<float>`
*/
CV_EXPORTS @interface FloatVector : NSObject
#pragma mark - Constructors
/**
* Create FloatVector and initialize with the contents of an NSData object
* @param data NSData containing raw float array
*/
-(instancetype)initWithData:(NSData*)data;
/**
* Create FloatVector and initialize with the contents of another FloatVector object
* @param src FloatVector containing data to copy
*/
-(instancetype)initWithVector:(FloatVector*)src;
#ifdef __OBJC__
/**
* Create FloatVector from raw C array
* @param array The raw C array
* @elements elements The number of elements in the array
*/
-(instancetype)initWithNativeArray:(float*)array elements:(NSInteger)elements;
#endif
#ifdef __cplusplus
/**
* Create FloatVector from std::vector<float>
* @param src The std::vector<float> object to wrap
*/
-(instancetype)initWithStdVector:(std::vector<float>&)src;
+(instancetype)fromNative:(std::vector<float>&)src;
#endif
#pragma mark - Properties
/**
* Length of the vector
*/
@property(readonly) NSInteger length;
#ifdef __OBJC__
/**
* Raw C array
*/
@property(readonly) float* nativeArray;
#endif
#ifdef __cplusplus
/**
* The wrapped std::vector<float> object
*/
@property(readonly) std::vector<float>& nativeRef;
#endif
/**
* NSData object containing the raw float data
*/
@property(readonly) NSData* data;
#pragma mark - Accessor method
/**
* Return array element
* @param index Index of the array element to return
*/
-(float)get:(NSInteger)index;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,76 @@
//
// FloatVector.m
//
// Created by Giles Payne on 2020/01/04.
//
#import "FloatVector.h"
#import <vector>
@implementation FloatVector {
std::vector<float> v;
}
-(instancetype)initWithData:(NSData*)data {
self = [super init];
if (self) {
if (data.length % sizeof(float) != 0) {
@throw [NSException exceptionWithName:NSInvalidArgumentException reason:@"Invalid data length" userInfo:nil];
}
v.insert(v.begin(), (float*)data.bytes, (float*)data.bytes + data.length/sizeof(float));
}
return self;
}
-(instancetype)initWithVector:(FloatVector *)src {
self = [super init];
if (self) {
v.insert(v.begin(), src.nativeRef.begin(), src.nativeRef.end());
}
return self;
}
-(NSInteger)length {
return v.size();
}
-(float*)nativeArray {
return (float*)v.data();
}
-(instancetype)initWithNativeArray:(float*)array elements:(NSInteger)elements {
self = [super init];
if (self) {
v.insert(v.begin(), array, array + elements);
}
return self;
}
- (std::vector<float>&)nativeRef {
return v;
}
-(instancetype)initWithStdVector:(std::vector<float>&)src {
self = [super init];
if (self) {
v.insert(v.begin(), src.begin(), src.end());
}
return self;
}
+(instancetype)fromNative:(std::vector<float>&)src {
return [[FloatVector alloc] initWithStdVector:src];
}
-(float)get:(NSInteger)index {
if (index < 0 || index >= (long)v.size()) {
@throw [NSException exceptionWithName:NSRangeException reason:@"Invalid data length" userInfo:nil];
}
return v[index];
}
-(NSData*)data {
return [NSData dataWithBytesNoCopy:v.data() length:(v.size() * sizeof(float)) freeWhenDone:NO];
}
@end

View File

@ -0,0 +1,53 @@
//
// FloatVectorExt.swift
//
// Created by Giles Payne on 2020/01/04.
//
import Foundation
public extension FloatVector {
convenience init(_ array:[Float]) {
let data = array.withUnsafeBufferPointer { Data(buffer: $0) }
self.init(data:data);
}
subscript(index: Int) -> Float {
get {
return self.get(index)
}
}
var array: [Float] {
get {
var ret = Array<Float>(repeating: 0, count: data.count/MemoryLayout<Float>.stride)
_ = ret.withUnsafeMutableBytes { data.copyBytes(to: $0) }
return ret
}
}
}
extension FloatVector : Sequence {
public typealias Iterator = FloatVectorIterator
public func makeIterator() -> FloatVectorIterator {
return FloatVectorIterator(self)
}
}
public struct FloatVectorIterator: IteratorProtocol {
public typealias Element = Float
let floatVector: FloatVector
var pos = 0
init(_ floatVector: FloatVector) {
self.floatVector = floatVector
}
mutating public func next() -> Float? {
guard pos >= 0 && pos < floatVector.length
else { return nil }
pos += 1
return floatVector.get(pos - 1)
}
}

View File

@ -0,0 +1,101 @@
//
// Int4.h
//
// Created by Giles Payne on 2020/02/05.
//
#pragma once
#ifdef __cplusplus
#import "opencv2/core.hpp"
#else
#define CV_EXPORTS
#endif
#import <Foundation/Foundation.h>
@class Mat;
NS_ASSUME_NONNULL_BEGIN
/**
* Simple wrapper for a vector of four `int`
*/
CV_EXPORTS @interface Int4 : NSObject
#pragma mark - Properties
/**
* First vector element
*/
@property int v0;
/**
* Second vector element
*/
@property int v1;
/**
* Third vector element
*/
@property int v2;
/**
* Fourth vector element
*/
@property int v3;
#ifdef __cplusplus
/**
* The wrapped vector
*/
@property(readonly) cv::Vec4i& nativeRef;
#endif
#pragma mark - Constructors
/**
* Create zero-initialize vecior
*/
-(instancetype)init;
/**
* Create vector with specified element values
* @param v0 First element
* @param v1 Second element
* @param v2 Third element
* @param v3 Fourth element
*/
-(instancetype)initWithV0:(int)v0 v1:(int)v1 v2:(int)v2 v3:(int)v3;
/**
* Create vector with specified element values
* @param vals array of element values
*/
-(instancetype)initWithVals:(NSArray<NSNumber*>*)vals;
#ifdef __cplusplus
+(instancetype)fromNative:(cv::Vec4i&)vec4i;
#endif
/**
* Update vector with specified element values
* @param vals array of element values
*/
-(void)set:(NSArray<NSNumber*>*)vals NS_SWIFT_NAME(set(vals:));
/**
* Get vector as an array
*/
-(NSArray<NSNumber*>*)get;
#pragma mark - Common Methods
/**
* Compare for equality
* @param other Object to compare
*/
-(BOOL)isEqual:(nullable id)other;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,95 @@
//
// Int4.mm
//
// Created by Giles Payne on 2020/02/05.
//
#import "Int4.h"
#import "Mat.h"
@implementation Int4 {
cv::Vec4i native;
}
-(int)v0 {
return native[0];
}
-(void)setV0:(int)v {
native[0] = v;
}
-(int)v1 {
return native[1];
}
-(void)setV1:(int)v {
native[1] = v;
}
-(int)v2 {
return native[2];
}
-(void)setV2:(int)v {
native[2] = v;
}
-(int)v3 {
return native[3];
}
-(void)setV3:(int)v {
native[3] = v;
}
-(instancetype)init {
return [self initWithV0:0 v1:0 v2:0 v3:0];
}
-(instancetype)initWithV0:(int)v0 v1:(int)v1 v2:(int)v2 v3:(int)v3 {
self = [super init];
if (self) {
self.v0 = v0;
self.v1 = v1;
self.v2 = v2;
self.v3 = v3;
}
return self;
}
-(instancetype)initWithVals:(NSArray<NSNumber*>*)vals {
self = [super init];
if (self) {
[self set:vals];
}
return self;
}
+(instancetype)fromNative:(cv::Vec4i&)vec4i {
return [[Int4 alloc] initWithV0:vec4i[0] v1:vec4i[1] v2:vec4i[2] v3:vec4i[3]];
}
-(void)set:(NSArray<NSNumber*>*)vals {
self.v0 = (vals != nil && vals.count > 0) ? vals[0].intValue : 0;
self.v1 = (vals != nil && vals.count > 1) ? vals[1].intValue : 0;
self.v2 = (vals != nil && vals.count > 2) ? vals[2].intValue : 0;
self.v3 = (vals != nil && vals.count > 3) ? vals[3].intValue : 0;
}
-(NSArray<NSNumber*>*)get {
return @[[NSNumber numberWithFloat:native[0]], [NSNumber numberWithFloat:native[1]], [NSNumber numberWithFloat:native[2]], [NSNumber numberWithFloat:native[3]]];
}
- (BOOL)isEqual:(id)other {
if (other == self) {
return YES;
} else if (![other isKindOfClass:[Int4 class]]) {
return NO;
} else {
Int4* point = (Int4*)other;
return self.v0 == point.v0 && self.v1 == point.v1 && self.v2 == point.v2 && self.v3 == point.v3;
}
}
@end

View File

@ -0,0 +1,89 @@
//
// IntVector.h
//
// Created by Giles Payne on 2020/01/04.
//
#pragma once
#import <Foundation/Foundation.h>
#ifdef __cplusplus
#import <vector>
#endif
#import "CVObjcUtil.h"
NS_ASSUME_NONNULL_BEGIN
/**
* Utility class to wrap a `std::vector<int>`
*/
CV_EXPORTS @interface IntVector : NSObject
#pragma mark - Constructors
/**
* Create IntVector and initialize with the contents of an NSData object
* @param data NSData containing raw int array
*/
-(instancetype)initWithData:(NSData*)data;
/**
* Create IntVector and initialize with the contents of another IntVector object
* @param src IntVector containing data to copy
*/
-(instancetype)initWithVector:(IntVector*)src;
#ifdef __OBJC__
/**
* Create IntVector from raw C array
* @param array The raw C array
* @elements elements The number of elements in the array
*/
-(instancetype)initWithNativeArray:(int*)array elements:(NSInteger)elements;
#endif
#ifdef __cplusplus
/**
* Create IntVector from std::vector<int>
* @param src The std::vector<int> object to wrap
*/
-(instancetype)initWithStdVector:(std::vector<int>&)src;
+(instancetype)fromNative:(std::vector<int>&)src;
#endif
#pragma mark - Properties
/**
* Length of the vector
*/
@property(readonly) NSInteger length;
#ifdef __OBJC__
/**
* Raw C array
*/
@property(readonly) int* nativeArray;
#endif
#ifdef __cplusplus
/**
* The wrapped std::vector<int> object
*/
@property(readonly) std::vector<int>& nativeRef;
#endif
/**
* NSData object containing the raw int data
*/
@property(readonly) NSData* data;
#pragma mark - Accessor method
/**
* Return array element
* @param index Index of the array element to return
*/
-(int)get:(NSInteger)index;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,76 @@
//
// IntVector.m
//
// Created by Giles Payne on 2020/01/04.
//
#import "IntVector.h"
#import <vector>
@implementation IntVector {
std::vector<int> v;
}
-(instancetype)initWithData:(NSData*)data {
self = [super init];
if (self) {
if (data.length % sizeof(int) != 0) {
@throw [NSException exceptionWithName:NSInvalidArgumentException reason:@"Invalid data length" userInfo:nil];
}
v.insert(v.begin(), (int*)data.bytes, (int*)data.bytes + data.length/sizeof(int));
}
return self;
}
-(instancetype)initWithVector:(IntVector*)src {
self = [super init];
if (self) {
v.insert(v.begin(), src.nativeRef.begin(), src.nativeRef.end());
}
return self;
}
-(NSInteger)length {
return v.size();
}
-(int*)nativeArray {
return (int*)v.data();
}
-(instancetype)initWithNativeArray:(int*)array elements:(NSInteger)elements {
self = [super init];
if (self) {
v.insert(v.begin(), array, array + elements);
}
return self;
}
- (std::vector<int>&)nativeRef {
return v;
}
-(instancetype)initWithStdVector:(std::vector<int>&)src {
self = [super init];
if (self) {
v.insert(v.begin(), src.begin(), src.end());
}
return self;
}
+(instancetype)fromNative:(std::vector<int>&)src {
return [[IntVector alloc] initWithStdVector:src];
}
-(int)get:(NSInteger)index {
if (index < 0 || index >= (long)v.size()) {
@throw [NSException exceptionWithName:NSRangeException reason:@"Invalid data length" userInfo:nil];
}
return v[index];
}
-(NSData*)data {
return [NSData dataWithBytesNoCopy:v.data() length:(v.size() * sizeof(int)) freeWhenDone:NO];
}
@end

View File

@ -0,0 +1,53 @@
//
// IntVectorExt.swift
//
// Created by Giles Payne on 2020/01/04.
//
import Foundation
public extension IntVector {
convenience init(_ array:[Int32]) {
let data = array.withUnsafeBufferPointer { Data(buffer: $0) }
self.init(data:data);
}
subscript(index: Int) -> Int32 {
get {
return self.get(index)
}
}
var array: [Int32] {
get {
var ret = Array<Int32>(repeating: 0, count: data.count/MemoryLayout<Int32>.stride)
_ = ret.withUnsafeMutableBytes { data.copyBytes(to: $0) }
return ret
}
}
}
extension IntVector : Sequence {
public typealias Iterator = IntVectorIterator
public func makeIterator() -> IntVectorIterator {
return IntVectorIterator(self)
}
}
public struct IntVectorIterator: IteratorProtocol {
public typealias Element = Int32
let intVector: IntVector
var pos = 0
init(_ intVector: IntVector) {
self.intVector = intVector
}
mutating public func next() -> Int32? {
guard pos >= 0 && pos < intVector.length
else { return nil }
pos += 1
return intVector.get(pos - 1)
}
}

View File

@ -0,0 +1,100 @@
//
// KeyPoint.h
//
// Created by Giles Payne on 2019/10/08.
//
#pragma once
#ifdef __cplusplus
#import "opencv2/core.hpp"
#else
#define CV_EXPORTS
#endif
#import <Foundation/Foundation.h>
@class Point2f;
NS_ASSUME_NONNULL_BEGIN
/**
* Object representing a point feature found by one of many available keypoint detectors, such as Harris corner detector, FAST, StarDetector, SURF, SIFT etc.
*/
CV_EXPORTS @interface KeyPoint : NSObject
#pragma mark - Properties
/**
* Coordinates of the keypoint.
*/
@property Point2f* pt;
/**
* Diameter of the useful keypoint adjacent area.
*/
@property float size;
/**
* Computed orientation of the keypoint (-1 if not applicable).
*/
@property float angle;
/**
* The response, by which the strongest keypoints have been selected. Can
* be used for further sorting or subsampling.
*/
@property float response;
/**
* Octave (pyramid layer), from which the keypoint has been extracted.
*/
@property int octave;
/**
* Object ID, that can be used to cluster keypoints by an object they
* belong to.
*/
@property int classId;
#ifdef __cplusplus
@property(readonly) cv::KeyPoint& nativeRef;
#endif
#pragma mark - Constructors
- (instancetype)init;
- (instancetype)initWithX:(float)x y:(float)y size:(float)size angle:(float)angle response:(float)response octave:(int)octave classId:(int)classId;
- (instancetype)initWithX:(float)x y:(float)y size:(float)size angle:(float)angle response:(float)response octave:(int)octave;
- (instancetype)initWithX:(float)x y:(float)y size:(float)size angle:(float)angle response:(float)response;
- (instancetype)initWithX:(float)x y:(float)y size:(float)size angle:(float)angle;
- (instancetype)initWithX:(float)x y:(float)y size:(float)size;
#ifdef __cplusplus
+ (instancetype)fromNative:(cv::KeyPoint&)keyPoint;
#endif
#pragma mark - Common Methods
/**
* Clone object
*/
- (KeyPoint*)clone;
/**
* Compare for equality
* @param other Object to compare
*/
- (BOOL)isEqual:(nullable id)other;
/**
* Calculate hash value for this object
*/
- (NSUInteger)hash;
/**
* Returns a string that describes the contents of the object
*/
- (NSString*)description;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,96 @@
//
// KeyPoint.m
//
// Created by Giles Payne on 2019/12/25.
//
#import "KeyPoint.h"
#import "Point2f.h"
@implementation KeyPoint {
cv::KeyPoint native;
}
- (cv::KeyPoint&)nativeRef {
native.pt.x = self.pt.x;
native.pt.y = self.pt.y;
native.size = self.size;
native.angle = self.angle;
native.response = self.response;
native.octave = self.octave;
native.class_id = self.classId;
return native;
}
- (instancetype)init {
return [self initWithX:0 y:0 size:0];
}
- (instancetype)initWithX:(float)x y:(float)y size:(float)size angle:(float)angle response:(float)response octave:(int)octave classId:(int)classId {
self = [super init];
if (self != nil) {
self.pt = [[Point2f alloc] initWithX:x y:y];
self.size = size;
self.angle = angle;
self.response = response;
self.octave = octave;
self.classId = classId;
}
return self;
}
- (instancetype)initWithX:(float)x y:(float)y size:(float)size angle:(float)angle response:(float)response octave:(int)octave {
return [self initWithX:x y:y size:size angle:angle response:response octave:octave classId:-1];
}
- (instancetype)initWithX:(float)x y:(float)y size:(float)size angle:(float)angle response:(float)response {
return [self initWithX:x y:y size:size angle:angle response:response octave:0];
}
- (instancetype)initWithX:(float)x y:(float)y size:(float)size angle:(float)angle {
return [self initWithX:x y:y size:size angle:angle response:0];
}
- (instancetype)initWithX:(float)x y:(float)y size:(float)size {
return [self initWithX:x y:y size:size angle:-1];
}
+ (instancetype)fromNative:(cv::KeyPoint&)keyPoint {
return [[KeyPoint alloc] initWithX:keyPoint.pt.x y:keyPoint.pt.y size:keyPoint.size angle:keyPoint.angle response:keyPoint.response octave:keyPoint.octave classId:keyPoint.class_id];
}
- (KeyPoint*)clone {
return [[KeyPoint alloc] initWithX:self.pt.x y:self.pt.y size:self.size angle:self.angle response:self.response octave:self.octave classId:self.classId];
}
- (BOOL)isEqual:(id)other {
if (other == self) {
return YES;
} else if (![other isKindOfClass:[KeyPoint class]]) {
return NO;
} else {
KeyPoint* keyPoint = (KeyPoint*)other;
return [self.pt isEqual:keyPoint.pt] && self.size == keyPoint.size && self.angle == keyPoint.angle && self.response == keyPoint.response && self.octave == keyPoint.octave && self.classId == keyPoint.classId;
}
}
#define FLOAT_TO_BITS(x) ((Cv32suf){ .f = x }).i
- (NSUInteger)hash {
int prime = 31;
uint32_t result = 1;
result = prime * result + FLOAT_TO_BITS(self.pt.x);
result = prime * result + FLOAT_TO_BITS(self.pt.y);
result = prime * result + FLOAT_TO_BITS(self.size);
result = prime * result + FLOAT_TO_BITS(self.angle);
result = prime * result + FLOAT_TO_BITS(self.response);
result = prime * result + self.octave;
result = prime * result + self.classId;
return result;
}
- (NSString*)description {
return [NSString stringWithFormat:@"KeyPoint { pt: %@, size: %f, angle: %f, response: %f, octave: %d, classId: %d}", self.pt.description, self.size, self.angle, self.response, self.octave, self.classId];
}
@end

View File

@ -0,0 +1,187 @@
//
// Mat.h
//
// Created by Giles Payne on 2019/10/06.
//
#pragma once
#ifdef __cplusplus
#import "opencv2/core.hpp"
#else
#define CV_EXPORTS
#endif
#import <Foundation/Foundation.h>
@class Size2i;
@class Scalar;
@class Range;
@class Rect2i;
@class Point2i;
NS_ASSUME_NONNULL_BEGIN
/**
The class Mat represents an n-dimensional dense numerical single-channel or multi-channel array.
####Swift Example
```swift
let mat = Mat(rows: 2, cols: 3, type: CvType.CV_8U)
try! mat.put(row: 0, col: 0, data: [2, 3, 4, 4, 5, 6] as [Int8])
print("mat: \(mat.dump())")
```
####Objective-C Example
```objc
Mat* mat = [[Mat alloc] initWithRows:2 cols:3 type: CV_8U];
[m1 put:0 col:0 data:@[@2, @3, @4, @3, @4, @5]];
NSLog(@"mat: %@", [m1 dump]);
```
*/
CV_EXPORTS @interface Mat : NSObject
#ifdef __cplusplus
@property(readonly) cv::Ptr<cv::Mat> nativePtr;
@property(readonly) cv::Mat& nativeRef;
#endif
#pragma mark - Constructors
- (instancetype)init;
#ifdef __cplusplus
- (instancetype)initWithNativeMat:(cv::Ptr<cv::Mat>)nativeMat;
+ (instancetype)fromNativePtr:(cv::Ptr<cv::Mat>)nativePtr;
+ (instancetype)fromNative:(cv::Mat&)nativeRef;
#endif
/**
Creates a Mat object with the specified number of rows and columns and Mat type
@param rows Number of rows
@param cols Number of columns
@param type Mat type (refer: `CvType`)
*/
- (instancetype)initWithRows:(int)rows cols:(int)cols type:(int)type;
- (instancetype)initWithRows:(int)rows cols:(int)cols type:(int)type data:(NSData*)data;
- (instancetype)initWithRows:(int)rows cols:(int)cols type:(int)type data:(NSData*)data step:(long)step;
- (instancetype)initWithSize:(Size2i*)size type:(int)type;
- (instancetype)initWithSizes:(NSArray<NSNumber*>*)sizes type:(int)type;
- (instancetype)initWithRows:(int)rows cols:(int)cols type:(int)type scalar:(Scalar*)scalar;
- (instancetype)initWithSize:(Size2i*)size type:(int)type scalar:(Scalar*)scalar;
- (instancetype)initWithSizes:(NSArray<NSNumber*>*)sizes type:(int)type scalar:(Scalar*)scalar;
- (instancetype)initWithMat:(Mat*)mat rowRange:(Range*)rowRange colRange:(Range*)colRange;
- (instancetype)initWithMat:(Mat*)mat rowRange:(Range*)rowRange;
- (instancetype)initWithMat:(Mat*)mat ranges:(NSArray<Range*>*)ranges;
- (instancetype)initWithMat:(Mat*)mat rect:(Rect2i*)roi;
#pragma mark - Mat operations
- (Mat*)adjustRoiTop:(int)dtop bottom:(int)dbottom left:(int)dleft right:(int)dright NS_SWIFT_NAME(adjustRoi(top:bottom:left:right:));
- (void)assignTo:(Mat*)mat type:(int)type;
- (void)assignTo:(Mat*)mat;
- (BOOL)isSameMat:(Mat*)mat;
- (int)channels;
- (int)checkVector:(int)elemChannels depth:(int)depth requireContinuous:(BOOL) requireContinuous NS_SWIFT_NAME(checkVector(elemChannels:depth:requireContinuous:));
- (int)checkVector:(int)elemChannels depth:(int)depth NS_SWIFT_NAME(checkVector(elemChannels:depth:));
- (int)checkVector:(int)elemChannels NS_SWIFT_NAME(checkVector(elemChannels:));
- (Mat*)clone;
- (Mat*)col:(int)x;
- (Mat*)colRange:(int)start end:(int)end NS_SWIFT_NAME(colRange(start:end:));
- (Mat*)colRange:(Range*)range;
- (int)dims;
- (int)cols;
- (void)convertTo:(Mat*)mat rtype:(int)rtype alpha:(double)alpha beta:(double)beta;
- (void)convertTo:(Mat*)mat rtype:(int)rtype alpha:(double)alpha;
- (void)convertTo:(Mat*)mat rtype:(int)rtype;
- (void)copyTo:(Mat*)mat;
- (void)copyTo:(Mat*)mat mask:(Mat*)mask;
- (void)create:(int)rows cols:(int)cols type:(int)type NS_SWIFT_NAME(create(rows:cols:type:));
- (void)create:(Size2i*)size type:(int)type NS_SWIFT_NAME(create(size:type:));
- (void)createEx:(NSArray<NSNumber*>*)sizes type:(int)type NS_SWIFT_NAME(create(sizes:type:));
- (void)copySize:(Mat*)mat;
- (Mat*)cross:(Mat*)mat;
- (unsigned char*)dataPtr NS_SWIFT_NAME(dataPointer());
- (int)depth;
- (Mat*)diag:(int)diagonal;
- (Mat*)diag;
+ (Mat*)diag:(Mat*)diagonal;
- (double)dot:(Mat*)mat;
- (long)elemSize;
- (long)elemSize1;
- (BOOL)empty;
+ (Mat*)eye:(int)rows cols:(int)cols type:(int)type NS_SWIFT_NAME(eye(rows:cols:type:));
+ (Mat*)eye:(Size2i*)size type:(int)type NS_SWIFT_NAME(eye(size:type:));
- (Mat*)inv:(int)method;
- (Mat*)inv;
- (BOOL)isContinuous;
- (BOOL)isSubmatrix;
- (void)locateROI:(Size2i*)wholeSize ofs:(Point2i*)offset NS_SWIFT_NAME(locateROI(wholeSize:offset:));
- (Mat*)mul:(Mat*)mat scale:(double)scale;
/**
Performs element-wise multiplication
@param mat operand with with which to perform element-wise multiplication
*/
- (Mat*)mul:(Mat*)mat;
/**
Performs matrix multiplication
@param mat operand with with which to perform matrix multiplication
@see `Core.gemm(...)`
*/
- (Mat*)matMul:(Mat*)mat;
+ (Mat*)ones:(int)rows cols:(int)cols type:(int)type NS_SWIFT_NAME(ones(rows:cols:type:));
+ (Mat*)ones:(Size2i*)size type:(int)type NS_SWIFT_NAME(ones(size:type:));
+ (Mat*)onesEx:(NSArray<NSNumber*>*)sizes type:(int)type NS_SWIFT_NAME(ones(sizes:type:));
- (void)push_back:(Mat*)mat;
- (Mat*)reshape:(int)channels rows:(int)rows NS_SWIFT_NAME(reshape(channels:rows:));
- (Mat*)reshape:(int)channels NS_SWIFT_NAME(reshape(channels:));
- (Mat*)reshape:(int)channels newshape:(NSArray<NSNumber*>*)newshape NS_SWIFT_NAME(reshape(channels:newshape:));
- (Mat*)row:(int)y;
- (Mat*)rowRange:(int)start end:(int)end NS_SWIFT_NAME(rowRange(start:end:));
- (Mat*)rowRange:(Range*)range;
- (int)rows;
- (Mat*)setToScalar:(Scalar*)scalar NS_SWIFT_NAME(setTo(scalar:));
- (Mat*)setToScalar:(Scalar*)scalar mask:(Mat*)mask NS_SWIFT_NAME(setTo(scalar:mask:));
- (Mat*)setToValue:(Mat*)value mask:(Mat*)mask NS_SWIFT_NAME(setTo(value:mask:));
- (Mat*)setToValue:(Mat*)value NS_SWIFT_NAME(setTo(value:));
- (Size2i*)size;
- (int)size:(int)dim;
- (long)step1:(int)dim;
- (long)step1;
- (Mat*)submat:(int)rowStart rowEnd:(int)rowEnd colStart:(int)colStart colEnd:(int)colEnd NS_SWIFT_NAME(submat(rowStart:rowEnd:colStart:colEnd:));
- (Mat*)submat:(Range*)rowRange colRange:(Range*)colRange NS_SWIFT_NAME(submat(rowRange:colRange:));
- (Mat*)submat:(NSArray<Range*>*)ranges NS_SWIFT_NAME(submat(ranges:));
- (Mat*)submatRoi:(Rect2i*)roi NS_SWIFT_NAME(submat(roi:));
- (Mat*)t;
- (long)total;
- (int)type;
+ (Mat*)zeros:(int)rows cols:(int)cols type:(int)type;
+ (Mat*)zeros:(Size2i*)size type:(int)type;
+ (Mat*)zerosEx:(NSArray<NSNumber*>*)sizes type:(int)type NS_SWIFT_NAME(zeros(sizes:type:));
- (NSString*)description;
- (NSString*)dump;
- (int)height;
- (int)width;
#pragma mark - Accessors
- (int)put:(int)row col:(int)col data:(NSArray<NSNumber*>*)data NS_REFINED_FOR_SWIFT;
- (int)put:(NSArray<NSNumber*>*)indices data:(NSArray<NSNumber*>*)data NS_REFINED_FOR_SWIFT;
- (int)get:(int)row col:(int)col data:(NSMutableArray<NSNumber*>*)data NS_REFINED_FOR_SWIFT;
- (int)get:(NSArray<NSNumber*>*)indices data:(NSMutableArray<NSNumber*>*)data NS_REFINED_FOR_SWIFT;
- (NSArray<NSNumber*>*)get:(int)row col:(int)col NS_REFINED_FOR_SWIFT;
- (NSArray<NSNumber*>*)get:(NSArray<NSNumber*>*)indices NS_REFINED_FOR_SWIFT;
- (int)get:(NSArray<NSNumber*>*)indices count:(int)count byteBuffer:(char*)buffer NS_REFINED_FOR_SWIFT;
- (int)get:(NSArray<NSNumber*>*)indices count:(int)count doubleBuffer:(double*)buffer NS_REFINED_FOR_SWIFT;
- (int)get:(NSArray<NSNumber*>*)indices count:(int)count floatBuffer:(float*)buffer NS_REFINED_FOR_SWIFT;
- (int)get:(NSArray<NSNumber*>*)indices count:(int)count intBuffer:(int*)buffer NS_REFINED_FOR_SWIFT;
- (int)get:(NSArray<NSNumber*>*)indices count:(int)count shortBuffer:(short*)buffer NS_REFINED_FOR_SWIFT;
- (int)put:(NSArray<NSNumber*>*)indices count:(int)count byteBuffer:(const char*)buffer NS_REFINED_FOR_SWIFT;
- (int)put:(NSArray<NSNumber*>*)indices count:(int)count doubleBuffer:(const double*)buffer NS_REFINED_FOR_SWIFT;
- (int)put:(NSArray<NSNumber*>*)indices count:(int)count floatBuffer:(const float*)buffer NS_REFINED_FOR_SWIFT;
- (int)put:(NSArray<NSNumber*>*)indices count:(int)count intBuffer:(const int*)buffer NS_REFINED_FOR_SWIFT;
- (int)put:(NSArray<NSNumber*>*)indices count:(int)count shortBuffer:(const short*)buffer NS_REFINED_FOR_SWIFT;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,935 @@
//
// Mat.m
//
// Created by Giles Payne on 2019/10/06.
//
#import "Mat.h"
#import "Size2i.h"
#import "Scalar.h"
#import "Range.h"
#import "Rect2i.h"
#import "Point2i.h"
#import "CvType.h"
#import "CVObjcUtil.h"
static int idx2Offset(cv::Mat* mat, std::vector<int>& indices) {
int offset = indices[0];
for (int dim=1; dim < mat->dims; dim++) {
offset = offset*mat->size[dim] + indices[dim];
}
return offset;
}
static void offset2Idx(cv::Mat* mat, size_t offset, std::vector<int>& indices) {
for (int dim=mat->dims-1; dim>=0; dim--) {
indices[dim] = offset % mat->size[dim];
offset = (offset - indices[dim]) / mat->size[dim];
}
}
// returns true if final index was reached
static bool updateIdx(cv::Mat* mat, std::vector<int>& indices, size_t inc) {
size_t currentOffset = idx2Offset(mat, indices);
size_t newOffset = currentOffset + inc;
bool reachedEnd = newOffset>=(size_t)mat->total();
offset2Idx(mat, reachedEnd?0:newOffset, indices);
return reachedEnd;
}
@implementation Mat {
NSData* _nsdata;
}
- (cv::Mat&)nativeRef {
return *_nativePtr;
}
- (instancetype)init {
self = [super init];
if (self) {
_nativePtr = cv::Ptr<cv::Mat>(new cv::Mat());
}
return self;
}
- (instancetype)initWithNativeMat:(cv::Ptr<cv::Mat>)nativePtr {
self = [super init];
if (self) {
_nativePtr = nativePtr;
}
return self;
}
+ (instancetype)fromNativePtr:(cv::Ptr<cv::Mat>)nativePtr {
return [[Mat alloc] initWithNativeMat:nativePtr];
}
+ (instancetype)fromNative:(cv::Mat&)nativeRef {
return [[Mat alloc] initWithNativeMat:cv::Ptr<cv::Mat>(new cv::Mat(nativeRef))];
}
- (instancetype)initWithRows:(int)rows cols:(int)cols type:(int)type {
self = [super init];
if (self) {
_nativePtr = new cv::Mat(rows, cols, type);
}
return self;
}
- (instancetype)initWithRows:(int)rows cols:(int)cols type:(int)type data:(NSData*)data {
self = [super init];
if (self) {
_nativePtr = new cv::Mat(rows, cols, type, (void*)data.bytes);
_nsdata = data; // hold onto a reference otherwise this object might be deallocated
}
return self;
}
- (instancetype)initWithRows:(int)rows cols:(int)cols type:(int)type data:(NSData*)data step:(long)step {
self = [super init];
if (self) {
_nativePtr = new cv::Mat(rows, cols, type, (void*)data.bytes, step);
_nsdata = data; // hold onto a reference otherwise this object might be deallocated
}
return self;
}
- (instancetype)initWithSize:(Size2i*)size type:(int)type {
self = [super init];
if (self) {
_nativePtr = new cv::Mat(size.width, size.height, type);
}
return self;
}
- (instancetype)initWithSizes:(NSArray<NSNumber*>*)sizes type:(int)type {
self = [super init];
if (self) {
std::vector<int> vSizes;
for (NSNumber* size in sizes) {
vSizes.push_back(size.intValue);
}
_nativePtr = new cv::Mat((int)sizes.count, vSizes.data(), type);
}
return self;
}
- (instancetype)initWithRows:(int)rows cols:(int)cols type:(int)type scalar:(Scalar*)scalar {
self = [super init];
if (self) {
cv::Scalar scalerTemp(scalar.val[0].doubleValue, scalar.val[1].doubleValue, scalar.val[2].doubleValue, scalar.val[3].doubleValue);
_nativePtr = new cv::Mat(rows, cols, type, scalerTemp);
}
return self;
}
- (instancetype)initWithSize:(Size2i*)size type:(int)type scalar:(Scalar *)scalar {
self = [super init];
if (self) {
cv::Scalar scalerTemp(scalar.val[0].doubleValue, scalar.val[1].doubleValue, scalar.val[2].doubleValue, scalar.val[3].doubleValue);
_nativePtr = new cv::Mat(size.width, size.height, type, scalerTemp);
}
return self;
}
- (instancetype)initWithSizes:(NSArray<NSNumber*>*)sizes type:(int)type scalar:(Scalar *)scalar {
self = [super init];
if (self) {
cv::Scalar scalerTemp(scalar.val[0].doubleValue, scalar.val[1].doubleValue, scalar.val[2].doubleValue, scalar.val[3].doubleValue);
std::vector<int> vSizes;
for (NSNumber* size in sizes) {
vSizes.push_back(size.intValue);
}
_nativePtr = new cv::Mat((int)sizes.count, vSizes.data(), type, scalerTemp);
}
return self;
}
- (instancetype)initWithMat:(Mat*)mat rowRange:(Range*)rowRange colRange:(Range*)colRange {
self = [super init];
if (self) {
cv::Range rows(rowRange.start, rowRange.end);
cv::Range cols(colRange.start, colRange.end);
_nativePtr = new cv::Mat(*(cv::Mat*)mat.nativePtr, rows, cols);
}
return self;
}
- (instancetype)initWithMat:(Mat*)mat rowRange:(Range*)rowRange {
self = [super init];
if (self) {
cv::Range rows(rowRange.start, rowRange.end);
_nativePtr = new cv::Mat(*(cv::Mat*)mat.nativePtr, rows);
}
return self;
}
- (instancetype)initWithMat:(Mat*)mat ranges:(NSArray<Range*>*)ranges {
self = [super init];
if (self) {
std::vector<cv::Range> tempRanges;
for (Range* range in ranges) {
tempRanges.push_back(cv::Range(range.start, range.end));
}
_nativePtr = new cv::Mat(mat.nativePtr->operator()(tempRanges));
}
return self;
}
- (instancetype)initWithMat:(Mat*)mat rect:(Rect2i*)roi {
self = [super init];
if (self) {
cv::Range rows(roi.y, roi.y + roi.height);
cv::Range cols(roi.x, roi.x + roi.width);
_nativePtr = new cv::Mat(*(cv::Mat*)mat.nativePtr, rows, cols);
}
return self;
}
- (BOOL)isSameMat:(Mat*)mat {
return self.nativePtr == mat.nativePtr;
}
- (Mat*)adjustRoiTop:(int)dtop bottom:(int)dbottom left:(int)dleft right:(int)dright {
cv::Mat adjusted = _nativePtr->adjustROI(dtop, dbottom, dleft, dright);
return [[Mat alloc] initWithNativeMat:new cv::Mat(adjusted)];
}
- (void)assignTo:(Mat*)mat type:(int)type {
_nativePtr->assignTo(*(cv::Mat*)mat.nativePtr, type);
}
- (void)assignTo:(Mat*)mat {
_nativePtr->assignTo(*(cv::Mat*)mat.nativePtr);
}
- (int)channels {
return _nativePtr->channels();
}
- (int)checkVector:(int)elemChannels depth:(int)depth requireContinuous:(BOOL) requireContinuous {
return _nativePtr->checkVector(elemChannels, depth, requireContinuous);
}
- (int)checkVector:(int)elemChannels depth:(int)depth {
return _nativePtr->checkVector(elemChannels, depth);
}
- (int)checkVector:(int)elemChannels {
return _nativePtr->checkVector(elemChannels);
}
- (Mat*)clone {
return [[Mat alloc] initWithNativeMat:(new cv::Mat(_nativePtr->clone()))];
}
- (Mat*)col:(int)x {
return [[Mat alloc] initWithNativeMat:(new cv::Mat(_nativePtr->col(x)))];
}
- (Mat*)colRange:(int)start end:(int)end {
return [[Mat alloc] initWithNativeMat:(new cv::Mat(_nativePtr->colRange(start, end)))];
}
- (Mat*)colRange:(Range*)range {
return [[Mat alloc] initWithNativeMat:(new cv::Mat(_nativePtr->colRange(range.start, range.end)))];
}
- (int)dims {
return _nativePtr->dims;
}
- (int)cols {
return _nativePtr->cols;
}
- (void)convertTo:(Mat*)mat rtype:(int)rtype alpha:(double)alpha beta:(double)beta {
_nativePtr->convertTo(*(cv::Mat*)mat->_nativePtr, rtype, alpha, beta);
}
- (void)convertTo:(Mat*)mat rtype:(int)rtype alpha:(double)alpha {
_nativePtr->convertTo(*(cv::Mat*)mat->_nativePtr, rtype, alpha);
}
- (void)convertTo:(Mat*)mat rtype:(int)rtype {
_nativePtr->convertTo(*(cv::Mat*)mat->_nativePtr, rtype);
}
- (void)copyTo:(Mat*)mat {
_nativePtr->copyTo(*(cv::Mat*)mat->_nativePtr);
}
- (void)copyTo:(Mat*)mat mask:(Mat*)mask {
_nativePtr->copyTo(*(cv::Mat*)mat->_nativePtr, *(cv::Mat*)mask->_nativePtr);
}
- (void)create:(int)rows cols:(int)cols type:(int)type {
_nativePtr->create(rows, cols, type);
}
- (void)create:(Size2i*)size type:(int)type {
cv::Size tempSize(size.width, size.height);
_nativePtr->create(tempSize, type);
}
- (void)createEx:(NSArray<NSNumber*>*)sizes type:(int)type {
std::vector<int> tempSizes;
for (NSNumber* size in sizes) {
tempSizes.push_back(size.intValue);
}
_nativePtr->create((int)tempSizes.size(), tempSizes.data(), type);
}
- (void)copySize:(Mat*)mat {
_nativePtr->copySize(*(cv::Mat*)mat.nativePtr);
}
- (Mat*)cross:(Mat*)mat {
return [[Mat alloc] initWithNativeMat:new cv::Mat(_nativePtr->cross(*(cv::Mat*)mat.nativePtr))];
}
- (unsigned char*)dataPtr {
return _nativePtr->data;
}
- (int)depth {
return _nativePtr->depth();
}
- (Mat*)diag:(int)diagonal {
return [[Mat alloc] initWithNativeMat:new cv::Mat(_nativePtr->diag(diagonal))];
}
- (Mat*)diag {
return [self diag:0];
}
+ (Mat*)diag:(Mat*)diagonal {
return [[Mat alloc] initWithNativeMat:new cv::Mat(cv::Mat::diag(*(cv::Mat*)diagonal.nativePtr))];
}
- (double)dot:(Mat*)mat {
return _nativePtr->dot(*(cv::Mat*)mat.nativePtr);
}
- (long)elemSize {
return _nativePtr->elemSize();
}
- (long)elemSize1 {
return _nativePtr->elemSize1();
}
- (BOOL)empty {
return _nativePtr->empty();
}
+ (Mat*)eye:(int)rows cols:(int)cols type:(int)type {
return [[Mat alloc] initWithNativeMat:new cv::Mat(cv::Mat::eye(rows, cols, type))];
}
+ (Mat*)eye:(Size2i*)size type:(int)type {
cv::Size tempSize(size.width, size.height);
return [[Mat alloc] initWithNativeMat:new cv::Mat(cv::Mat::eye(tempSize, type))];
}
- (Mat*)inv:(int)method {
return [[Mat alloc] initWithNativeMat:new cv::Mat(_nativePtr->inv(method))];
}
- (Mat*)inv {
return [[Mat alloc] initWithNativeMat:new cv::Mat(_nativePtr->inv())];
}
- (BOOL)isContinuous {
return _nativePtr->isContinuous();
}
- (BOOL)isSubmatrix {
return _nativePtr->isSubmatrix();
}
- (void)locateROI:(Size2i*)wholeSize ofs:(Point2i*)ofs {
cv::Size tempWholeSize;
cv::Point tempOfs;
_nativePtr->locateROI(tempWholeSize, tempOfs);
if (wholeSize != nil) {
wholeSize.width = tempWholeSize.width;
wholeSize.height = tempWholeSize.height;
}
if (ofs != nil) {
ofs.x = tempOfs.x;
ofs.y = tempOfs.y;
}
}
- (Mat*)mul:(Mat*)mat scale:(double)scale {
return [[Mat alloc] initWithNativeMat:new cv::Mat(_nativePtr->mul(*(cv::Mat*)mat.nativePtr, scale))];
}
- (Mat*)mul:(Mat*)mat {
return [[Mat alloc] initWithNativeMat:new cv::Mat(_nativePtr->mul(*(cv::Mat*)mat.nativePtr))];
}
- (Mat*)matMul:(Mat*)mat {
cv::Mat temp = self.nativeRef * mat.nativeRef;
return [Mat fromNative:temp];
}
+ (Mat*)ones:(int)rows cols:(int)cols type:(int)type {
return [[Mat alloc] initWithNativeMat:new cv::Mat(cv::Mat::ones(rows, cols, type))];
}
+ (Mat*)ones:(Size2i*)size type:(int)type {
cv::Size tempSize(size.width, size.height);
return [[Mat alloc] initWithNativeMat:new cv::Mat(cv::Mat::ones(tempSize, type))];
}
+ (Mat*)onesEx:(NSArray<NSNumber*>*)sizes type:(int)type {
std::vector<int> tempSizes;
for (NSNumber* size in sizes) {
tempSizes.push_back(size.intValue);
}
return [[Mat alloc] initWithNativeMat:new cv::Mat(cv::Mat::ones((int)tempSizes.size(), tempSizes.data(), type))];
}
- (void)push_back:(Mat*)mat {
_nativePtr->push_back(*(cv::Mat*)mat.nativePtr);
}
- (Mat*)reshape:(int)channels rows:(int)rows {
return [[Mat alloc] initWithNativeMat:new cv::Mat(_nativePtr->reshape(channels, rows))];
}
- (Mat*)reshape:(int)channels {
return [[Mat alloc] initWithNativeMat:new cv::Mat(_nativePtr->reshape(channels))];
}
- (Mat*)reshape:(int)channels newshape:(NSArray<NSNumber*>*)newshape {
std::vector<int> tempNewshape;
for (NSNumber* size in newshape) {
tempNewshape.push_back(size.intValue);
}
return [[Mat alloc] initWithNativeMat:new cv::Mat(_nativePtr->reshape(channels, tempNewshape))];
}
- (Mat*)row:(int)y {
return [[Mat alloc] initWithNativeMat:new cv::Mat(_nativePtr->row(y))];
}
- (Mat*)rowRange:(int)start end:(int)end {
return [[Mat alloc] initWithNativeMat:new cv::Mat(_nativePtr->rowRange(start, end))];
}
- (Mat*)rowRange:(Range*)range {
return [[Mat alloc] initWithNativeMat:new cv::Mat(_nativePtr->rowRange(range.start, range.end))];
}
- (int)rows {
return _nativePtr->rows;
}
- (Mat*)setToScalar:(Scalar*)scalar {
cv::Scalar tempScalar(scalar.val[0].doubleValue, scalar.val[1].doubleValue, scalar.val[2].doubleValue, scalar.val[3].doubleValue);
return [[Mat alloc] initWithNativeMat:new cv::Mat(_nativePtr->operator=(tempScalar))];
}
- (Mat*)setToScalar:(Scalar*)scalar mask:(Mat*)mask {
cv::Scalar tempScalar(scalar.val[0].doubleValue, scalar.val[1].doubleValue, scalar.val[2].doubleValue, scalar.val[3].doubleValue);
return [[Mat alloc] initWithNativeMat:new cv::Mat(_nativePtr->setTo(tempScalar, *(cv::Mat*)mask.nativePtr))];
}
- (Mat*)setToValue:(Mat*)value mask:(Mat*)mask {
return [[Mat alloc] initWithNativeMat:new cv::Mat(_nativePtr->setTo(*(cv::Mat*)value.nativePtr, *(cv::Mat*)mask.nativePtr))];
}
- (Mat*)setToValue:(Mat*)value {
return [[Mat alloc] initWithNativeMat:new cv::Mat(_nativePtr->setTo(*(cv::Mat*)value.nativePtr))];
}
- (Size2i*)size {
return [[Size2i alloc] initWithWidth:_nativePtr->size().width height:_nativePtr->size().height];
}
- (int)size:(int)dimIndex {
return _nativePtr->size[dimIndex];
}
- (long)step1:(int)dimIndex {
return _nativePtr->step1(dimIndex);
}
- (long)step1 {
return _nativePtr->step1();
}
- (Mat*)submat:(int)rowStart rowEnd:(int)rowEnd colStart:(int)colStart colEnd:(int)colEnd {
Range* rowRange = [[Range alloc] initWithStart:rowStart end:rowEnd];
Range* colRange = [[Range alloc] initWithStart:colStart end:colEnd];
return [self submat:rowRange colRange:colRange];
}
- (Mat*)submat:(Range*)rowRange colRange:(Range*)colRange {
cv::Range tempRowRange(rowRange.start, rowRange.end);
cv::Range tempColRange(colRange.start, colRange.end);
return [[Mat alloc] initWithNativeMat:new cv::Mat(_nativePtr->operator()(tempRowRange, tempColRange))];
}
- (Mat*)submat:(NSArray<Range*>*)ranges {
std::vector<cv::Range> tempRanges;
for (Range* range in ranges) {
tempRanges.push_back(cv::Range(range.start, range.end));
}
return [[Mat alloc] initWithNativeMat:new cv::Mat(_nativePtr->operator()(tempRanges))];
}
- (Mat*)submatRoi:(Rect2i*)roi {
cv::Rect tempRoi(roi.x, roi.y, roi.width, roi.height);
return [[Mat alloc] initWithNativeMat:new cv::Mat(_nativePtr->operator()(tempRoi))];
}
- (Mat*)t {
return [[Mat alloc] initWithNativeMat:new cv::Mat(_nativePtr->t())];
}
- (long)total {
return _nativePtr->total();
}
- (int)type {
return _nativePtr->type();
}
+ (Mat*)zeros:(int)rows cols:(int)cols type:(int)type {
return [[Mat alloc] initWithNativeMat:new cv::Mat(cv::Mat::zeros(rows, cols, type))];
}
+ (Mat*)zeros:(Size2i*)size type:(int)type {
cv::Size tempSize(size.width, size.height);
return [[Mat alloc] initWithNativeMat:new cv::Mat(cv::Mat::zeros(tempSize, type))];
}
+ (Mat*)zerosEx:(NSArray<NSNumber*>*)sizes type:(int)type {
std::vector<int> tempSizes;
for (NSNumber* size in sizes) {
tempSizes.push_back(size.intValue);
}
return [[Mat alloc] initWithNativeMat:new cv::Mat(cv::Mat::zeros((int)tempSizes.size(), tempSizes.data(), type))];
}
- (NSString*)dimsDescription {
if (_nativePtr->dims <= 0) {
return @"-1*-1*";
} else {
NSMutableString* ret = [NSMutableString string];
for (int index=0; index<_nativePtr->dims; index++) {
[ret appendFormat:@"%d*", _nativePtr->size[index]];
}
return ret;
}
}
- (NSString*)description {
NSString* dimDesc = [self dimsDescription];
return [NSString stringWithFormat:@"Mat [ %@%@, isCont=%s, isSubmat=%s, nativeObj=0x%p, dataAddr=0x%p ]", dimDesc, [CvType typeToString:_nativePtr->type()], _nativePtr->isContinuous()?"YES":"NO", _nativePtr->isSubmatrix()?"YES":"NO", (void*)_nativePtr, (void*)_nativePtr->data];
}
- (NSString*)dump {
NSMutableString* ret = [NSMutableString string];
cv::Ptr<cv::Formatted> formatted = cv::Formatter::get()->format(*_nativePtr);
for(const char* format = formatted->next(); format; format = formatted->next()) {
[ret appendFormat:@"%s", format];
}
return ret;
}
template<typename T> void putData(uchar* dataDest, int count, T (^readData)(int)) {
T* tDataDest = (T*)dataDest;
for (int index = 0; index < count; index++) {
tDataDest[index] = readData(index);
}
}
- (void)put:(uchar*)dest data:(NSArray<NSNumber*>*)data offset:(int)offset count:(int)count {
int depth = _nativePtr->depth();
if (depth == CV_8U) {
putData(dest, count, ^uchar (int index) { return cv::saturate_cast<uchar>(data[offset + index].doubleValue);} );
} else if (depth == CV_8S) {
putData(dest, count, ^schar (int index) { return cv::saturate_cast<schar>(data[offset + index].doubleValue);} );
} else if (depth == CV_16U) {
putData(dest, count, ^ushort (int index) { return cv::saturate_cast<ushort>(data[offset + index].doubleValue);} );
} else if (depth == CV_16S) {
putData(dest, count, ^short (int index) { return cv::saturate_cast<short>(data[offset + index].doubleValue);} );
} else if (depth == CV_32S) {
putData(dest, count, ^int32_t (int index) { return cv::saturate_cast<int32_t>(data[offset + index].doubleValue);} );
} else if (depth == CV_32F) {
putData(dest, count, ^float (int index) { return cv::saturate_cast<float>(data[offset + index].doubleValue);} );
} else if (depth == CV_64F) {
putData(dest, count, ^double (int index) { return data[offset + index].doubleValue;} );
}
}
- (int)put:(NSArray<NSNumber*>*)indices data:(NSArray<NSNumber*>*)data {
cv::Mat* mat = _nativePtr;
int type = mat->type();
int rawValueSize = (int)(mat->elemSize() / mat->channels());
if (data == nil || data.count % [CvType channels:type] != 0) {
NSException* exception = [NSException
exceptionWithName:@"UnsupportedOperationException"
reason:[NSString stringWithFormat:@"Provided data element number (%lu) should be multiple of the Mat channels count (%d)", (unsigned long)(data == nil ? 0 : data.count), [CvType channels:type]]
userInfo:nil];
@throw exception;
}
std::vector<int> tempIndices;
for (NSNumber* index in indices) {
tempIndices.push_back(index.intValue);
}
for (int index = 0; index < mat->dims; index++) {
if (mat->size[index]<=tempIndices[index]) {
return 0; // indexes out of range
}
}
int arrayAvailable = (int)data.count;
int matAvailable = getMatAvailable(mat, tempIndices);
int available = MIN(arrayAvailable, matAvailable);
int copyOffset = 0;
int copyCount = MIN((mat->size[mat->dims - 1] - tempIndices[mat->dims - 1]) * mat->channels(), available);
int result = (int)(available * rawValueSize);
while (available > 0) {
[self put:mat->ptr(tempIndices.data()) data:data offset:(int)copyOffset count:copyCount];
if (updateIdx(mat, tempIndices, copyCount / mat->channels())) {
break;
}
available -= copyCount;
copyOffset += copyCount;
copyCount = MIN(mat->size[mat->dims-1] * mat->channels(), available);
}
return result;
}
- (int)put:(int)row col:(int)col data:(NSArray<NSNumber*>*)data {
NSArray<NSNumber*>* indices = @[[NSNumber numberWithInt:row], [NSNumber numberWithInt:col]];
return [self put:indices data:data];
}
template<typename T> void getData(uchar* dataSource, int count, void (^writeData)(int,T)) {
T* tDataSource = (T*)dataSource;
for (int index = 0; index < count; index++) {
writeData(index, tDataSource[index]);
}
}
- (void)get:(uchar*)source data:(NSMutableArray<NSNumber*>*)data offset:(int)offset count:(int)count {
int depth = _nativePtr->depth();
if (depth == CV_8U) {
getData(source, count, ^void (int index, uchar value) { data[offset + index] = [[NSNumber alloc] initWithUnsignedChar:value]; } );
} else if (depth == CV_8S) {
getData(source, count, ^void (int index, char value) { data[offset + index] = [[NSNumber alloc] initWithChar:value]; } );
} else if (depth == CV_16U) {
getData(source, count, ^void (int index, ushort value) { data[offset + index] = [[NSNumber alloc] initWithUnsignedShort:value]; } );
} else if (depth == CV_16S) {
getData(source, count, ^void (int index, short value) { data[offset + index] = [[NSNumber alloc] initWithShort:value]; } );
} else if (depth == CV_32S) {
getData(source, count, ^void (int index, int32_t value) { data[offset + index] = [[NSNumber alloc] initWithInt:value]; } );
} else if (depth == CV_32F) {
getData(source, count, ^void (int index, float value) { data[offset + index] = [[NSNumber alloc] initWithFloat:value]; } );
} else if (depth == CV_64F) {
getData(source, count, ^void (int index, double value) { data[offset + index] = [[NSNumber alloc] initWithDouble:value]; } );
}
}
- (int)get:(NSArray<NSNumber*>*)indices data:(NSMutableArray<NSNumber*>*)data {
cv::Mat* mat = _nativePtr;
int type = mat->type();
if (data == nil || data.count % [CvType channels:type] != 0) {
NSException* exception = [NSException
exceptionWithName:@"UnsupportedOperationException"
reason:[NSString stringWithFormat:@"Provided data element number (%lu) should be multiple of the Mat channels count (%d)", (unsigned long)(data == nil ? 0 : data.count), [CvType channels:type]]
userInfo:nil];
@throw exception;
}
std::vector<int> tempIndices;
for (NSNumber* index in indices) {
tempIndices.push_back(index.intValue);
}
for (int index = 0; index < mat->dims; index++) {
if (mat->size[index]<=tempIndices[index]) {
return 0; // indexes out of range
}
}
int arrayAvailable = (int)data.count;
int copyOffset = 0;
int matAvailable = getMatAvailable(mat, tempIndices);
int available = MIN(arrayAvailable, matAvailable);
int copyCount = MIN((mat->size[mat->dims - 1] - tempIndices[mat->dims - 1]) * mat->channels(), available);
int result = (int)(available * mat->elemSize() / mat->channels());
while (available > 0) {
[self get:mat->ptr(tempIndices.data()) data:data offset:(int)copyOffset count:copyCount];
if (updateIdx(mat, tempIndices, copyCount / mat->channels())) {
break;
}
available -= copyCount;
copyOffset += copyCount;
copyCount = MIN(mat->size[mat->dims-1] * mat->channels(), available);
}
return result;
}
- (int)get:(int)row col:(int)col data:(NSMutableArray<NSNumber*>*)data {
NSArray<NSNumber*>* indices = @[[NSNumber numberWithInt:row], [NSNumber numberWithInt:col]];
return [self get:indices data:data];
}
- (NSArray<NSNumber*>*)get:(int)row col:(int)col {
NSMutableArray<NSNumber*>* result = [NSMutableArray new];
for (int index = 0; index<_nativePtr->channels(); index++) {
[result addObject:@0];
}
[self get:row col:col data:result];
return result;
}
- (NSArray<NSNumber*>*)get:(NSArray<NSNumber*>*)indices {
NSMutableArray<NSNumber*>* result = [NSMutableArray new];
for (int index = 0; index<_nativePtr->channels(); index++) {
[result addObject:@0];
}
[self get:indices data:result];
return result;
}
template<typename T> void getData(uchar* source, void (^writeData)(int,T), int dataOffset, int dataLength) {
T* tSource = (T*)source;
for (int index = 0; index < dataLength; index++) {
writeData(dataOffset+index, tSource[index]);
}
}
int getMatAvailable(cv::Mat* mat, std::vector<int>& indices) {
int blockSize = 1;
int unavailableCount = 0;
for (int index = mat->dims - 1; index >= 0; index--) {
unavailableCount += blockSize * indices[index];
blockSize *= mat->size[index];
}
return (int)(mat->channels() * (mat->total() - unavailableCount));
}
template<typename T> int getData(NSArray<NSNumber*>* indices, cv::Mat* mat, int count, T* tBuffer) {
std::vector<int> tempIndices;
for (NSNumber* index in indices) {
tempIndices.push_back(index.intValue);
}
for (int index = 0; index < mat->dims; index++) {
if (mat->size[index]<=tempIndices[index]) {
return 0; // indexes out of range
}
}
int arrayAvailable = count;
size_t countBytes = count * sizeof(T);
size_t remainingBytes = (size_t)(mat->total() - idx2Offset(mat, tempIndices))*mat->elemSize();
countBytes = (countBytes>remainingBytes)?remainingBytes:countBytes;
int result = (int)countBytes;
int matAvailable = getMatAvailable(mat, tempIndices);
int available = MIN(arrayAvailable, matAvailable);
if (mat->isContinuous()) {
memcpy(tBuffer, mat->ptr(tempIndices.data()), available * sizeof(T));
} else {
char* buff = (char*)tBuffer;
size_t blockSize = mat->size[mat->dims-1] * mat->elemSize();
size_t firstPartialBlockSize = (mat->size[mat->dims-1] - tempIndices[mat->dims-1]) * mat->step[mat->dims-1];
for (int dim=mat->dims-2; dim>=0 && blockSize == mat->step[dim]; dim--) {
blockSize *= mat->size[dim];
firstPartialBlockSize += (mat->size[dim] - (tempIndices[dim]+1)) * mat->step[dim];
}
size_t copyCount = (countBytes<firstPartialBlockSize)?countBytes:firstPartialBlockSize;
uchar* data = mat->ptr(tempIndices.data());
while(countBytes>0) {
memcpy(buff, data, copyCount);
updateIdx(mat, tempIndices, copyCount / mat->elemSize());
countBytes -= copyCount;
buff += copyCount;
copyCount = countBytes<blockSize?countBytes:blockSize;
data = mat->ptr(tempIndices.data());
}
}
return result;
}
- (int)get:(NSArray<NSNumber*>*)indices count:(int)count byteBuffer:(char*)buffer {
int depth = _nativePtr->depth();
if (depth != CV_8U && depth != CV_8S) {
NSException* exception = [NSException
exceptionWithName:@"UnsupportedOperationException"
reason:[NSString stringWithFormat:@"Invalid depth (%@). Valid depths for this call are CV_8U or CV_8S.", [CvType typeToString:depth]]
userInfo:nil];
@throw exception;
}
return getData(indices, _nativePtr, count, buffer);
}
- (int)get:(NSArray<NSNumber*>*)indices count:(int)count doubleBuffer:(double*)buffer {
int depth = _nativePtr->depth();
if (depth != CV_64F) {
NSException* exception = [NSException
exceptionWithName:@"UnsupportedOperationException"
reason:[NSString stringWithFormat:@"Invalid depth (%@). Valid depth for this call is CV_64F.", [CvType typeToString:depth]]
userInfo:nil];
@throw exception;
}
return getData(indices, _nativePtr, count, buffer);
}
- (int)get:(NSArray<NSNumber*>*)indices count:(int)count floatBuffer:(float*)buffer {
int depth = _nativePtr->depth();
if (depth != CV_32F) {
NSException* exception = [NSException
exceptionWithName:@"UnsupportedOperationException"
reason:[NSString stringWithFormat:@"Invalid depth (%@). Valid depth for this call is CV_32F.", [CvType typeToString:depth]]
userInfo:nil];
@throw exception;
}
return getData(indices, _nativePtr, count, buffer);
}
- (int)get:(NSArray<NSNumber*>*)indices count:(int)count intBuffer:(int*)buffer {
int depth = _nativePtr->depth();
if (depth != CV_32S) {
NSException* exception = [NSException
exceptionWithName:@"UnsupportedOperationException"
reason:[NSString stringWithFormat:@"Invalid depth (%@). Valid depth for this call is CV_32S.", [CvType typeToString:depth]]
userInfo:nil];
@throw exception;
}
return getData(indices, _nativePtr, count, buffer);
}
- (int)get:(NSArray<NSNumber*>*)indices count:(int)count shortBuffer:(short*)buffer {
int depth = _nativePtr->depth();
if (depth != CV_16S && depth != CV_16U) {
NSException* exception = [NSException
exceptionWithName:@"UnsupportedOperationException"
reason:[NSString stringWithFormat:@"Invalid depth (%@). Valid depths for this call are CV_16S and CV_16U.", [CvType typeToString:depth]]
userInfo:nil];
@throw exception;
}
return getData(indices, _nativePtr, count, buffer);
}
template<typename T> int putData(NSArray<NSNumber*>* indices, cv::Mat* mat, int count, const T* tBuffer) {
std::vector<int> tempIndices;
for (NSNumber* index in indices) {
tempIndices.push_back(index.intValue);
}
for (int index = 0; index < mat->dims; index++) {
if (mat->size[index]<=tempIndices[index]) {
return 0; // indexes out of range
}
}
int arrayAvailable = count;
size_t countBytes = count * sizeof(T);
size_t remainingBytes = (size_t)(mat->total() - idx2Offset(mat, tempIndices))*mat->elemSize();
countBytes = (countBytes>remainingBytes)?remainingBytes:countBytes;
int result = (int)countBytes;
int matAvailable = getMatAvailable(mat, tempIndices);
int available = MIN(arrayAvailable, matAvailable);
if (mat->isContinuous()) {
memcpy(mat->ptr(tempIndices.data()), tBuffer, available * sizeof(T));
} else {
char* buff = (char*)tBuffer;
size_t blockSize = mat->size[mat->dims-1] * mat->elemSize();
size_t firstPartialBlockSize = (mat->size[mat->dims-1] - tempIndices[mat->dims-1]) * mat->step[mat->dims-1];
for (int dim=mat->dims-2; dim>=0 && blockSize == mat->step[dim]; dim--) {
blockSize *= mat->size[dim];
firstPartialBlockSize += (mat->size[dim] - (tempIndices[dim]+1)) * mat->step[dim];
}
size_t copyCount = (countBytes<firstPartialBlockSize)?countBytes:firstPartialBlockSize;
uchar* data = mat->ptr(tempIndices.data());
while(countBytes>0){
memcpy(data, buff, copyCount);
updateIdx(mat, tempIndices, copyCount / mat->elemSize());
countBytes -= copyCount;
buff += copyCount;
copyCount = countBytes<blockSize?countBytes:blockSize;
data = mat->ptr(tempIndices.data());
}
}
return result;
}
- (int)put:(NSArray<NSNumber*>*)indices count:(int)count byteBuffer:(const char*)buffer {
int depth = _nativePtr->depth();
if (depth != CV_8U && depth != CV_8S) {
NSException* exception = [NSException
exceptionWithName:@"UnsupportedOperationException"
reason:[NSString stringWithFormat:@"Invalid depth (%@). Valid depths for this call are CV_8U or CV_8S.", [CvType typeToString:depth]]
userInfo:nil];
@throw exception;
}
return putData(indices, _nativePtr, count, buffer);
}
- (int)put:(NSArray<NSNumber*>*)indices count:(int)count doubleBuffer:(const double*)buffer {
int depth = _nativePtr->depth();
if (depth != CV_64F) {
NSException* exception = [NSException
exceptionWithName:@"UnsupportedOperationException"
reason:[NSString stringWithFormat:@"Invalid depth (%@). Valid depth for this call is CV_64F.", [CvType typeToString:depth]]
userInfo:nil];
@throw exception;
}
return putData(indices, _nativePtr, count, buffer);
}
- (int)put:(NSArray<NSNumber*>*)indices count:(int)count floatBuffer:(const float*)buffer {
int depth = _nativePtr->depth();
if (depth != CV_32F) {
NSException* exception = [NSException
exceptionWithName:@"UnsupportedOperationException"
reason:[NSString stringWithFormat:@"Invalid depth (%@). Valid depth for this call is CV_32F.", [CvType typeToString:depth]]
userInfo:nil];
@throw exception;
}
return putData(indices, _nativePtr, count, buffer);
}
- (int)put:(NSArray<NSNumber*>*)indices count:(int)count intBuffer:(const int*)buffer {
int depth = _nativePtr->depth();
if (depth != CV_32S) {
NSException* exception = [NSException
exceptionWithName:@"UnsupportedOperationException"
reason:[NSString stringWithFormat:@"Invalid depth (%@). Valid depth for this call is CV_32S.", [CvType typeToString:depth]]
userInfo:nil];
@throw exception;
}
return putData(indices, _nativePtr, count, buffer);
}
- (int)put:(NSArray<NSNumber*>*)indices count:(int)count shortBuffer:(const short*)buffer {
int depth = _nativePtr->depth();
if (depth != CV_16S && depth != CV_16U) {
NSException* exception = [NSException
exceptionWithName:@"UnsupportedOperationException"
reason:[NSString stringWithFormat:@"Invalid depth (%@). Valid depths for this call are CV_16S and CV_16U.", [CvType typeToString:depth]]
userInfo:nil];
@throw exception;
}
return putData(indices, _nativePtr, count, buffer);
}
- (int)height {
return [self rows];
}
- (int)width {
return [self cols];
}
@end

View File

@ -0,0 +1,723 @@
//
// MatExt.swift
//
// Created by Giles Payne on 2020/01/19.
//
import Foundation
let OpenCVErrorDomain = "OpenCVErrorDomain"
enum OpenCVError : Int {
case IncompatibleDataType = 10001
case IncompatibleBufferSize
}
func throwIncompatibleDataType(typeName: String) throws {
throw NSError(
domain: OpenCVErrorDomain,
code: OpenCVError.IncompatibleDataType.rawValue,
userInfo: [
NSLocalizedDescriptionKey: "Incompatible Mat type \(typeName)"
]
)
}
func throwIncompatibleBufferSize(count: Int, channels: Int32) throws {
throw NSError(
domain: OpenCVErrorDomain,
code: OpenCVError.IncompatibleBufferSize.rawValue,
userInfo: [
NSLocalizedDescriptionKey: "Provided data element number \(count) should be multiple of the Mat channels count \(channels)"
]
)
}
public typealias T2<T> = (T, T)
public typealias T3<T> = (T, T, T)
public typealias T4<T> = (T, T, T, T)
public extension Mat {
convenience init(rows:Int32, cols:Int32, type:Int32, data:[Int8]) {
let dataObject = data.withUnsafeBufferPointer { Data(buffer: $0) }
self.init(rows: rows, cols: cols, type: type, data: dataObject)
}
convenience init(rows:Int32, cols:Int32, type:Int32, data:[Int8], step:Int) {
let dataObject = data.withUnsafeBufferPointer { Data(buffer: $0) }
self.init(rows: rows, cols: cols, type: type, data: dataObject, step:step)
}
@discardableResult func get(indices:[Int32], data:inout [Int8]) throws -> Int32 {
let channels = CvType.channels(Int32(type()))
if Int32(data.count) % channels != 0 {
try throwIncompatibleBufferSize(count: data.count, channels: channels)
} else if depth() != CvType.CV_8U && depth() != CvType.CV_8S {
try throwIncompatibleDataType(typeName: CvType.type(toString: type()))
}
let count = Int32(data.count)
return data.withUnsafeMutableBufferPointer { body in
return __get(indices as [NSNumber], count: count, byteBuffer: body.baseAddress!)
}
}
@discardableResult func get(indices:[Int32], data:inout [UInt8]) throws -> Int32 {
let channels = CvType.channels(Int32(type()))
if Int32(data.count) % channels != 0 {
try throwIncompatibleBufferSize(count: data.count, channels: channels)
} else if depth() != CvType.CV_8U {
try throwIncompatibleDataType(typeName: CvType.type(toString: type()))
}
let count = Int32(data.count)
return data.withUnsafeMutableBufferPointer { body in
body.withMemoryRebound(to: Int8.self) { reboundBody in
return __get(indices as [NSNumber], count: count, byteBuffer: reboundBody.baseAddress!)
}
}
}
@discardableResult func get(indices:[Int32], data:inout [Double]) throws -> Int32 {
let channels = CvType.channels(Int32(type()))
if Int32(data.count) % channels != 0 {
try throwIncompatibleBufferSize(count: data.count, channels: channels)
} else if depth() != CvType.CV_64F {
try throwIncompatibleDataType(typeName: CvType.type(toString: type()))
}
let count = Int32(data.count)
return data.withUnsafeMutableBufferPointer { body in
return __get(indices as [NSNumber], count: count, doubleBuffer: body.baseAddress!)
}
}
@discardableResult func get(indices:[Int32], data:inout [Float]) throws -> Int32 {
let channels = CvType.channels(Int32(type()))
if Int32(data.count) % channels != 0 {
try throwIncompatibleBufferSize(count: data.count, channels: channels)
} else if depth() != CvType.CV_32F {
try throwIncompatibleDataType(typeName: CvType.type(toString: type()))
}
let count = Int32(data.count)
return data.withUnsafeMutableBufferPointer { body in
return __get(indices as [NSNumber], count: count, floatBuffer: body.baseAddress!)
}
}
@discardableResult func get(indices:[Int32], data:inout [Int32]) throws -> Int32 {
let channels = CvType.channels(Int32(type()))
if Int32(data.count) % channels != 0 {
try throwIncompatibleBufferSize(count: data.count, channels: channels)
} else if depth() != CvType.CV_32S {
try throwIncompatibleDataType(typeName: CvType.type(toString: type()))
}
let count = Int32(data.count)
return data.withUnsafeMutableBufferPointer { body in
return __get(indices as [NSNumber], count: count, intBuffer: body.baseAddress!)
}
}
@discardableResult func get(indices:[Int32], data:inout [Int16]) throws -> Int32 {
let channels = CvType.channels(Int32(type()))
if Int32(data.count) % channels != 0 {
try throwIncompatibleBufferSize(count: data.count, channels: channels)
} else if depth() != CvType.CV_16U && depth() != CvType.CV_16S {
try throwIncompatibleDataType(typeName: CvType.type(toString: type()))
}
let count = Int32(data.count)
return data.withUnsafeMutableBufferPointer { body in
return __get(indices as [NSNumber], count: count, shortBuffer: body.baseAddress!)
}
}
@discardableResult func get(indices:[Int32], data:inout [UInt16]) throws -> Int32 {
let channels = CvType.channels(Int32(type()))
if Int32(data.count) % channels != 0 {
try throwIncompatibleBufferSize(count: data.count, channels: channels)
} else if depth() != CvType.CV_16U {
try throwIncompatibleDataType(typeName: CvType.type(toString: type()))
}
let count = Int32(data.count)
return data.withUnsafeMutableBufferPointer { body in
body.withMemoryRebound(to: Int16.self) { reboundBody in
return __get(indices as [NSNumber], count: count, shortBuffer: reboundBody.baseAddress!)
}
}
}
@discardableResult func get(row: Int32, col: Int32, data:inout [Int8]) throws -> Int32 {
return try get(indices: [row, col], data: &data)
}
@discardableResult func get(row: Int32, col: Int32, data:inout [UInt8]) throws -> Int32 {
return try get(indices: [row, col], data: &data)
}
@discardableResult func get(row: Int32, col: Int32, data:inout [Double]) throws -> Int32 {
return try get(indices: [row, col], data: &data)
}
@discardableResult func get(row: Int32, col: Int32, data:inout [Float]) throws -> Int32 {
return try get(indices: [row, col], data: &data)
}
@discardableResult func get(row: Int32, col: Int32, data:inout [Int32]) throws -> Int32 {
return try get(indices: [row, col], data: &data)
}
@discardableResult func get(row: Int32, col: Int32, data:inout [Int16]) throws -> Int32 {
return try get(indices: [row, col], data: &data)
}
@discardableResult func get(row: Int32, col: Int32, data:inout [UInt16]) throws -> Int32 {
return try get(indices: [row, col], data: &data)
}
@discardableResult func put(indices:[Int32], data:[Int8]) throws -> Int32 {
let channels = CvType.channels(Int32(type()))
if Int32(data.count) % channels != 0 {
try throwIncompatibleBufferSize(count: data.count, channels: channels)
} else if depth() != CvType.CV_8U && depth() != CvType.CV_8S {
try throwIncompatibleDataType(typeName: CvType.type(toString: type()))
}
let count = Int32(data.count)
return data.withUnsafeBufferPointer { body in
return __put(indices as [NSNumber], count: count, byteBuffer: body.baseAddress!)
}
}
@discardableResult func put(indices:[Int32], data:[UInt8]) throws -> Int32 {
let channels = CvType.channels(Int32(type()))
if Int32(data.count) % channels != 0 {
try throwIncompatibleBufferSize(count: data.count, channels: channels)
} else if depth() != CvType.CV_8U {
try throwIncompatibleDataType(typeName: CvType.type(toString: type()))
}
let count = Int32(data.count)
return data.withUnsafeBufferPointer { body in
body.withMemoryRebound(to: Int8.self) { reboundBody in
return __put(indices as [NSNumber], count: count, byteBuffer: reboundBody.baseAddress!)
}
}
}
@discardableResult func put(indices:[Int32], data:[Int8], offset: Int, length: Int32) throws -> Int32 {
let channels = CvType.channels(Int32(type()))
if Int32(data.count) % channels != 0 {
try throwIncompatibleBufferSize(count: data.count, channels: channels)
} else if depth() != CvType.CV_8U && depth() != CvType.CV_8S {
try throwIncompatibleDataType(typeName: CvType.type(toString: type()))
}
return data.withUnsafeBufferPointer { body in
return __put(indices as [NSNumber], count: length, byteBuffer: body.baseAddress! + offset)
}
}
// unlike other put:indices:data functions this one (with [Double]) should convert input values to correct type
@discardableResult func put(indices:[Int32], data:[Double]) throws -> Int32 {
let channels = CvType.channels(Int32(type()))
if Int32(data.count) % channels != 0 {
try throwIncompatibleBufferSize(count: data.count, channels: channels)
}
if depth() == CvType.CV_64F {
let count = Int32(data.count)
return data.withUnsafeBufferPointer { body in
return __put(indices as [NSNumber], count: count, doubleBuffer: body.baseAddress!)
}
} else {
return __put(indices as [NSNumber], data: data as [NSNumber])
}
}
@discardableResult func put(indices:[Int32], data:[Float]) throws -> Int32 {
let channels = CvType.channels(Int32(type()))
if Int32(data.count) % channels != 0 {
try throwIncompatibleBufferSize(count: data.count, channels: channels)
} else if depth() != CvType.CV_32F {
try throwIncompatibleDataType(typeName: CvType.type(toString: type()))
}
let count = Int32(data.count)
return data.withUnsafeBufferPointer { body in
return __put(indices as [NSNumber], count: count, floatBuffer: body.baseAddress!)
}
}
@discardableResult func put(indices:[Int32], data:[Int32]) throws -> Int32 {
let channels = CvType.channels(Int32(type()))
if Int32(data.count) % channels != 0 {
try throwIncompatibleBufferSize(count: data.count, channels: channels)
} else if depth() != CvType.CV_32S {
try throwIncompatibleDataType(typeName: CvType.type(toString: type()))
}
let count = Int32(data.count)
return data.withUnsafeBufferPointer { body in
return __put(indices as [NSNumber], count: count, intBuffer: body.baseAddress!)
}
}
@discardableResult func put(indices:[Int32], data:[Int16]) throws -> Int32 {
let channels = CvType.channels(Int32(type()))
if Int32(data.count) % channels != 0 {
try throwIncompatibleBufferSize(count: data.count, channels: channels)
} else if depth() != CvType.CV_16U && depth() != CvType.CV_16S {
try throwIncompatibleDataType(typeName: CvType.type(toString: type()))
}
let count = Int32(data.count)
return data.withUnsafeBufferPointer { body in
return __put(indices as [NSNumber], count: count, shortBuffer: body.baseAddress!)
}
}
@discardableResult func put(indices:[Int32], data:[UInt16]) throws -> Int32 {
let channels = CvType.channels(Int32(type()))
if Int32(data.count) % channels != 0 {
try throwIncompatibleBufferSize(count: data.count, channels: channels)
} else if depth() != CvType.CV_16U {
try throwIncompatibleDataType(typeName: CvType.type(toString: type()))
}
let count = Int32(data.count)
return data.withUnsafeBufferPointer { body in
body.withMemoryRebound(to: Int16.self) { reboundBody in
return __put(indices as [NSNumber], count: count, shortBuffer: reboundBody.baseAddress!)
}
}
}
@discardableResult func put(row: Int32, col: Int32, data:[Int8]) throws -> Int32 {
return try put(indices: [row, col], data: data)
}
@discardableResult func put(row: Int32, col: Int32, data:[UInt8]) throws -> Int32 {
return try put(indices: [row, col], data: data)
}
@discardableResult func put(row: Int32, col: Int32, data: [Int8], offset: Int, length: Int32) throws -> Int32 {
return try put(indices: [row, col], data: data, offset: offset, length: length)
}
@discardableResult func put(row: Int32, col: Int32, data: [Double]) throws -> Int32 {
return try put(indices: [row, col], data: data)
}
@discardableResult func put(row: Int32, col: Int32, data: [Float]) throws -> Int32 {
return try put(indices: [row, col], data: data)
}
@discardableResult func put(row: Int32, col: Int32, data: [Int32]) throws -> Int32 {
return try put(indices: [row, col], data: data)
}
@discardableResult func put(row: Int32, col: Int32, data: [Int16]) throws -> Int32 {
return try put(indices: [row, col], data: data)
}
@discardableResult func put(row: Int32, col: Int32, data: [UInt16]) throws -> Int32 {
return try put(indices: [row, col], data: data)
}
@discardableResult func get(row: Int32, col: Int32) -> [Double] {
return get(indices: [row, col])
}
@discardableResult func get(indices: [Int32]) -> [Double] {
return __get(indices as [NSNumber]) as! [Double]
}
}
public protocol Atable {
static func getAt(m: Mat, indices:[Int32]) -> Self
static func putAt(m: Mat, indices:[Int32], v: Self)
static func getAt2c(m: Mat, indices:[Int32]) -> (Self, Self)
static func putAt2c(m: Mat, indices:[Int32], v: (Self, Self))
static func getAt3c(m: Mat, indices:[Int32]) -> (Self, Self, Self)
static func putAt3c(m: Mat, indices:[Int32], v: (Self, Self, Self))
static func getAt4c(m: Mat, indices:[Int32]) -> (Self, Self, Self, Self)
static func putAt4c(m: Mat, indices:[Int32], v: (Self, Self, Self, Self))
}
public class MatAt<N: Atable> {
init(mat: Mat, indices: [Int32]) {
self.mat = mat
self.indices = indices
}
private let mat: Mat
private let indices: [Int32]
public var v: N {
get {
return N.getAt(m: mat, indices: indices)
}
set(value) {
N.putAt(m: mat, indices: indices, v: value)
}
}
public var v2c: (N, N) {
get {
return N.getAt2c(m: mat, indices: indices)
}
set(value) {
N.putAt2c(m: mat, indices: indices, v: value)
}
}
public var v3c: (N, N, N) {
get {
return N.getAt3c(m: mat, indices: indices)
}
set(value) {
N.putAt3c(m: mat, indices: indices, v: value)
}
}
public var v4c: (N, N, N, N) {
get {
return N.getAt4c(m: mat, indices: indices)
}
set(value) {
N.putAt4c(m: mat, indices: indices, v: value)
}
}
}
extension UInt8: Atable {
public static func getAt(m: Mat, indices:[Int32]) -> UInt8 {
var tmp = [UInt8](repeating: 0, count: 1)
try! m.get(indices: indices, data: &tmp)
return tmp[0]
}
public static func putAt(m: Mat, indices: [Int32], v: UInt8) {
let tmp = [v]
try! m.put(indices: indices, data: tmp)
}
public static func getAt2c(m: Mat, indices:[Int32]) -> (UInt8, UInt8) {
var tmp = [UInt8](repeating: 0, count: 2)
try! m.get(indices: indices, data: &tmp)
return (tmp[0], tmp[1])
}
public static func putAt2c(m: Mat, indices: [Int32], v: (UInt8, UInt8)) {
let tmp = [v.0, v.1]
try! m.put(indices: indices, data: tmp)
}
public static func getAt3c(m: Mat, indices:[Int32]) -> (UInt8, UInt8, UInt8) {
var tmp = [UInt8](repeating: 0, count: 3)
try! m.get(indices: indices, data: &tmp)
return (tmp[0], tmp[1], tmp[2])
}
public static func putAt3c(m: Mat, indices: [Int32], v: (UInt8, UInt8, UInt8)) {
let tmp = [v.0, v.1, v.2]
try! m.put(indices: indices, data: tmp)
}
public static func getAt4c(m: Mat, indices:[Int32]) -> (UInt8, UInt8, UInt8, UInt8) {
var tmp = [UInt8](repeating: 0, count: 4)
try! m.get(indices: indices, data: &tmp)
return (tmp[0], tmp[1], tmp[2], tmp[3])
}
public static func putAt4c(m: Mat, indices: [Int32], v: (UInt8, UInt8, UInt8, UInt8)) {
let tmp = [v.0, v.1, v.2, v.3]
try! m.put(indices: indices, data: tmp)
}
}
extension Int8: Atable {
public static func getAt(m: Mat, indices:[Int32]) -> Int8 {
var tmp = [Int8](repeating: 0, count: 1)
try! m.get(indices: indices, data: &tmp)
return tmp[0]
}
public static func putAt(m: Mat, indices: [Int32], v: Int8) {
let tmp = [v]
try! m.put(indices: indices, data: tmp)
}
public static func getAt2c(m: Mat, indices:[Int32]) -> (Int8, Int8) {
var tmp = [Int8](repeating: 0, count: 2)
try! m.get(indices: indices, data: &tmp)
return (tmp[0], tmp[1])
}
public static func putAt2c(m: Mat, indices: [Int32], v: (Int8, Int8)) {
let tmp = [v.0, v.1]
try! m.put(indices: indices, data: tmp)
}
public static func getAt3c(m: Mat, indices:[Int32]) -> (Int8, Int8, Int8) {
var tmp = [Int8](repeating: 0, count: 3)
try! m.get(indices: indices, data: &tmp)
return (tmp[0], tmp[1], tmp[2])
}
public static func putAt3c(m: Mat, indices: [Int32], v: (Int8, Int8, Int8)) {
let tmp = [v.0, v.1, v.2]
try! m.put(indices: indices, data: tmp)
}
public static func getAt4c(m: Mat, indices:[Int32]) -> (Int8, Int8, Int8, Int8) {
var tmp = [Int8](repeating: 0, count: 4)
try! m.get(indices: indices, data: &tmp)
return (tmp[0], tmp[1], tmp[2], tmp[3])
}
public static func putAt4c(m: Mat, indices: [Int32], v: (Int8, Int8, Int8, Int8)) {
let tmp = [v.0, v.1, v.2, v.3]
try! m.put(indices: indices, data: tmp)
}
}
extension Double: Atable {
public static func getAt(m: Mat, indices:[Int32]) -> Double {
var tmp = [Double](repeating: 0, count: 1)
try! m.get(indices: indices, data: &tmp)
return tmp[0]
}
public static func putAt(m: Mat, indices: [Int32], v: Double) {
let tmp = [v]
try! m.put(indices: indices, data: tmp)
}
public static func getAt2c(m: Mat, indices:[Int32]) -> (Double, Double) {
var tmp = [Double](repeating: 0, count: 2)
try! m.get(indices: indices, data: &tmp)
return (tmp[0], tmp[1])
}
public static func putAt2c(m: Mat, indices: [Int32], v: (Double, Double)) {
let tmp = [v.0, v.1]
try! m.put(indices: indices, data: tmp)
}
public static func getAt3c(m: Mat, indices:[Int32]) -> (Double, Double, Double) {
var tmp = [Double](repeating: 0, count: 3)
try! m.get(indices: indices, data: &tmp)
return (tmp[0], tmp[1], tmp[2])
}
public static func putAt3c(m: Mat, indices: [Int32], v: (Double, Double, Double)) {
let tmp = [v.0, v.1, v.2]
try! m.put(indices: indices, data: tmp)
}
public static func getAt4c(m: Mat, indices:[Int32]) -> (Double, Double, Double, Double) {
var tmp = [Double](repeating: 0, count: 4)
try! m.get(indices: indices, data: &tmp)
return (tmp[0], tmp[1], tmp[2], tmp[3])
}
public static func putAt4c(m: Mat, indices: [Int32], v: (Double, Double, Double, Double)) {
let tmp = [v.0, v.1, v.2, v.3]
try! m.put(indices: indices, data: tmp)
}
}
extension Float: Atable {
public static func getAt(m: Mat, indices:[Int32]) -> Float {
var tmp = [Float](repeating: 0, count: 1)
try! m.get(indices: indices, data: &tmp)
return tmp[0]
}
public static func putAt(m: Mat, indices: [Int32], v: Float) {
let tmp = [v]
try! m.put(indices: indices, data: tmp)
}
public static func getAt2c(m: Mat, indices:[Int32]) -> (Float, Float) {
var tmp = [Float](repeating: 0, count: 2)
try! m.get(indices: indices, data: &tmp)
return (tmp[0], tmp[1])
}
public static func putAt2c(m: Mat, indices: [Int32], v: (Float, Float)) {
let tmp = [v.0, v.1]
try! m.put(indices: indices, data: tmp)
}
public static func getAt3c(m: Mat, indices:[Int32]) -> (Float, Float, Float) {
var tmp = [Float](repeating: 0, count: 3)
try! m.get(indices: indices, data: &tmp)
return (tmp[0], tmp[1], tmp[2])
}
public static func putAt3c(m: Mat, indices: [Int32], v: (Float, Float, Float)) {
let tmp = [v.0, v.1, v.2]
try! m.put(indices: indices, data: tmp)
}
public static func getAt4c(m: Mat, indices:[Int32]) -> (Float, Float, Float, Float) {
var tmp = [Float](repeating: 0, count: 4)
try! m.get(indices: indices, data: &tmp)
return (tmp[0], tmp[1], tmp[2], tmp[3])
}
public static func putAt4c(m: Mat, indices: [Int32], v: (Float, Float, Float, Float)) {
let tmp = [v.0, v.1, v.2, v.3]
try! m.put(indices: indices, data: tmp)
}
}
extension Int32: Atable {
public static func getAt(m: Mat, indices:[Int32]) -> Int32 {
var tmp = [Int32](repeating: 0, count: 1)
try! m.get(indices: indices, data: &tmp)
return tmp[0]
}
public static func putAt(m: Mat, indices: [Int32], v: Int32) {
let tmp = [v]
try! m.put(indices: indices, data: tmp)
}
public static func getAt2c(m: Mat, indices:[Int32]) -> (Int32, Int32) {
var tmp = [Int32](repeating: 0, count: 2)
try! m.get(indices: indices, data: &tmp)
return (tmp[0], tmp[1])
}
public static func putAt2c(m: Mat, indices: [Int32], v: (Int32, Int32)) {
let tmp = [v.0, v.1]
try! m.put(indices: indices, data: tmp)
}
public static func getAt3c(m: Mat, indices:[Int32]) -> (Int32, Int32, Int32) {
var tmp = [Int32](repeating: 0, count: 3)
try! m.get(indices: indices, data: &tmp)
return (tmp[0], tmp[1], tmp[2])
}
public static func putAt3c(m: Mat, indices: [Int32], v: (Int32, Int32, Int32)) {
let tmp = [v.0, v.1, v.2]
try! m.put(indices: indices, data: tmp)
}
public static func getAt4c(m: Mat, indices:[Int32]) -> (Int32, Int32, Int32, Int32) {
var tmp = [Int32](repeating: 0, count: 4)
try! m.get(indices: indices, data: &tmp)
return (tmp[0], tmp[1], tmp[2], tmp[3])
}
public static func putAt4c(m: Mat, indices: [Int32], v: (Int32, Int32, Int32, Int32)) {
let tmp = [v.0, v.1, v.2, v.3]
try! m.put(indices: indices, data: tmp)
}
}
extension UInt16: Atable {
public static func getAt(m: Mat, indices:[Int32]) -> UInt16 {
var tmp = [UInt16](repeating: 0, count: 1)
try! m.get(indices: indices, data: &tmp)
return tmp[0]
}
public static func putAt(m: Mat, indices: [Int32], v: UInt16) {
let tmp = [v]
try! m.put(indices: indices, data: tmp)
}
public static func getAt2c(m: Mat, indices:[Int32]) -> (UInt16, UInt16) {
var tmp = [UInt16](repeating: 0, count: 2)
try! m.get(indices: indices, data: &tmp)
return (tmp[0], tmp[1])
}
public static func putAt2c(m: Mat, indices: [Int32], v: (UInt16, UInt16)) {
let tmp = [v.0, v.1]
try! m.put(indices: indices, data: tmp)
}
public static func getAt3c(m: Mat, indices:[Int32]) -> (UInt16, UInt16, UInt16) {
var tmp = [UInt16](repeating: 0, count: 3)
try! m.get(indices: indices, data: &tmp)
return (tmp[0], tmp[1], tmp[2])
}
public static func putAt3c(m: Mat, indices: [Int32], v: (UInt16, UInt16, UInt16)) {
let tmp = [v.0, v.1, v.2]
try! m.put(indices: indices, data: tmp)
}
public static func getAt4c(m: Mat, indices:[Int32]) -> (UInt16, UInt16, UInt16, UInt16) {
var tmp = [UInt16](repeating: 0, count: 4)
try! m.get(indices: indices, data: &tmp)
return (tmp[0], tmp[1], tmp[2], tmp[3])
}
public static func putAt4c(m: Mat, indices: [Int32], v: (UInt16, UInt16, UInt16, UInt16)) {
let tmp = [v.0, v.1, v.2, v.3]
try! m.put(indices: indices, data: tmp)
}
}
extension Int16: Atable {
public static func getAt(m: Mat, indices:[Int32]) -> Int16 {
var tmp = [Int16](repeating: 0, count: 1)
try! m.get(indices: indices, data: &tmp)
return tmp[0]
}
public static func putAt(m: Mat, indices: [Int32], v: Int16) {
let tmp = [v]
try! m.put(indices: indices, data: tmp)
}
public static func getAt2c(m: Mat, indices:[Int32]) -> (Int16, Int16) {
var tmp = [Int16](repeating: 0, count: 2)
try! m.get(indices: indices, data: &tmp)
return (tmp[0], tmp[1])
}
public static func putAt2c(m: Mat, indices: [Int32], v: (Int16, Int16)) {
let tmp = [v.0, v.1]
try! m.put(indices: indices, data: tmp)
}
public static func getAt3c(m: Mat, indices:[Int32]) -> (Int16, Int16, Int16) {
var tmp = [Int16](repeating: 0, count: 3)
try! m.get(indices: indices, data: &tmp)
return (tmp[0], tmp[1], tmp[2])
}
public static func putAt3c(m: Mat, indices: [Int32], v: (Int16, Int16, Int16)) {
let tmp = [v.0, v.1, v.2]
try! m.put(indices: indices, data: tmp)
}
public static func getAt4c(m: Mat, indices:[Int32]) -> (Int16, Int16, Int16, Int16) {
var tmp = [Int16](repeating: 0, count: 4)
try! m.get(indices: indices, data: &tmp)
return (tmp[0], tmp[1], tmp[2], tmp[3])
}
public static func putAt4c(m: Mat, indices: [Int32], v: (Int16, Int16, Int16, Int16)) {
let tmp = [v.0, v.1, v.2, v.3]
try! m.put(indices: indices, data: tmp)
}
}
/***
* Example use:
*
* let elemantVal: UInt8 = mat.at(row: 50, col: 50).v
* mat.at(row: 50, col: 50).v = 245
*
*/
public extension Mat {
func at<N: Atable>(row: Int32, col: Int32) -> MatAt<N> {
return MatAt(mat: self, indices: [row, col])
}
func at<N: Atable>(indices:[Int32]) -> MatAt<N> {
return MatAt(mat: self, indices: indices)
}
}
public extension Mat {
static func *(lhs:Mat, rhs: Mat) -> Mat {
return lhs.matMul(rhs)
}
}

View File

@ -0,0 +1,62 @@
//
// MatOfByte.h
//
// Created by Giles Payne on 2019/12/26.
//
#pragma once
#import "Mat.h"
NS_ASSUME_NONNULL_BEGIN
/**
* Mat representation of an array of bytes
*/
CV_EXPORTS @interface MatOfByte : Mat
#pragma mark - Constructors
#ifdef __cplusplus
- (instancetype)initWithNativeMat:(cv::Mat*)nativeMat;
#endif
/**
* Create MatOfByte from Mat object
* @param mat Mat object from which to create MatOfByte
*/
- (instancetype)initWithMat:(Mat*)mat;
/**
* Create MatOfByte from array
* @param array Array from which to create MatOfByte
*/
- (instancetype)initWithArray:(NSArray<NSNumber*>*)array;
#pragma mark - Methods
/**
* Allocate specified number of elements
* @param elemNumber Number of elements
*/
- (void)alloc:(int)elemNumber;
/**
* Populate Mat with elements of an array
* @param array Array with which to populate the Mat
*/
- (void)fromArray:(NSArray<NSNumber*>*)array;
/**
* Output Mat elements as an array
*/
- (NSArray<NSNumber*>*)toArray;
/**
* Total number of values in Mat
*/
- (int)length;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,69 @@
//
// MatOfByte.mm
//
// Created by Giles Payne on 2019/12/26.
//
#import "MatOfByte.h"
#import "Range.h"
#import "CvType.h"
#import "ArrayUtil.h"
@implementation MatOfByte
static const int _depth = CV_8U;
static const int _channels = 1;
#ifdef __cplusplus
- (instancetype)initWithNativeMat:(cv::Mat*)nativeMat {
self = [super initWithNativeMat:nativeMat];
if (self && ![self empty] && [self checkVector:_channels depth:_depth] < 0) {
@throw [NSException exceptionWithName:NSInvalidArgumentException reason:@"Incompatible Mat" userInfo:nil];
}
return self;
}
#endif
- (instancetype)initWithMat:(Mat*)mat {
self = [super initWithMat:mat rowRange:[Range all]];
if (self && ![self empty] && [self checkVector:_channels depth:_depth] < 0) {
@throw [NSException exceptionWithName:NSInvalidArgumentException reason:@"Incompatible Mat" userInfo:nil];
}
return self;
}
- (instancetype)initWithArray:(NSArray<NSNumber*>*)array {
self = [super init];
if (self) {
[self fromArray:array];
}
return self;
}
- (void)alloc:(int)elemNumber {
if (elemNumber>0) {
[super create:elemNumber cols:1 type:[CvType makeType:_depth channels:_channels]];
}
}
- (void)fromArray:(NSArray<NSNumber*>*)array {
[self alloc:(int)array.count / _channels];
[self put:0 col:0 data:array];
}
- (NSArray<NSNumber*>*)toArray {
int length = [self length];
NSMutableArray<NSNumber*>* data = createArrayWithSize(length, @0.0);
[self get:0 col:0 data:data];
return data;
}
- (int)length {
int num = [self checkVector:_channels depth:_depth];
if (num < 0) {
@throw [NSException exceptionWithName:NSInternalInconsistencyException reason:@"Incompatible Mat" userInfo:nil];
}
return num * _channels;
}
@end

View File

@ -0,0 +1,64 @@
//
// MatOfDMatch.h
//
// Created by Giles Payne on 2019/12/27.
//
#pragma once
#import "Mat.h"
@class DMatch;
NS_ASSUME_NONNULL_BEGIN
/**
* Mat representation of an array of DMatch objects
*/
CV_EXPORTS @interface MatOfDMatch : Mat
#pragma mark - Constructors
#ifdef __cplusplus
- (instancetype)initWithNativeMat:(cv::Mat*)nativeMat;
#endif
/**
* Create MatOfDMatch from Mat object
* @param mat Mat object from which to create MatOfDMatch
*/
- (instancetype)initWithMat:(Mat*)mat;
/**
* Create MatOfDMatch from array
* @param array Array from which to create MatOfDMatch
*/
- (instancetype)initWithArray:(NSArray<DMatch*>*)array;
#pragma mark - Methods
/**
* Allocate specified number of elements
* @param elemNumber Number of elements
*/
- (void)alloc:(int)elemNumber;
/**
* Populate Mat with elements of an array
* @param array Array with which to populate the Mat
*/
- (void)fromArray:(NSArray<DMatch*>*)array;
/**
* Output Mat elements as an array of DMatch objects
*/
- (NSArray<DMatch*>*)toArray;
/**
* Total number of values in Mat
*/
- (int)length;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,83 @@
//
// MatOfDMatch.m
//
// Created by Giles Payne on 2019/12/27.
//
#import "MatOfDMatch.h"
#import "Range.h"
#import "DMatch.h"
#import "CvType.h"
#import "ArrayUtil.h"
@implementation MatOfDMatch
static const int _depth = CV_32F;
static const int _channels = 4;
#ifdef __cplusplus
- (instancetype)initWithNativeMat:(cv::Mat*)nativeMat {
self = [super initWithNativeMat:nativeMat];
if (self && ![self empty] && [self checkVector:_channels depth:_depth] < 0) {
@throw [NSException exceptionWithName:NSInvalidArgumentException reason:@"Incompatible Mat" userInfo:nil];
}
return self;
}
#endif
- (instancetype)initWithMat:(Mat*)mat {
self = [super initWithMat:mat rowRange:[Range all]];
if (self && ![self empty] && [self checkVector:_channels depth:_depth] < 0) {
@throw [NSException exceptionWithName:NSInvalidArgumentException reason:@"Incompatible Mat" userInfo:nil];
}
return self;
}
- (instancetype)initWithArray:(NSArray<DMatch*>*)array {
self = [super init];
if (self) {
[self fromArray:array];
}
return self;
}
- (void)alloc:(int)elemNumber {
if (elemNumber>0) {
[super create:elemNumber cols:1 type:[CvType makeType:_depth channels:_channels]];
}
}
- (void)fromArray:(NSArray<DMatch*>*)array {
NSMutableArray<NSNumber*>* data = [[NSMutableArray alloc] initWithCapacity:array.count * _channels];
for (int index = 0; index < (int)array.count; index++) {
data[_channels * index] = [NSNumber numberWithFloat:array[index].queryIdx];
data[_channels * index + 1] = [NSNumber numberWithFloat:array[index].trainIdx];
data[_channels * index + 2] = [NSNumber numberWithFloat:array[index].imgIdx];
data[_channels * index + 3] = [NSNumber numberWithFloat:array[index].distance];
}
[self alloc:(int)array.count];
[self put:0 col:0 data:data];
}
- (NSArray<DMatch*>*)toArray {
int length = [self length] / _channels;
NSMutableArray<DMatch*>* ret = createArrayWithSize(length, [DMatch new]);
if (length > 0) {
NSMutableArray<NSNumber*>* data = createArrayWithSize([self length], @0.0);
[self get:0 col:0 data:data];
for (int index = 0; index < length; index++) {
ret[index] = [[DMatch alloc] initWithQueryIdx:data[index * _channels].intValue trainIdx:data[index * _channels + 1].intValue imgIdx:data[index * _channels + 2].intValue distance:data[index * _channels + 3].floatValue];
}
}
return ret;
}
- (int)length {
int num = [self checkVector:_channels depth:_depth];
if (num < 0) {
@throw [NSException exceptionWithName:NSInternalInconsistencyException reason:@"Incompatible Mat" userInfo:nil];
}
return num * _channels;
}
@end

View File

@ -0,0 +1,63 @@
//
// MatOfDouble.h
//
// Created by Giles Payne on 2019/12/26.
//
#pragma once
#import "Mat.h"
NS_ASSUME_NONNULL_BEGIN
/**
* Mat representation of an array of doubles
*/
CV_EXPORTS @interface MatOfDouble : Mat
#pragma mark - Constructors
#ifdef __cplusplus
- (instancetype)initWithNativeMat:(cv::Mat*)nativeMat;
#endif
/**
* Create MatOfDouble from Mat object
* @param mat Mat object from which to create MatOfDouble
*/
- (instancetype)initWithMat:(Mat*)mat;
/**
* Create MatOfDouble from array
* @param array Array from which to create MatOfDouble
*/
- (instancetype)initWithArray:(NSArray<NSNumber*>*)array;
#pragma mark - Methods
/**
* Allocate specified number of elements
* @param elemNumber Number of elements
*/
- (void)alloc:(int)elemNumber;
/**
* Populate Mat with elements of an array
* @param array Array with which to populate the Mat
*/
- (void)fromArray:(NSArray<NSNumber*>*)array;
/**
* Output Mat elements as an array
*/
- (NSArray<NSNumber*>*)toArray;
/**
* Total number of values in Mat
*/
- (int)length;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,69 @@
//
// MatOfDouble.mm
//
// Created by Giles Payne on 2019/12/26.
//
#import "MatOfDouble.h"
#import "Range.h"
#import "CvType.h"
#import "ArrayUtil.h"
@implementation MatOfDouble
static const int _depth = CV_64F;
static const int _channels = 1;
#ifdef __cplusplus
- (instancetype)initWithNativeMat:(cv::Mat*)nativeMat {
self = [super initWithNativeMat:nativeMat];
if (self && ![self empty] && [self checkVector:_channels depth:_depth] < 0) {
@throw [NSException exceptionWithName:NSInvalidArgumentException reason:@"Incompatible Mat" userInfo:nil];
}
return self;
}
#endif
- (instancetype)initWithMat:(Mat*)mat {
self = [super initWithMat:mat rowRange:[Range all]];
if (self && ![self empty] && [self checkVector:_channels depth:_depth] < 0) {
@throw [NSException exceptionWithName:NSInvalidArgumentException reason:@"Incompatible Mat" userInfo:nil];
}
return self;
}
- (instancetype)initWithArray:(NSArray<NSNumber*>*)array {
self = [super init];
if (self) {
[self fromArray:array];
}
return self;
}
- (void)alloc:(int)elemNumber {
if (elemNumber>0) {
[super create:elemNumber cols:1 type:[CvType makeType:_depth channels:_channels]];
}
}
- (void)fromArray:(NSArray<NSNumber*>*)array {
[self alloc:(int)array.count / _channels];
[self put:0 col:0 data:array];
}
- (NSArray<NSNumber*>*)toArray {
int length = [self length];
NSMutableArray<NSNumber*>* data = createArrayWithSize(length, @0.0);
[self get:0 col:0 data:data];
return data;
}
- (int)length {
int num = [self checkVector:_channels depth:_depth];
if (num < 0) {
@throw [NSException exceptionWithName:NSInternalInconsistencyException reason:@"Incompatible Mat" userInfo:nil];
}
return num * _channels;
}
@end

View File

@ -0,0 +1,60 @@
//
// MatOfFloat.h
//
// Created by Giles Payne on 2019/12/26.
//
#pragma once
#import "Mat.h"
NS_ASSUME_NONNULL_BEGIN
/**
* Mat representation of an array of floats
*/
CV_EXPORTS @interface MatOfFloat : Mat
#ifdef __cplusplus
- (instancetype)initWithNativeMat:(cv::Mat*)nativeMat;
#endif
/**
* Create MatOfFloat from Mat object
* @param mat Mat object from which to create MatOfFloat
*/
- (instancetype)initWithMat:(Mat*)mat;
/**
* Create MatOfFloat from array
* @param array Array from which to create MatOfFloat
*/
- (instancetype)initWithArray:(NSArray<NSNumber*>*)array;
#pragma mark - Methods
/**
* Allocate specified number of elements
* @param elemNumber Number of elements
*/
- (void)alloc:(int)elemNumber;
/**
* Populate Mat with elements of an array
* @param array Array with which to populate the Mat
*/
- (void)fromArray:(NSArray<NSNumber*>*)array;
/**
* Output Mat elements as an array
*/
- (NSArray<NSNumber*>*)toArray;
/**
* Total number of values in Mat
*/
- (int)length;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,69 @@
//
// MatOfFloat.mm
//
// Created by Giles Payne on 2019/12/26.
//
#import "MatOfFloat.h"
#import "Range.h"
#import "CvType.h"
#import "ArrayUtil.h"
@implementation MatOfFloat
static const int _depth = CV_32F;
static const int _channels = 1;
#ifdef __cplusplus
- (instancetype)initWithNativeMat:(cv::Mat*)nativeMat {
self = [super initWithNativeMat:nativeMat];
if (self && ![self empty] && [self checkVector:_channels depth:_depth] < 0) {
@throw [NSException exceptionWithName:NSInvalidArgumentException reason:@"Incompatible Mat" userInfo:nil];
}
return self;
}
#endif
- (instancetype)initWithMat:(Mat*)mat {
self = [super initWithMat:mat rowRange:[Range all]];
if (self && ![self empty] && [self checkVector:_channels depth:_depth] < 0) {
@throw [NSException exceptionWithName:NSInvalidArgumentException reason:@"Incompatible Mat" userInfo:nil];
}
return self;
}
- (instancetype)initWithArray:(NSArray<NSNumber*>*)array {
self = [super init];
if (self) {
[self fromArray:array];
}
return self;
}
- (void)alloc:(int)elemNumber {
if (elemNumber>0) {
[super create:elemNumber cols:1 type:[CvType makeType:_depth channels:_channels]];
}
}
- (void)fromArray:(NSArray<NSNumber*>*)array {
[self alloc:(int)array.count / _channels];
[self put:0 col:0 data:array];
}
- (NSArray<NSNumber*>*)toArray {
int length = [self length];
NSMutableArray<NSNumber*>* data = createArrayWithSize(length, @0.0);
[self get:0 col:0 data:data];
return data;
}
- (int)length {
int num = [self checkVector:_channels depth:_depth];
if (num < 0) {
@throw [NSException exceptionWithName:NSInternalInconsistencyException reason:@"Incompatible Mat" userInfo:nil];
}
return num * _channels;
}
@end

View File

@ -0,0 +1,62 @@
//
// MatOfFloat4.h
//
// Created by Giles Payne on 2019/12/26.
//
#pragma once
#import "Mat.h"
NS_ASSUME_NONNULL_BEGIN
/**
* Mat representation of an array of vectors of four floats
*/
CV_EXPORTS @interface MatOfFloat4 : Mat
#pragma mark - Constructors
#ifdef __cplusplus
- (instancetype)initWithNativeMat:(cv::Mat*)nativeMat;
#endif
/**
* Create MatOfFloat4 from Mat object
* @param mat Mat object from which to create MatOfFloat4
*/
- (instancetype)initWithMat:(Mat*)mat;
/**
* Create MatOfFloat4 from array
* @param array Array from which to create MatOfFloat4
*/
- (instancetype)initWithArray:(NSArray<NSNumber*>*)array;
#pragma mark - Methods
/**
* Allocate specified number of elements
* @param elemNumber Number of elements
*/
- (void)alloc:(int)elemNumber;
/**
* Populate Mat with elements of an array
* @param array Array with which to populate the Mat
*/
- (void)fromArray:(NSArray<NSNumber*>*)array;
/**
* Output Mat elements as an array
*/
- (NSArray<NSNumber*>*)toArray;
/**
* Total number of values in Mat
*/
- (int)length;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,69 @@
//
// MatOfFloat4.mm
//
// Created by Giles Payne on 2019/12/26.
//
#import "MatOfFloat4.h"
#import "Range.h"
#import "CvType.h"
#import "ArrayUtil.h"
@implementation MatOfFloat4
static const int _depth = CV_32F;
static const int _channels = 4;
#ifdef __cplusplus
- (instancetype)initWithNativeMat:(cv::Mat*)nativeMat {
self = [super initWithNativeMat:nativeMat];
if (self && ![self empty] && [self checkVector:_channels depth:_depth] < 0) {
@throw [NSException exceptionWithName:NSInvalidArgumentException reason:@"Incompatible Mat" userInfo:nil];
}
return self;
}
#endif
- (instancetype)initWithMat:(Mat*)mat {
self = [super initWithMat:mat rowRange:[Range all]];
if (self && ![self empty] && [self checkVector:_channels depth:_depth] < 0) {
@throw [NSException exceptionWithName:NSInvalidArgumentException reason:@"Incompatible Mat" userInfo:nil];
}
return self;
}
- (instancetype)initWithArray:(NSArray<NSNumber*>*)array {
self = [super init];
if (self) {
[self fromArray:array];
}
return self;
}
- (void)alloc:(int)elemNumber {
if (elemNumber>0) {
[super create:elemNumber cols:1 type:[CvType makeType:_depth channels:_channels]];
}
}
- (void)fromArray:(NSArray<NSNumber*>*)array {
[self alloc:(int)array.count / _channels];
[self put:0 col:0 data:array];
}
- (NSArray<NSNumber*>*)toArray {
int length = [self length];
NSMutableArray<NSNumber*>* data = [[NSMutableArray alloc] initWithCapacity:length];
[self get:0 col:0 data:data];
return data;
}
- (int)length {
int num = [self checkVector:_channels depth:_depth];
if (num < 0) {
@throw [NSException exceptionWithName:NSInternalInconsistencyException reason:@"Incompatible Mat" userInfo:nil];
}
return num * _channels;
}
@end

View File

@ -0,0 +1,62 @@
//
// MatOfFloat6.h
//
// Created by Giles Payne on 2019/12/26.
//
#pragma once
#import "Mat.h"
NS_ASSUME_NONNULL_BEGIN
/**
* Mat representation of an array of vectors of six floats
*/
CV_EXPORTS @interface MatOfFloat6 : Mat
#pragma mark - Constructors
#ifdef __cplusplus
- (instancetype)initWithNativeMat:(cv::Mat*)nativeMat;
#endif
/**
* Create MatOfFloat6 from Mat object
* @param mat Mat object from which to create MatOfFloat6
*/
- (instancetype)initWithMat:(Mat*)mat;
/**
* Create MatOfFloat6 from array
* @param array Array from which to create MatOfFloat6
*/
- (instancetype)initWithArray:(NSArray<NSNumber*>*)array;
#pragma mark - Methods
/**
* Allocate specified number of elements
* @param elemNumber Number of elements
*/
- (void)alloc:(int)elemNumber;
/**
* Populate Mat with elements of an array
* @param array Array with which to populate the Mat
*/
- (void)fromArray:(NSArray<NSNumber*>*)array;
/**
* Output Mat elements as an array
*/
- (NSArray<NSNumber*>*)toArray;
/**
* Total number of values in Mat
*/
- (int)length;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,69 @@
//
// MatOfFloat6.mm
//
// Created by Giles Payne on 2019/12/26.
//
#import "MatOfFloat6.h"
#import "Range.h"
#import "CvType.h"
#import "ArrayUtil.h"
@implementation MatOfFloat6
static const int _depth = CV_32F;
static const int _channels = 6;
#ifdef __cplusplus
- (instancetype)initWithNativeMat:(cv::Mat*)nativeMat {
self = [super initWithNativeMat:nativeMat];
if (self && ![self empty] && [self checkVector:_channels depth:_depth] < 0) {
@throw [NSException exceptionWithName:NSInvalidArgumentException reason:@"Incompatible Mat" userInfo:nil];
}
return self;
}
#endif
- (instancetype)initWithMat:(Mat*)mat {
self = [super initWithMat:mat rowRange:[Range all]];
if (self && ![self empty] && [self checkVector:_channels depth:_depth] < 0) {
@throw [NSException exceptionWithName:NSInvalidArgumentException reason:@"Incompatible Mat" userInfo:nil];
}
return self;
}
- (instancetype)initWithArray:(NSArray<NSNumber*>*)array {
self = [super init];
if (self) {
[self fromArray:array];
}
return self;
}
- (void)alloc:(int)elemNumber {
if (elemNumber>0) {
[super create:elemNumber cols:1 type:[CvType makeType:_depth channels:_channels]];
}
}
- (void)fromArray:(NSArray<NSNumber*>*)array {
[self alloc:(int)array.count / _channels];
[self put:0 col:0 data:array];
}
- (NSArray<NSNumber*>*)toArray {
int length = [self length];
NSMutableArray<NSNumber*>* data = [[NSMutableArray alloc] initWithCapacity:length];
[self get:0 col:0 data:data];
return data;
}
- (int)length {
int num = [self checkVector:_channels depth:_depth];
if (num < 0) {
@throw [NSException exceptionWithName:NSInternalInconsistencyException reason:@"Incompatible Mat" userInfo:nil];
}
return num * _channels;
}
@end

Some files were not shown because too many files have changed in this diff Show More