vendor: OpenCV 5.0.0 snapshot at 755e50675d97db9b7d449d8bd6b09888646f6c6e
This commit is contained in:
@@ -0,0 +1,148 @@
|
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html
|
||||
// Copyright (C) 2020 by Archit Rungta
|
||||
|
||||
#include "jlcxx/array.hpp"
|
||||
#include "jlcxx/jlcxx.hpp"
|
||||
#include "jlcxx/functions.hpp"
|
||||
#include "jlcxx/stl.hpp"
|
||||
#include "jlcxx/tuple.hpp"
|
||||
|
||||
#include "jlcv.hpp"
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
using namespace jlcxx;
|
||||
|
||||
|
||||
namespace jlcxx
|
||||
{
|
||||
template <typename T>
|
||||
struct IsSmartPointerType<cv::Ptr<T>> : std::true_type
|
||||
{
|
||||
};
|
||||
template <typename T>
|
||||
struct ConstructorPointerType<cv::Ptr<T>>
|
||||
{
|
||||
typedef T *type;
|
||||
};
|
||||
|
||||
template<typename T, int Val>
|
||||
struct BuildParameterList<cv::Vec<T, Val>>
|
||||
{
|
||||
typedef ParameterList<T, std::integral_constant<int, Val>> type;
|
||||
};
|
||||
${include_code}
|
||||
|
||||
|
||||
//
|
||||
// Manual Wrapping BEGIN
|
||||
//
|
||||
|
||||
#ifdef HAVE_OPENCV_FEATURES
|
||||
// template <>
|
||||
// struct SuperType<cv::Feature2D>
|
||||
// {
|
||||
// typedef cv::Algorithm type;
|
||||
// };
|
||||
// TODO: Needs to be fixed but doesn't matter for now
|
||||
template <>
|
||||
struct SuperType<cv::SimpleBlobDetector>
|
||||
{
|
||||
typedef cv::Feature2D type;
|
||||
};
|
||||
#endif
|
||||
|
||||
//
|
||||
// Manual Wrapping END
|
||||
//
|
||||
} // namespace jlcxx
|
||||
JLCXX_MODULE cv_wrap(jlcxx::Module &mod)
|
||||
{
|
||||
mod.map_type<RotatedRect>("RotatedRect");
|
||||
mod.map_type<TermCriteria>("TermCriteria");
|
||||
mod.map_type<Range>("Range");
|
||||
|
||||
mod.add_type<Parametric<TypeVar<1>, TypeVar<2>>>("CxxVec")
|
||||
.apply<Vec4f, Vec6f, Vec3d, Vec2d>([](auto wrapped){
|
||||
typedef typename decltype(wrapped)::type WrappedT;
|
||||
typedef typename get_template_type_vec<WrappedT>::type T;
|
||||
wrapped.template constructor<const T*>();
|
||||
});
|
||||
|
||||
mod.add_type<Mat>("CxxMat").constructor<int, const int *, int, void *, const size_t *>();
|
||||
|
||||
mod.method("jlopencv_core_get_sizet", [](){return sizeof(size_t);});
|
||||
jlcxx::add_smart_pointer<cv::Ptr>(mod, "cv_Ptr");
|
||||
mod.method("jlopencv_core_Mat_mutable_data", [](Mat m) {
|
||||
return make_tuple(m.data, m.type(), m.channels(), m.size[1], m.size[0], m.step[1], m.step[0]);
|
||||
});
|
||||
|
||||
|
||||
mod.add_type<Parametric<TypeVar<1>>>("CxxScalar")
|
||||
.apply<Scalar_<int>, Scalar_<float>, Scalar_<double>>([](auto wrapped) {
|
||||
typedef typename decltype(wrapped)::type WrappedT;
|
||||
typedef typename get_template_type<WrappedT>::type T;
|
||||
wrapped.template constructor<T, T, T, T>();
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Manual Wrapping BEGIN
|
||||
//
|
||||
|
||||
#ifdef HAVE_OPENCV_HIGHGUI
|
||||
mod.method("createButton", [](const string & bar_name, jl_function_t* on_change, int type, bool initial_button_state) {createButton(bar_name, [](int s, void* c) {
|
||||
JuliaFunction f((jl_function_t*)c);
|
||||
f(forward<int>(s));
|
||||
}, (void*)on_change, type, initial_button_state);});
|
||||
|
||||
mod.method("setMouseCallback", [](const string & winname, jl_function_t* onMouse) {
|
||||
setMouseCallback(winname, [](int event, int x, int y, int flags, void* c) {
|
||||
JuliaFunction f((jl_function_t*)c);
|
||||
f(forward<int>(event), forward<int>(x), forward<int>(y), forward<int>(flags));
|
||||
}, (void*)onMouse);});
|
||||
|
||||
mod.method("createTrackbar", [](const String &trackbarname, const String &winname, int& value, int count, jl_function_t* onChange) {
|
||||
createTrackbar(trackbarname, winname, &value, count, [](int s, void* c) {
|
||||
JuliaFunction f((jl_function_t*)c);
|
||||
f(forward<int>(s));
|
||||
}, (void*)onChange);});
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OPENCV_OBJDETECT
|
||||
mod.add_type<cv::CascadeClassifier>("CascadeClassifier");
|
||||
mod.method("jlopencv_cv_cv_CascadeClassifier_cv_CascadeClassifier_CascadeClassifier", [](string &filename) { return jlcxx::create<cv::CascadeClassifier>(filename); });
|
||||
mod.method("jlopencv_cv_cv_CascadeClassifier_cv_CascadeClassifier_detectMultiScale", [](cv::CascadeClassifier &cobj, Mat &image, double &scaleFactor, int &minNeighbors, int &flags, Size &minSize, Size &maxSize) {vector<Rect> objects; cobj.detectMultiScale(image, objects, scaleFactor, minNeighbors, flags, minSize, maxSize); return objects; });
|
||||
mod.method("jlopencv_cv_cv_CascadeClassifier_cv_CascadeClassifier_empty", [](cv::CascadeClassifier &cobj) { auto retval = cobj.empty(); return retval; });
|
||||
|
||||
mod.set_const("CASCADE_DO_CANNY_PRUNING", (int)cv::CASCADE_DO_CANNY_PRUNING);
|
||||
mod.set_const("CASCADE_DO_ROUGH_SEARCH", (int)cv::CASCADE_DO_ROUGH_SEARCH);
|
||||
mod.set_const("CASCADE_FIND_BIGGEST_OBJECT", (int)cv::CASCADE_FIND_BIGGEST_OBJECT);
|
||||
mod.set_const("CASCADE_SCALE_IMAGE", (int)cv::CASCADE_SCALE_IMAGE);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OPENCV_FEATURES
|
||||
mod.add_type<cv::Feature2D>("Feature2D");
|
||||
mod.add_type<cv::SimpleBlobDetector>("SimpleBlobDetector", jlcxx::julia_base_type<cv::Feature2D>());
|
||||
mod.add_type<cv::SimpleBlobDetector::Params>("SimpleBlobDetector_Params");
|
||||
#endif
|
||||
|
||||
//
|
||||
// Manual Wrapping END
|
||||
//
|
||||
|
||||
${cpp_code}
|
||||
|
||||
#ifdef HAVE_OPENCV_FEATURES
|
||||
|
||||
mod.method("jlopencv_cv_cv_Feature2D_cv_Feature2D_detect", [](cv::Ptr<cv::Feature2D> &cobj, Mat &image, Mat &mask) {vector<KeyPoint> keypoints; cobj->detect(image, keypoints, mask); return keypoints; });
|
||||
mod.method("jlopencv_cv_cv_SimpleBlobDetector_create", [](SimpleBlobDetector_Params ¶meters) { auto retval = cv::SimpleBlobDetector::create(parameters); return retval; });
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
${code}
|
||||
|
||||
${submodule_imports}
|
||||
@@ -0,0 +1,7 @@
|
||||
module ${modname}
|
||||
import ..OpenCV
|
||||
|
||||
${code}
|
||||
|
||||
${submodule_imports}
|
||||
end
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
${code}
|
||||
|
||||
${submodule_imports}
|
||||
@@ -0,0 +1,122 @@
|
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html
|
||||
// Copyright (C) 2020 by Archit Rungta
|
||||
|
||||
// This header files hacks into the mapping code of CxxWrap to support automatic conversion between types from OpenCV and Julia
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "jlcxx/jlcxx.hpp"
|
||||
#include "jlcxx/functions.hpp"
|
||||
#include "jlcxx/stl.hpp"
|
||||
#include "jlcxx/array.hpp"
|
||||
#include "jlcxx/tuple.hpp"
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/core/utility.hpp>
|
||||
#include <opencv2/core/ocl.hpp>
|
||||
|
||||
#include <opencv2/core/bindings_utils.hpp>
|
||||
|
||||
|
||||
#include <opencv2/opencv_modules.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
using namespace jlcxx;
|
||||
|
||||
#ifdef HAVE_OPENCV_HIGHGUI
|
||||
#include <opencv2/highgui.hpp>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OPENCV_IMGPROC
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OPENCV_VIDEOIO
|
||||
#include <opencv2/videoio.hpp>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OPENCV_FEATURES
|
||||
#include <opencv2/features.hpp>
|
||||
typedef SimpleBlobDetector::Params SimpleBlobDetector_Params;
|
||||
typedef AKAZE::DescriptorType AKAZE_DescriptorType;
|
||||
typedef AgastFeatureDetector::DetectorType AgastFeatureDetector_DetectorType;
|
||||
typedef FastFeatureDetector::DetectorType FastFeatureDetector_DetectorType;
|
||||
typedef DescriptorMatcher::MatcherType DescriptorMatcher_MatcherType;
|
||||
typedef KAZE::DiffusivityType KAZE_DiffusivityType;
|
||||
typedef ORB::ScoreType ORB_ScoreType;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OPENCV_XOBJDETECT
|
||||
|
||||
#include <opencv2/xobjdetect.hpp>
|
||||
|
||||
typedef HOGDescriptor::HistogramNormType HOGDescriptor_HistogramNormType;
|
||||
typedef HOGDescriptor::DescriptorStorageFormat HOGDescriptor_DescriptorStorageFormat;
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OPENCV_FLANN
|
||||
typedef cvflann::flann_distance_t cvflann_flann_distance_t;
|
||||
typedef cvflann::flann_algorithm_t cvflann_flann_algorithm_t;
|
||||
|
||||
typedef flann::IndexParams flann_IndexParams;
|
||||
typedef flann::SearchParams flann_SearchParams;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OPENCV_DNN
|
||||
|
||||
#include <opencv2/dnn.hpp>
|
||||
typedef cv::dnn::DictValue LayerId;
|
||||
typedef cv::dnn::Backend dnn_Backend;
|
||||
typedef cv::dnn::Target dnn_Target;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OPENCV_CALIB3D
|
||||
|
||||
#include <opencv2/calib3d.hpp>
|
||||
#endif
|
||||
|
||||
template <typename C>
|
||||
struct get_template_type;
|
||||
template <typename C>
|
||||
struct get_template_type_vec;
|
||||
|
||||
template <template <typename> class C, typename T>
|
||||
struct get_template_type<C<T>> {
|
||||
using type = T;
|
||||
};
|
||||
|
||||
template <template <typename, int> class C, typename T, int N>
|
||||
struct get_template_type_vec<C<T, N>> {
|
||||
using type = T;
|
||||
int dim = N;
|
||||
};
|
||||
|
||||
template<typename T, bool v>
|
||||
struct force_enum{};
|
||||
template<typename T>
|
||||
struct force_enum<T, false>{
|
||||
using Type = T;
|
||||
};
|
||||
template<typename T>
|
||||
struct force_enum<T, true>{
|
||||
using Type = int64_t;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct force_enum_int{
|
||||
using Type = typename force_enum<T, std::is_enum<T>::value>::Type;
|
||||
};
|
||||
|
||||
typedef vector<Mat> vector_Mat;
|
||||
typedef vector<UMat> vector_UMat;
|
||||
|
||||
typedef char* c_string;
|
||||
|
||||
|
||||
#include "jlcv_types.hpp"
|
||||
@@ -0,0 +1,283 @@
|
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html
|
||||
// Copyright (C) 2020 by Archit Rungta
|
||||
|
||||
template<typename T>
|
||||
struct CxxPoint
|
||||
{
|
||||
T x;
|
||||
T y;
|
||||
};
|
||||
template<typename T>
|
||||
struct CxxPoint3
|
||||
{
|
||||
T x;
|
||||
T y;
|
||||
T z;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct CxxSize
|
||||
{
|
||||
T width;
|
||||
T height;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct CxxRect
|
||||
{
|
||||
T x;
|
||||
T y;
|
||||
T width;
|
||||
T height;
|
||||
};
|
||||
|
||||
struct CxxRotatedRect
|
||||
{
|
||||
Point2f center;
|
||||
Size2f size;
|
||||
float angle;
|
||||
};
|
||||
|
||||
struct CxxRange
|
||||
{
|
||||
int start;
|
||||
int end;
|
||||
};
|
||||
|
||||
struct CxxTermCriteria
|
||||
{
|
||||
int type;
|
||||
int maxCount;
|
||||
double epsilon;
|
||||
};
|
||||
|
||||
|
||||
template<typename T>
|
||||
struct CxxComplex
|
||||
{
|
||||
T re;
|
||||
T im;
|
||||
};
|
||||
|
||||
|
||||
namespace jlcxx
|
||||
{
|
||||
template <> struct IsMirroredType<cv::Range> : std::true_type {};
|
||||
template <> struct IsMirroredType<cv::RotatedRect> : std::true_type {};
|
||||
template <> struct IsMirroredType<cv::TermCriteria> : std::true_type {};
|
||||
|
||||
template<typename T> struct IsMirroredType<cv::Point_<T>> : std::true_type {};
|
||||
|
||||
template<typename T> struct static_type_mapping<cv::Point_<T>> { using type = CxxPoint<T>; };
|
||||
|
||||
template<typename T>
|
||||
struct julia_type_factory<cv::Point_<T>>
|
||||
{
|
||||
static inline jl_datatype_t* julia_type()
|
||||
{
|
||||
return (jl_datatype_t*)apply_type((jl_value_t*)jlcxx::julia_type("Point"), jl_svec1(julia_base_type<T>()));
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct ConvertToJulia<cv::Point_<T>, NoMappingTrait>
|
||||
{
|
||||
CxxPoint<T> operator()(const cv::Point_<T>& cpp_val) const
|
||||
{
|
||||
return *reinterpret_cast<const CxxPoint<T>*>(&cpp_val);
|
||||
}
|
||||
};
|
||||
template<typename T>
|
||||
struct ConvertToCpp<cv::Point_<T>, NoMappingTrait>
|
||||
{
|
||||
inline cv::Point operator()(const CxxPoint<T>& julia_val) const
|
||||
{
|
||||
return *reinterpret_cast<const cv::Point_<T>*>(&julia_val);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
template<typename T> struct IsMirroredType<cv::Size_<T>> : std::true_type {};
|
||||
|
||||
template<typename T> struct static_type_mapping<cv::Size_<T>> { using type = CxxSize<T>; };
|
||||
|
||||
template<typename T>
|
||||
struct julia_type_factory<cv::Size_<T>>
|
||||
{
|
||||
static inline jl_datatype_t* julia_type()
|
||||
{
|
||||
return (jl_datatype_t*)apply_type((jl_value_t*)jlcxx::julia_type("Size"), jl_svec1(julia_base_type<T>()));
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct ConvertToJulia<cv::Size_<T>, NoMappingTrait>
|
||||
{
|
||||
CxxSize<T> operator()(const cv::Size_<T>& cpp_val) const
|
||||
{
|
||||
return *reinterpret_cast<const CxxSize<T>*>(&cpp_val);
|
||||
}
|
||||
};
|
||||
template<typename T>
|
||||
struct ConvertToCpp<cv::Size_<T>, NoMappingTrait>
|
||||
{
|
||||
inline cv::Size operator()(const CxxSize<T>& julia_val) const
|
||||
{
|
||||
return *reinterpret_cast<const cv::Size_<T>*>(&julia_val);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
template<typename T> struct IsMirroredType<cv::Point3_<T>> : std::true_type {};
|
||||
|
||||
template<typename T> struct static_type_mapping<cv::Point3_<T>> { using type = CxxPoint3<T>; };
|
||||
|
||||
template<typename T>
|
||||
struct julia_type_factory<cv::Point3_<T>>
|
||||
{
|
||||
static inline jl_datatype_t* julia_type()
|
||||
{
|
||||
return (jl_datatype_t*)apply_type((jl_value_t*)jlcxx::julia_type("Point3"), jl_svec1(julia_base_type<T>()));
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct ConvertToJulia<cv::Point3_<T>, NoMappingTrait>
|
||||
{
|
||||
CxxPoint3<T> operator()(const cv::Point3_<T>& cpp_val) const
|
||||
{
|
||||
return *reinterpret_cast<const CxxPoint3<T>*>(&cpp_val);
|
||||
}
|
||||
};
|
||||
template<typename T>
|
||||
struct ConvertToCpp<cv::Point3_<T>, NoMappingTrait>
|
||||
{
|
||||
inline cv::Point3_<T> operator()(const CxxPoint3<T>& julia_val) const
|
||||
{
|
||||
return *reinterpret_cast<const cv::Point3_<T>*>(&julia_val);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T> struct IsMirroredType<cv::Rect_<T>> : std::true_type {};
|
||||
|
||||
template<typename T> struct static_type_mapping<cv::Rect_<T>> { using type = CxxRect<T>; };
|
||||
|
||||
template<typename T>
|
||||
struct julia_type_factory<cv::Rect_<T>>
|
||||
{
|
||||
static inline jl_datatype_t* julia_type()
|
||||
{
|
||||
return (jl_datatype_t*)apply_type((jl_value_t*)jlcxx::julia_type("Rect"), jl_svec1(julia_base_type<T>()));
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct ConvertToJulia<cv::Rect_<T>, NoMappingTrait>
|
||||
{
|
||||
CxxRect<T> operator()(const cv::Rect_<T>& cpp_val) const
|
||||
{
|
||||
return *reinterpret_cast<const CxxRect<T>*>(&cpp_val);
|
||||
}
|
||||
};
|
||||
template<typename T>
|
||||
struct ConvertToCpp<cv::Rect_<T>, NoMappingTrait>
|
||||
{
|
||||
inline cv::Rect operator()(const CxxRect<T>& julia_val) const
|
||||
{
|
||||
return *reinterpret_cast<const cv::Rect_<T>*>(&julia_val);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<typename T> struct IsMirroredType<cv::Complex<T>> : std::true_type {};
|
||||
|
||||
template<typename T> struct static_type_mapping<cv::Complex<T>> { using type = CxxComplex<T>; };
|
||||
|
||||
template<typename T>
|
||||
struct julia_type_factory<cv::Complex<T>>
|
||||
{
|
||||
static inline jl_datatype_t* julia_type()
|
||||
{
|
||||
return (jl_datatype_t*)apply_type((jl_value_t*)jlcxx::julia_type("cvComplex"), jl_svec1(julia_base_type<T>()));
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct ConvertToJulia<cv::Complex<T>, NoMappingTrait>
|
||||
{
|
||||
CxxComplex<T> operator()(const cv::Complex<T>& cpp_val) const
|
||||
{
|
||||
return *reinterpret_cast<const CxxComplex<T>*>(&cpp_val);
|
||||
}
|
||||
};
|
||||
template<typename T>
|
||||
struct ConvertToCpp<cv::Complex<T>, NoMappingTrait>
|
||||
{
|
||||
inline cv::Complex<T> operator()(const CxxComplex<T>& julia_val) const
|
||||
{
|
||||
return *reinterpret_cast<const cv::Complex<T>*>(&julia_val);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct BoxValue<Size_<T>,CxxSize<T>>
|
||||
{
|
||||
inline jl_value_t* operator()(Size_<T> cppval)
|
||||
{
|
||||
return jl_new_bits((jl_value_t*)julia_type<Size_<T>>(), reinterpret_cast<CxxSize<T>*>(&cppval));
|
||||
}
|
||||
|
||||
inline jl_value_t* operator()(Size_<T> cppval, jl_value_t* dt)
|
||||
{
|
||||
return jl_new_bits(dt, reinterpret_cast<CxxSize<T>*>(&cppval));
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct BoxValue<Point_<T>,CxxPoint<T>>
|
||||
{
|
||||
inline jl_value_t* operator()(Point_<T> cppval)
|
||||
{
|
||||
return jl_new_bits((jl_value_t*)julia_type<Point_<T>>(), reinterpret_cast<CxxPoint<T>*>(&cppval));
|
||||
}
|
||||
|
||||
inline jl_value_t* operator()(Point_<T> cppval, jl_value_t* dt)
|
||||
{
|
||||
return jl_new_bits(dt, reinterpret_cast<CxxPoint<T>*>(&cppval));
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct BoxValue<Point3_<T>,CxxPoint3<T>>
|
||||
{
|
||||
inline jl_value_t* operator()(Point3_<T> cppval)
|
||||
{
|
||||
return jl_new_bits((jl_value_t*)julia_type<Point3_<T>>(), reinterpret_cast<CxxPoint3<T>*>(&cppval));
|
||||
}
|
||||
|
||||
inline jl_value_t* operator()(Point3_<T> cppval, jl_value_t* dt)
|
||||
{
|
||||
return jl_new_bits(dt, reinterpret_cast<CxxPoint3<T>*>(&cppval));
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct BoxValue<Rect_<T>,CxxRect<T>>
|
||||
{
|
||||
inline jl_value_t* operator()(Rect_<T> cppval)
|
||||
{
|
||||
return jl_new_bits((jl_value_t*)julia_type<Rect_<T>>(), reinterpret_cast<CxxRect<T>*>(&cppval));
|
||||
}
|
||||
|
||||
inline jl_value_t* operator()(Rect_<T> cppval, jl_value_t* dt)
|
||||
{
|
||||
return jl_new_bits(dt, reinterpret_cast<CxxRect<T>*>(&cppval));
|
||||
}
|
||||
};
|
||||
|
||||
};
|
||||
@@ -0,0 +1,459 @@
|
||||
// This file is a modified array.hpp from https://github.com/JuliaInterop/libcxxwrap-julia
|
||||
// required for the hack that allows automated conversion of OpenCV types.
|
||||
// Shouldn't be needed once CxxWrap gets inbuilt support
|
||||
// Here is the original copyright and the license:
|
||||
/*
|
||||
==
|
||||
|
||||
Copyright (c) 2015: Bart Janssens.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
==
|
||||
*/
|
||||
|
||||
|
||||
#ifndef JLCXX_ARRAY_HPP
|
||||
#define JLCXX_ARRAY_HPP
|
||||
|
||||
#include "jlcxx/type_conversion.hpp"
|
||||
#include "jlcxx/tuple.hpp"
|
||||
|
||||
namespace jlcxx
|
||||
{
|
||||
|
||||
template<typename PointedT, typename CppT>
|
||||
struct ValueExtractor
|
||||
{
|
||||
inline CppT operator()(PointedT* p)
|
||||
{
|
||||
return convert_to_cpp<CppT>(*p);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<typename PointedT>
|
||||
struct ValueExtractor<PointedT, PointedT>
|
||||
{
|
||||
inline PointedT& operator()(PointedT* p)
|
||||
{
|
||||
return *p;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename PointedT, typename CppT>
|
||||
class array_iterator_base : public std::iterator<std::random_access_iterator_tag, CppT>
|
||||
{
|
||||
private:
|
||||
PointedT* m_ptr;
|
||||
public:
|
||||
array_iterator_base() : m_ptr(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
explicit array_iterator_base(PointedT* p) : m_ptr(p)
|
||||
{
|
||||
}
|
||||
|
||||
template <class OtherPointedT, class OtherCppT>
|
||||
array_iterator_base(array_iterator_base<OtherPointedT, OtherCppT> const& other) : m_ptr(other.m_ptr) {}
|
||||
|
||||
auto operator*() -> decltype(ValueExtractor<PointedT,CppT>()(m_ptr))
|
||||
{
|
||||
return ValueExtractor<PointedT,CppT>()(m_ptr);
|
||||
}
|
||||
|
||||
array_iterator_base<PointedT, CppT>& operator++()
|
||||
{
|
||||
++m_ptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
array_iterator_base<PointedT, CppT>& operator--()
|
||||
{
|
||||
--m_ptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
array_iterator_base<PointedT, CppT>& operator+=(std::ptrdiff_t n)
|
||||
{
|
||||
m_ptr += n;
|
||||
return *this;
|
||||
}
|
||||
|
||||
array_iterator_base<PointedT, CppT>& operator-=(std::ptrdiff_t n)
|
||||
{
|
||||
m_ptr -= n;
|
||||
return *this;
|
||||
}
|
||||
|
||||
PointedT* ptr() const
|
||||
{
|
||||
return m_ptr;
|
||||
}
|
||||
};
|
||||
|
||||
/// Wrap a Julia 1D array in a C++ class. Array is allocated on the C++ side
|
||||
template<typename ValueT>
|
||||
class Array
|
||||
{
|
||||
public:
|
||||
Array(const size_t n = 0)
|
||||
{
|
||||
jl_value_t* array_type = apply_array_type(julia_type<ValueT>(), 1);
|
||||
m_array = jl_alloc_array_1d(array_type, n);
|
||||
}
|
||||
|
||||
Array(jl_datatype_t* applied_type, const size_t n = 0)
|
||||
{
|
||||
jl_value_t* array_type = apply_array_type(applied_type, 1);
|
||||
m_array = jl_alloc_array_1d(array_type, n);
|
||||
}
|
||||
|
||||
/// Append an element to the end of the list
|
||||
template<typename VT>
|
||||
void push_back(VT&& val)
|
||||
{
|
||||
JL_GC_PUSH1(&m_array);
|
||||
const size_t pos = jl_array_len(m_array);
|
||||
jl_array_grow_end(m_array, 1);
|
||||
jl_arrayset(m_array, box<ValueT>(val), pos);
|
||||
JL_GC_POP();
|
||||
}
|
||||
|
||||
/// Access to the wrapped array
|
||||
jl_array_t* wrapped()
|
||||
{
|
||||
return m_array;
|
||||
}
|
||||
|
||||
// access to the pointer for GC macros
|
||||
jl_array_t** gc_pointer()
|
||||
{
|
||||
return &m_array;
|
||||
}
|
||||
|
||||
private:
|
||||
jl_array_t* m_array;
|
||||
};
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<typename T, typename TraitT=mapping_trait<T>>
|
||||
struct ArrayElementType
|
||||
{
|
||||
using type = static_julia_type<T>;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct ArrayElementType<T,WrappedPtrTrait>
|
||||
{
|
||||
using type = T;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/// Reference a Julia array in an STL-compatible wrapper
|
||||
template<typename ValueT, int Dim = 1>
|
||||
class ArrayRef
|
||||
{
|
||||
public:
|
||||
|
||||
using julia_t = typename detail::ArrayElementType<ValueT>::type;
|
||||
|
||||
ArrayRef(jl_array_t* arr) : m_array(arr)
|
||||
{
|
||||
assert(wrapped() != nullptr);
|
||||
}
|
||||
|
||||
/// Convert from existing C-array (memory owned by C++)
|
||||
template<typename... SizesT>
|
||||
ArrayRef(julia_t* ptr, const SizesT... sizes);
|
||||
|
||||
/// Convert from existing C-array, explicitly setting Julia ownership
|
||||
template<typename... SizesT>
|
||||
ArrayRef(const bool julia_owned, julia_t* ptr, const SizesT... sizes);
|
||||
|
||||
typedef array_iterator_base<julia_t, ValueT> iterator;
|
||||
typedef array_iterator_base<julia_t const, ValueT const> const_iterator;
|
||||
|
||||
inline jl_array_t* wrapped() const
|
||||
{
|
||||
return m_array;
|
||||
}
|
||||
|
||||
iterator begin()
|
||||
{
|
||||
return iterator(static_cast<julia_t*>(jl_array_data(wrapped())));
|
||||
}
|
||||
|
||||
const_iterator begin() const
|
||||
{
|
||||
return const_iterator(static_cast<julia_t*>(jl_array_data(wrapped())));
|
||||
}
|
||||
|
||||
iterator end()
|
||||
{
|
||||
return iterator(static_cast<julia_t*>(jl_array_data(wrapped())) + jl_array_len(wrapped()));
|
||||
}
|
||||
|
||||
const_iterator end() const
|
||||
{
|
||||
return const_iterator(static_cast<julia_t*>(jl_array_data(wrapped())) + jl_array_len(wrapped()));
|
||||
}
|
||||
|
||||
void push_back(const ValueT& val)
|
||||
{
|
||||
static_assert(Dim == 1, "ArrayRef::push_back is only for 1D ArrayRef");
|
||||
static_assert(std::is_same<julia_t,ValueT>::value, "ArrayRef::push_back is only for arrays of fundamental types");
|
||||
jl_array_t* arr_ptr = wrapped();
|
||||
JL_GC_PUSH1(&arr_ptr);
|
||||
const size_t pos = size();
|
||||
jl_array_grow_end(arr_ptr, 1);
|
||||
jl_arrayset(arr_ptr, box<ValueT>(val), pos);
|
||||
JL_GC_POP();
|
||||
}
|
||||
|
||||
const julia_t* data() const
|
||||
{
|
||||
return (julia_t*)jl_array_data(wrapped());
|
||||
}
|
||||
|
||||
julia_t* data()
|
||||
{
|
||||
return (julia_t*)jl_array_data(wrapped());
|
||||
}
|
||||
|
||||
std::size_t size() const
|
||||
{
|
||||
return jl_array_len(wrapped());
|
||||
}
|
||||
|
||||
ValueT& operator[](const std::size_t i)
|
||||
{
|
||||
if constexpr(std::is_same<julia_t, ValueT>::value)
|
||||
{
|
||||
return data()[i];
|
||||
}
|
||||
else if constexpr(std::is_same<julia_t, static_julia_type<ValueT>>::value && !std::is_same<julia_t, WrappedCppPtr>::value)
|
||||
{
|
||||
return *reinterpret_cast<ValueT*>(&data()[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return *extract_pointer_nonull<ValueT>(data()[i]);
|
||||
}
|
||||
}
|
||||
|
||||
const ValueT& operator[](const std::size_t i) const
|
||||
{
|
||||
if constexpr(std::is_same<julia_t, ValueT>::value)
|
||||
{
|
||||
return data()[i];
|
||||
}
|
||||
else if constexpr(std::is_same<julia_t, static_julia_type<ValueT>>::value && !std::is_same<julia_t, WrappedCppPtr>::value)
|
||||
{
|
||||
return *reinterpret_cast<ValueT*>(&data()[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return *extract_pointer_nonull<ValueT>(data()[i]);
|
||||
}
|
||||
}
|
||||
|
||||
jl_array_t* m_array;
|
||||
};
|
||||
|
||||
// Conversions
|
||||
template<typename T, int Dim, typename SubTraitT>
|
||||
struct static_type_mapping<ArrayRef<T, Dim>, CxxWrappedTrait<SubTraitT>>
|
||||
{
|
||||
typedef jl_array_t* type;
|
||||
};
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<typename T, typename TraitT=mapping_trait<T>>
|
||||
struct PackedArrayType
|
||||
{
|
||||
static jl_datatype_t* type()
|
||||
{
|
||||
return julia_type<T>();
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct PackedArrayType<T*, WrappedPtrTrait>
|
||||
{
|
||||
static jl_datatype_t* type()
|
||||
{
|
||||
return (jl_datatype_t*)apply_type((jl_value_t*)jlcxx::julia_type("Ptr"), jl_svec1(julia_base_type<T>()));
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T, typename SubTraitT>
|
||||
struct PackedArrayType<T,CxxWrappedTrait<SubTraitT>>
|
||||
{
|
||||
static jl_datatype_t* type()
|
||||
{
|
||||
create_if_not_exists<T&>();
|
||||
return julia_type<T&>();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
template<typename T, int Dim>
|
||||
struct julia_type_factory<ArrayRef<T, Dim>>
|
||||
{
|
||||
static inline jl_datatype_t* julia_type()
|
||||
{
|
||||
create_if_not_exists<T>();
|
||||
return (jl_datatype_t*)apply_array_type(detail::PackedArrayType<T>::type(), Dim);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename ValueT, typename... SizesT>
|
||||
jl_array_t* wrap_array(const bool julia_owned, ValueT* c_ptr, const SizesT... sizes)
|
||||
{
|
||||
jl_datatype_t* dt = julia_type<ArrayRef<ValueT, sizeof...(SizesT)>>();
|
||||
jl_value_t *dims = nullptr;
|
||||
JL_GC_PUSH1(&dims);
|
||||
dims = convert_to_julia(std::make_tuple(static_cast<cxxint_t>(sizes)...));
|
||||
jl_array_t* result = jl_ptr_to_array((jl_value_t*)dt, c_ptr, dims, julia_owned);
|
||||
JL_GC_POP();
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename ValueT, int Dim>
|
||||
template<typename... SizesT>
|
||||
ArrayRef<ValueT, Dim>::ArrayRef(julia_t* c_ptr, const SizesT... sizes) : m_array(wrap_array(false, c_ptr, sizes...))
|
||||
{
|
||||
}
|
||||
|
||||
template<typename ValueT, int Dim>
|
||||
template<typename... SizesT>
|
||||
ArrayRef<ValueT, Dim>::ArrayRef(const bool julia_owned, julia_t* c_ptr, const SizesT... sizes) : m_array(wrap_array(julia_owned, c_ptr, sizes...))
|
||||
{
|
||||
}
|
||||
|
||||
template<typename ValueT, typename... SizesT>
|
||||
auto make_julia_array(ValueT* c_ptr, const SizesT... sizes) -> ArrayRef<ValueT, sizeof...(SizesT)>
|
||||
{
|
||||
return ArrayRef<ValueT, sizeof...(SizesT)>(false, c_ptr, sizes...);
|
||||
}
|
||||
|
||||
template<typename T, typename SubTraitT>
|
||||
struct static_type_mapping<Array<T>, CxxWrappedTrait<SubTraitT>>
|
||||
{
|
||||
typedef jl_array_t* type;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct julia_type_factory<Array<T>>
|
||||
{
|
||||
static inline jl_datatype_t* julia_type()
|
||||
{
|
||||
create_if_not_exists<T>();
|
||||
return (jl_datatype_t*)apply_array_type(jlcxx::julia_type<T>(), 1);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T, int Dim>
|
||||
struct ConvertToJulia<ArrayRef<T,Dim>>
|
||||
{
|
||||
template<typename ArrayRefT>
|
||||
jl_array_t* operator()(ArrayRefT&& arr) const
|
||||
{
|
||||
return arr.wrapped();
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct ConvertToJulia<Array<T>>
|
||||
{
|
||||
jl_value_t* operator()(Array<T>&& arr) const
|
||||
{
|
||||
return (jl_value_t*)arr.wrapped();
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T, int Dim, typename SubTraitT>
|
||||
struct ConvertToCpp<ArrayRef<T,Dim>, CxxWrappedTrait<SubTraitT>>
|
||||
{
|
||||
ArrayRef<T,Dim> operator()(jl_array_t* arr) const
|
||||
{
|
||||
return ArrayRef<T,Dim>(arr);
|
||||
}
|
||||
};
|
||||
|
||||
// Iterator operator implementation
|
||||
template<typename PointedT, typename CppT>
|
||||
bool operator!=(const array_iterator_base<PointedT, CppT>& l, const array_iterator_base<PointedT, CppT>& r)
|
||||
{
|
||||
return r.ptr() != l.ptr();
|
||||
}
|
||||
|
||||
template<typename PointedT, typename CppT>
|
||||
bool operator==(const array_iterator_base<PointedT, CppT>& l, const array_iterator_base<PointedT, CppT>& r)
|
||||
{
|
||||
return r.ptr() == l.ptr();
|
||||
}
|
||||
|
||||
template<typename PointedT, typename CppT>
|
||||
bool operator<=(const array_iterator_base<PointedT, CppT>& l, const array_iterator_base<PointedT, CppT>& r)
|
||||
{
|
||||
return l.ptr() <= r.ptr();
|
||||
}
|
||||
|
||||
template<typename PointedT, typename CppT>
|
||||
bool operator>=(const array_iterator_base<PointedT, CppT>& l, const array_iterator_base<PointedT, CppT>& r)
|
||||
{
|
||||
return l.ptr() >= r.ptr();
|
||||
}
|
||||
|
||||
template<typename PointedT, typename CppT>
|
||||
bool operator>(const array_iterator_base<PointedT, CppT>& l, const array_iterator_base<PointedT, CppT>& r)
|
||||
{
|
||||
return l.ptr() > r.ptr();
|
||||
}
|
||||
|
||||
template<typename PointedT, typename CppT>
|
||||
bool operator<(const array_iterator_base<PointedT, CppT>& l, const array_iterator_base<PointedT, CppT>& r)
|
||||
{
|
||||
return l.ptr() < r.ptr();
|
||||
}
|
||||
|
||||
template<typename PointedT, typename CppT>
|
||||
array_iterator_base<PointedT, CppT> operator+(const array_iterator_base<PointedT, CppT>& l, const std::ptrdiff_t n)
|
||||
{
|
||||
return array_iterator_base<PointedT, CppT>(l.ptr() + n);
|
||||
}
|
||||
|
||||
template<typename PointedT, typename CppT>
|
||||
array_iterator_base<PointedT, CppT> operator+(const std::ptrdiff_t n, const array_iterator_base<PointedT, CppT>& r)
|
||||
{
|
||||
return array_iterator_base<PointedT, CppT>(r.ptr() + n);
|
||||
}
|
||||
|
||||
template<typename PointedT, typename CppT>
|
||||
array_iterator_base<PointedT, CppT> operator-(const array_iterator_base<PointedT, CppT>& l, const std::ptrdiff_t n)
|
||||
{
|
||||
return array_iterator_base<PointedT, CppT>(l.ptr() - n);
|
||||
}
|
||||
|
||||
template<typename PointedT, typename CppT>
|
||||
std::ptrdiff_t operator-(const array_iterator_base<PointedT, CppT>& l, const array_iterator_base<PointedT, CppT>& r)
|
||||
{
|
||||
return l.ptr() - r.ptr();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,103 @@
|
||||
Float64|0.1|0.1
|
||||
Float64|1.0|1.0
|
||||
Float64|0|0
|
||||
Int64|NORM_L2|cv_NORM_L2
|
||||
Float64|0.04|0.04
|
||||
Bool|true|true
|
||||
Float64|0.0f|0
|
||||
Float64|DBL_MAX|typemax(Float64)
|
||||
Ptr{Float32}|Ptr<float>()|cpp_to_julia(PtrifloatkOP())
|
||||
Int64|CV_32F|CV_32F
|
||||
Int64|20|20
|
||||
Array{String, 1}|std::vector<String>()|cpp_to_julia(stdggvectoriStringkOP())
|
||||
Float64|1|1
|
||||
TermCriteria|TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS,5,1)|cpp_to_julia(TermCriteriaOTermCriteriaggMAXRITERRTermCriteriaggEPSSbSXP())
|
||||
Int64|4|4
|
||||
Int64|LINE_8|cv_LINE_8
|
||||
Float64|0.5|0.5
|
||||
Float64|0.5f|0.5
|
||||
Int64|MARKER_CROSS|cv_MARKER_CROSS
|
||||
Float64|1|1
|
||||
Point{Int32}|Point(-1,-1)|cpp_to_julia(PointOTXSTXP())
|
||||
Float64|CV_PI*0.5|pi*0.5
|
||||
Int64|QT_FONT_NORMAL|cv_QT_FONT_NORMAL
|
||||
Point{Int32}|Point()|cpp_to_julia(PointOP())
|
||||
Float64|CV_PI|pi
|
||||
Float64|-1|-1
|
||||
Int64|300|300
|
||||
Int64|3|3
|
||||
String|""|""
|
||||
Scalar|Scalar()|cpp_to_julia(ScalarOP())
|
||||
Float64|1.f|1
|
||||
Array{Int32, 1}|std::vector<int>()|cpp_to_julia(stdggvectoriintkOP())
|
||||
InputArray|Mat()|CxxMat()
|
||||
Int64|BORDER_DEFAULT|cv_BORDER_DEFAULT
|
||||
Int64|CV_32S|CV_32S
|
||||
Int64|IMREAD_COLOR|cv_IMREAD_COLOR
|
||||
Float64|100|100
|
||||
Size{Int32}|Size(8, 8)|cpp_to_julia(SizeOeSGeP())
|
||||
Array{InputArray, 1}||Array{InputArray, 1}()
|
||||
Int64|GC_EVAL|cv_GC_EVAL
|
||||
Int64|8|8
|
||||
Int64|DIST_LABEL_CCOMP|cv_DIST_LABEL_CCOMP
|
||||
Int64|CAP_ANY|cv_CAP_ANY
|
||||
Float64|0|0
|
||||
Int64|-1|-1
|
||||
Float64|-DBL_MAX|-typemax(Float64)
|
||||
Scalar|Scalar::all(0)|cpp_to_julia(ScalarggallOWP())
|
||||
InputArray||CxxMat()
|
||||
Int64|QT_STYLE_NORMAL|cv_QT_STYLE_NORMAL
|
||||
Int64|INTER_LINEAR|cv_INTER_LINEAR
|
||||
Bool|false|false
|
||||
Int64|CV_64F|CV_64F
|
||||
Point{Int32}|Point(-1, -1)|cpp_to_julia(PointOTXSGTXP())
|
||||
Scalar|morphologyDefaultBorderValue()|cpp_to_julia(morphologyDefaultBorderValueOP())
|
||||
Int64|IMREAD_ANYCOLOR|cv_IMREAD_ANYCOLOR
|
||||
Int64|INT_MAX|typemax(Int32)
|
||||
String|String()|""
|
||||
Float64|1.|1
|
||||
Int64|WINDOW_AUTOSIZE|cv_WINDOW_AUTOSIZE
|
||||
Int64|DECOMP_LU|cv_DECOMP_LU
|
||||
Float64|40.0|40.0
|
||||
Int64|BORDER_CONSTANT|cv_BORDER_CONSTANT
|
||||
Array{UInt8, 1}|std::vector<uchar>()|cpp_to_julia(stdggvectoriucharkOP())
|
||||
Int64|0|0
|
||||
Float64|255.|255
|
||||
Scalar|Scalar(1)|cpp_to_julia(ScalarOXP())
|
||||
Int64|1|1
|
||||
Size{Int32}|Size()|cpp_to_julia(SizeOP())
|
||||
TermCriteria|TermCriteria(TermCriteria::EPS + TermCriteria::COUNT, 20, FLT_EPSILON)|cpp_to_julia(TermCriteriaOTermCriteriaggEPSGRGTermCriteriaggCOUNTSGYWSGFLTREPSILONP())
|
||||
Int64|RANSAC|cv_RANSAC
|
||||
Float64|8.0|8.0
|
||||
Float64|-1|-1
|
||||
Int64|21|21
|
||||
TermCriteria|TermCriteria( TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON)|TermCriteriaOGTermCriteriaggCOUNTGRGTermCriteriaggEPSSGZWSGDBLREPSILONP
|
||||
TermCriteria|TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 1e-6)|TermCriteriaOTermCriteriaggCOUNTRTermCriteriaggEPSSGZWSGXeTcP
|
||||
Int64|CALIB_CB_SYMMETRIC_GRID|cv_CALIB_CB_SYMMETRIC_GRID
|
||||
InputArray|cv::Mat()|CxxMat()
|
||||
Int64|SOLVEPNP_ITERATIVE|cv_SOLVEPNP_ITERATIVE
|
||||
Float64|3|3
|
||||
Int64|CALIB_FIX_INTRINSIC|cv_CALIB_FIX_INTRINSIC
|
||||
Float64|5|5
|
||||
Float64|0.99|0.99
|
||||
Int64|CALIB_ZERO_DISPARITY|cv_CALIB_ZERO_DISPARITY
|
||||
size_t|2000|2000
|
||||
SolvePnPMethod|SOLVEPNP_ITERATIVE|cv_SOLVEPNP_ITERATIVE
|
||||
Float64|0.0|0.0
|
||||
Ptr{Feature2D}|SimpleBlobDetector::create()|SimpleBlobDetectorggcreateOP
|
||||
Int64|StereoSGBM::MODE_SGBM|StereoSGBMggMODERSGBM
|
||||
Int64|CALIB_CB_ADAPTIVE_THRESH + CALIB_CB_NORMALIZE_IMAGE|cv_CALIB_CB_ADAPTIVE_THRESH + cv_CALIB_CB_NORMALIZE_IMAGE
|
||||
Float64|3.|3
|
||||
size_t|10|10
|
||||
Int64|16|16
|
||||
Point{Float64}|Point2d(0, 0)|PointYdOWSGWP
|
||||
Int64|2000|2000
|
||||
Int64|FM_RANSAC|cv_FM_RANSAC
|
||||
Int64|100|100
|
||||
TermCriteria|TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 100, DBL_EPSILON)|TermCriteriaOTermCriteriaggCOUNTGRGTermCriteriaggEPSSGXWWSGDBLREPSILONP
|
||||
HandEyeCalibrationMethod|CALIB_HAND_EYE_TSAI|cv_CALIB_HAND_EYE_TSAI
|
||||
Float64|0.8F|0.8
|
||||
Int64|fisheye::CALIB_FIX_INTRINSIC|cv_fisheye_CALIB_FIX_INTRINSIC
|
||||
Float64|0.999|0.999
|
||||
Float64|0.995|0.995
|
||||
Int64|1000|1000
|
||||
@@ -0,0 +1,490 @@
|
||||
cv.borderInterpolate
|
||||
cv.copyMakeBorder
|
||||
cv.add
|
||||
cv.subtract
|
||||
cv.multiply
|
||||
cv.divide
|
||||
cv.scaleAdd
|
||||
cv.addWeighted
|
||||
cv.convertScaleAbs
|
||||
cv.LUT
|
||||
cv.sum
|
||||
cv.countNonZero
|
||||
cv.findNonZero
|
||||
cv.mean
|
||||
cv.meanStdDev
|
||||
cv.norm
|
||||
cv.PSNR
|
||||
cv.batchDistance
|
||||
cv.normalize
|
||||
cv.minMaxLoc
|
||||
cv.reduce
|
||||
cv.merge
|
||||
cv.split
|
||||
cv.mixChannels
|
||||
cv.extractChannel
|
||||
cv.insertChannel
|
||||
cv.flip
|
||||
cv.rotate
|
||||
cv.repeat
|
||||
cv.hconcat
|
||||
cv.vconcat
|
||||
cv.bitwise_and
|
||||
cv.bitwise_or
|
||||
cv.bitwise_xor
|
||||
cv.bitwise_not
|
||||
cv.absdiff
|
||||
cv.copyTo
|
||||
cv.inRange
|
||||
cv.compare
|
||||
cv.min
|
||||
cv.max
|
||||
cv.sqrt
|
||||
cv.pow
|
||||
cv.exp
|
||||
cv.log
|
||||
cv.polarToCart
|
||||
cv.cartToPolar
|
||||
cv.phase
|
||||
cv.magnitude
|
||||
cv.checkRange
|
||||
cv.patchNaNs
|
||||
cv.gemm
|
||||
cv.mulTransposed
|
||||
cv.transpose
|
||||
cv.transform
|
||||
cv.perspectiveTransform
|
||||
cv.completeSymm
|
||||
cv.setIdentity
|
||||
cv.determinant
|
||||
cv.trace
|
||||
cv.invert
|
||||
cv.solve
|
||||
cv.sort
|
||||
cv.sortIdx
|
||||
cv.solveCubic
|
||||
cv.solvePoly
|
||||
cv.eigen
|
||||
cv.eigenNonSymmetric
|
||||
cv.calcCovarMatrix
|
||||
cv.PCACompute
|
||||
cv.PCAProject
|
||||
cv.PCABackProject
|
||||
cv.SVDecomp
|
||||
cv.SVBackSubst
|
||||
cv.Mahalanobis
|
||||
cv.dft
|
||||
cv.idft
|
||||
cv.dct
|
||||
cv.idct
|
||||
cv.mulSpectrums
|
||||
cv.getOptimalDFTSize
|
||||
cv.setRNGSeed
|
||||
cv.randu
|
||||
cv.randn
|
||||
cv.randShuffle
|
||||
cv.kmeans
|
||||
cv.cubeRoot
|
||||
cv.fastAtan2
|
||||
cv.ipp.useIPP
|
||||
cv.ipp.setUseIPP
|
||||
cv.ipp.getIppVersion
|
||||
cv.ipp.useIPP_NotExact
|
||||
cv.ipp.setUseIPP_NotExact
|
||||
cv.utils.dumpInputArray
|
||||
cv.utils.dumpInputArrayOfArrays
|
||||
cv.utils.dumpInputOutputArray
|
||||
cv.utils.dumpInputOutputArrayOfArrays
|
||||
cv.utils.dumpBool
|
||||
cv.utils.dumpInt
|
||||
cv.utils.dumpSizeT
|
||||
cv.utils.dumpFloat
|
||||
cv.utils.dumpDouble
|
||||
cv.utils.dumpCString
|
||||
cv.utils.testAsyncArray
|
||||
cv.utils.testAsyncException
|
||||
cv.solveLP
|
||||
cv.FileStorage.FileStorage
|
||||
cv.FileStorage.open
|
||||
cv.FileStorage.isOpened
|
||||
cv.FileStorage.release
|
||||
cv.FileStorage.releaseAndGetString
|
||||
cv.FileStorage.getFirstTopLevelNode
|
||||
cv.FileStorage.root
|
||||
#cv.FileStorage.operator[]
|
||||
cv.FileStorage.write
|
||||
cv.FileStorage.writeComment
|
||||
cv.FileStorage.startWriteStruct
|
||||
cv.FileStorage.endWriteStruct
|
||||
cv.FileStorage.getFormat
|
||||
cv.FileNode.FileNode
|
||||
cv.FileNode.keys
|
||||
cv.FileNode.type
|
||||
cv.FileNode.empty
|
||||
cv.FileNode.isNone
|
||||
cv.FileNode.isSeq
|
||||
cv.FileNode.isMap
|
||||
cv.FileNode.isInt
|
||||
cv.FileNode.isReal
|
||||
cv.FileNode.isString
|
||||
cv.FileNode.isNamed
|
||||
cv.FileNode.name
|
||||
cv.FileNode.size
|
||||
cv.FileNode.rawSize
|
||||
cv.FileNode.real
|
||||
cv.FileNode.string
|
||||
cv.FileNode.mat
|
||||
cv.KeyPoint.KeyPoint
|
||||
cv.KeyPoint.convert
|
||||
cv.KeyPoint.overlap
|
||||
cv.DMatch.DMatch
|
||||
cv.setNumThreads
|
||||
cv.getNumThreads
|
||||
cv.getThreadNum
|
||||
cv.getBuildInformation
|
||||
cv.getVersionString
|
||||
cv.getVersionMajor
|
||||
cv.getVersionMinor
|
||||
cv.getVersionRevision
|
||||
cv.getTickCount
|
||||
cv.getTickFrequency
|
||||
cv.Subdiv2D.Subdiv2D
|
||||
cv.Subdiv2D.initDelaunay
|
||||
cv.Subdiv2D.insert
|
||||
cv.Subdiv2D.locate
|
||||
cv.Subdiv2D.findNearest
|
||||
cv.Subdiv2D.getEdgeList
|
||||
cv.Subdiv2D.getLeadingEdgeList
|
||||
cv.Subdiv2D.getTriangleList
|
||||
cv.Subdiv2D.getVoronoiFacetList
|
||||
cv.Subdiv2D.getVertex
|
||||
cv.Subdiv2D.getEdge
|
||||
cv.Subdiv2D.nextEdge
|
||||
cv.Subdiv2D.rotateEdge
|
||||
cv.Subdiv2D.symEdge
|
||||
cv.Subdiv2D.edgeOrg
|
||||
cv.Subdiv2D.edgeDst
|
||||
cv.getGaussianKernel
|
||||
cv.getDerivKernels
|
||||
cv.getGaborKernel
|
||||
cv.getStructuringElement
|
||||
cv.medianBlur
|
||||
cv.GaussianBlur
|
||||
cv.bilateralFilter
|
||||
cv.boxFilter
|
||||
cv.sqrBoxFilter
|
||||
cv.blur
|
||||
cv.filter2D
|
||||
cv.sepFilter2D
|
||||
cv.Sobel
|
||||
cv.spatialGradient
|
||||
cv.Scharr
|
||||
cv.Laplacian
|
||||
cv.Canny
|
||||
cv.cornerMinEigenVal
|
||||
cv.cornerHarris
|
||||
cv.cornerEigenValsAndVecs
|
||||
cv.preCornerDetect
|
||||
cv.cornerSubPix
|
||||
cv.goodFeaturesToTrack
|
||||
cv.HoughLines
|
||||
cv.HoughLinesP
|
||||
cv.HoughLinesPointSet
|
||||
cv.HoughCircles
|
||||
cv.erode
|
||||
cv.dilate
|
||||
cv.morphologyEx
|
||||
cv.resize
|
||||
cv.warpAffine
|
||||
cv.warpPerspective
|
||||
cv.remap
|
||||
cv.convertMaps
|
||||
cv.getRotationMatrix2D
|
||||
cv.invertAffineTransform
|
||||
cv.getPerspectiveTransform
|
||||
cv.getAffineTransform
|
||||
cv.getRectSubPix
|
||||
cv.logPolar
|
||||
cv.linearPolar
|
||||
cv.warpPolar
|
||||
cv.integral
|
||||
cv.accumulate
|
||||
cv.accumulateSquare
|
||||
cv.accumulateProduct
|
||||
cv.accumulateWeighted
|
||||
cv.phaseCorrelate
|
||||
cv.createHanningWindow
|
||||
cv.threshold
|
||||
cv.adaptiveThreshold
|
||||
cv.pyrDown
|
||||
cv.pyrUp
|
||||
cv.calcHist
|
||||
cv.calcBackProject
|
||||
cv.compareHist
|
||||
cv.equalizeHist
|
||||
cv.createCLAHE
|
||||
cv.wrapperEMD
|
||||
cv.watershed
|
||||
cv.pyrMeanShiftFiltering
|
||||
cv.grabCut
|
||||
cv.distanceTransform
|
||||
cv.floodFill
|
||||
cv.cvtColor
|
||||
cv.cvtColorTwoPlane
|
||||
cv.demosaicing
|
||||
cv.moments
|
||||
cv.HuMoments
|
||||
cv.matchTemplate
|
||||
cv.connectedComponents
|
||||
cv.connectedComponentsWithStats
|
||||
cv.findContours
|
||||
cv.approxPolyDP
|
||||
cv.arcLength
|
||||
cv.boundingRect
|
||||
cv.contourArea
|
||||
cv.minAreaRect
|
||||
cv.boxPoints
|
||||
cv.minEnclosingCircle
|
||||
cv.minEnclosingTriangle
|
||||
cv.matchShapes
|
||||
cv.convexHull
|
||||
cv.convexityDefects
|
||||
cv.isContourConvex
|
||||
cv.intersectConvexConvex
|
||||
cv.fitEllipse
|
||||
cv.fitEllipseAMS
|
||||
cv.fitEllipseDirect
|
||||
cv.fitLine
|
||||
cv.pointPolygonTest
|
||||
cv.rotatedRectangleIntersection
|
||||
cv.createGeneralizedHoughBallard
|
||||
cv.createGeneralizedHoughGuil
|
||||
cv.applyColorMap
|
||||
cv.line
|
||||
cv.arrowedLine
|
||||
cv.rectangle
|
||||
cv.circle
|
||||
cv.ellipse
|
||||
cv.drawMarker
|
||||
cv.fillConvexPoly
|
||||
cv.fillPoly
|
||||
cv.polylines
|
||||
cv.drawContours
|
||||
cv.clipLine
|
||||
cv.ellipse2Poly
|
||||
cv.putText
|
||||
cv.getTextSize
|
||||
cv.getFontScaleFromHeight
|
||||
cv.dnn.Net.Net
|
||||
cv.dnn.Net.readFromModelOptimizer
|
||||
cv.dnn.Net.empty
|
||||
cv.dnn.Net.dump
|
||||
cv.dnn.Net.dumpToFile
|
||||
cv.dnn.Net.setInputShape
|
||||
cv.dnn.Net.forwardAsync
|
||||
cv.dnn.Net.forward
|
||||
cv.dnn.Net.setPreferableBackend
|
||||
cv.dnn.Net.setPreferableTarget
|
||||
cv.dnn.Net.setInput
|
||||
cv.dnn.Net.setParam
|
||||
cv.dnn.Net.getParam
|
||||
cv.dnn.Net.getFLOPS
|
||||
cv.dnn.Net.getMemoryConsumption
|
||||
cv.dnn.Net.enableFusion
|
||||
cv.dnn.Net.getPerfProfile
|
||||
cv.dnn.readNetFromTensorflow
|
||||
cv.dnn.readNetFromTorch
|
||||
cv.dnn.readNet
|
||||
cv.dnn.readTorchBlob
|
||||
cv.dnn.readNetFromModelOptimizer
|
||||
cv.dnn.readNetFromONNX
|
||||
cv.dnn.readTensorFromONNX
|
||||
cv.dnn.blobFromImage
|
||||
cv.dnn.blobFromImages
|
||||
cv.dnn.imagesFromBlob
|
||||
cv.dnn.shrinkCaffeModel
|
||||
cv.dnn.writeTextGraph
|
||||
cv.dnn.NMSBoxes
|
||||
cv.dnn.Model.Model
|
||||
cv.dnn.Model.setInputSize
|
||||
cv.dnn.Model.setInputMean
|
||||
cv.dnn.Model.setInputScale
|
||||
cv.dnn.Model.setInputCrop
|
||||
cv.dnn.Model.setInputSwapRB
|
||||
cv.dnn.Model.setInputParams
|
||||
cv.dnn.Model.setPreferableTarget
|
||||
cv.dnn.Model.predict
|
||||
cv.dnn.ClassificationModel.ClassificationModel
|
||||
cv.dnn.ClassificationModel.classify
|
||||
cv.dnn.KeypointsModel.KeypointsModel
|
||||
cv.dnn.KeypointsModel.estimate
|
||||
cv.dnn.SegmentationModel.SegmentationModel
|
||||
cv.dnn.SegmentationModel.segment
|
||||
cv.dnn.DetectionModel.DetectionModel
|
||||
cv.dnn.DetectionModel.detect
|
||||
cv.imread
|
||||
cv.imreadmulti
|
||||
cv.imwrite
|
||||
cv.imdecode
|
||||
cv.imencode
|
||||
cv.haveImageReader
|
||||
cv.haveImageWriter
|
||||
cv.VideoCapture.VideoCapture
|
||||
cv.VideoCapture.open
|
||||
cv.VideoCapture.isOpened
|
||||
cv.VideoCapture.release
|
||||
cv.VideoCapture.grab
|
||||
cv.VideoCapture.retrieve
|
||||
cv.VideoCapture.read
|
||||
cv.VideoCapture.set
|
||||
cv.VideoCapture.get
|
||||
cv.VideoCapture.getBackendName
|
||||
cv.VideoCapture.setExceptionMode
|
||||
cv.VideoCapture.getExceptionMode
|
||||
cv.VideoWriter.VideoWriter
|
||||
cv.VideoWriter.open
|
||||
cv.VideoWriter.isOpened
|
||||
cv.VideoWriter.release
|
||||
cv.VideoWriter.write
|
||||
cv.VideoWriter.set
|
||||
cv.VideoWriter.get
|
||||
cv.VideoWriter.fourcc
|
||||
cv.VideoWriter.getBackendName
|
||||
cv.namedWindow
|
||||
cv.destroyWindow
|
||||
cv.destroyAllWindows
|
||||
cv.startWindowThread
|
||||
cv.waitKeyEx
|
||||
cv.waitKey
|
||||
cv.imshow
|
||||
cv.resizeWindow
|
||||
cv.moveWindow
|
||||
cv.setWindowProperty
|
||||
cv.setWindowTitle
|
||||
cv.getWindowProperty
|
||||
cv.getWindowImageRect
|
||||
cv.selectROI
|
||||
cv.selectROIs
|
||||
cv.getTrackbarPos
|
||||
cv.setTrackbarPos
|
||||
cv.setTrackbarMax
|
||||
cv.setTrackbarMin
|
||||
cv.addText
|
||||
cv.displayOverlay
|
||||
cv.displayStatusBar
|
||||
cv.Rodrigues
|
||||
cv.findHomography
|
||||
cv.RQDecomp3x3
|
||||
cv.decomposeProjectionMatrix
|
||||
cv.matMulDeriv
|
||||
cv.composeRT
|
||||
cv.projectPoints
|
||||
cv.solvePnP
|
||||
cv.solvePnPRansac
|
||||
cv.solveP3P
|
||||
cv.solvePnPRefineLM
|
||||
cv.solvePnPRefineVVS
|
||||
cv.solvePnPGeneric
|
||||
cv.initCameraMatrix2D
|
||||
cv.findChessboardCorners
|
||||
cv.checkChessboard
|
||||
cv.findChessboardCornersSB
|
||||
cv.findChessboardCornersSB
|
||||
cv.estimateChessboardSharpness
|
||||
cv.find4QuadCornerSubpix
|
||||
cv.drawChessboardCorners
|
||||
cv.drawFrameAxes
|
||||
cv.CirclesGridFinderParameters.CirclesGridFinderParameters
|
||||
cv.findCirclesGrid
|
||||
cv.findCirclesGrid
|
||||
cv.calibrateCamera
|
||||
cv.calibrateCamera
|
||||
cv.calibrateCameraRO
|
||||
cv.calibrateCameraRO
|
||||
cv.calibrationMatrixValues
|
||||
cv.stereoCalibrate
|
||||
cv.stereoCalibrate
|
||||
cv.stereoRectify
|
||||
cv.stereoRectifyUncalibrated
|
||||
cv.rectify3Collinear
|
||||
cv.getOptimalNewCameraMatrix
|
||||
cv.calibrateHandEye
|
||||
cv.convertPointsToHomogeneous
|
||||
cv.convertPointsFromHomogeneous
|
||||
cv.findFundamentalMat
|
||||
cv.findFundamentalMat
|
||||
cv.findEssentialMat
|
||||
cv.findEssentialMat
|
||||
cv.decomposeEssentialMat
|
||||
cv.recoverPose
|
||||
cv.recoverPose
|
||||
cv.recoverPose
|
||||
cv.computeCorrespondEpilines
|
||||
cv.triangulatePoints
|
||||
cv.correctMatches
|
||||
cv.filterSpeckles
|
||||
cv.getValidDisparityROI
|
||||
cv.validateDisparity
|
||||
cv.reprojectImageTo3D
|
||||
cv.sampsonDistance
|
||||
cv.estimateAffine3D
|
||||
cv.estimateTranslation3D
|
||||
cv.estimateAffine2D
|
||||
cv.estimateAffinePartial2D
|
||||
cv.decomposeHomographyMat
|
||||
cv.filterHomographyDecompByVisibleRefpoints
|
||||
cv.StereoMatcher.compute
|
||||
cv.StereoMatcher.getMinDisparity
|
||||
cv.StereoMatcher.setMinDisparity
|
||||
cv.StereoMatcher.getNumDisparities
|
||||
cv.StereoMatcher.setNumDisparities
|
||||
cv.StereoMatcher.getBlockSize
|
||||
cv.StereoMatcher.setBlockSize
|
||||
cv.StereoMatcher.getSpeckleWindowSize
|
||||
cv.StereoMatcher.setSpeckleWindowSize
|
||||
cv.StereoMatcher.getSpeckleRange
|
||||
cv.StereoMatcher.setSpeckleRange
|
||||
cv.StereoMatcher.getDisp12MaxDiff
|
||||
cv.StereoMatcher.setDisp12MaxDiff
|
||||
cv.StereoBM.getPreFilterType
|
||||
cv.StereoBM.setPreFilterType
|
||||
cv.StereoBM.getPreFilterSize
|
||||
cv.StereoBM.setPreFilterSize
|
||||
cv.StereoBM.getPreFilterCap
|
||||
cv.StereoBM.setPreFilterCap
|
||||
cv.StereoBM.getTextureThreshold
|
||||
cv.StereoBM.setTextureThreshold
|
||||
cv.StereoBM.getUniquenessRatio
|
||||
cv.StereoBM.setUniquenessRatio
|
||||
cv.StereoBM.getSmallerBlockSize
|
||||
cv.StereoBM.setSmallerBlockSize
|
||||
cv.StereoBM.getROI1
|
||||
cv.StereoBM.setROI1
|
||||
cv.StereoBM.getROI2
|
||||
cv.StereoBM.setROI2
|
||||
cv.StereoBM.create
|
||||
cv.StereoSGBM.getPreFilterCap
|
||||
cv.StereoSGBM.setPreFilterCap
|
||||
cv.StereoSGBM.getUniquenessRatio
|
||||
cv.StereoSGBM.setUniquenessRatio
|
||||
cv.StereoSGBM.getP1
|
||||
cv.StereoSGBM.setP1
|
||||
cv.StereoSGBM.getP2
|
||||
cv.StereoSGBM.setP2
|
||||
cv.StereoSGBM.getMode
|
||||
cv.StereoSGBM.setMode
|
||||
cv.StereoSGBM.create
|
||||
cv.undistort
|
||||
cv.initUndistortRectifyMap
|
||||
cv.getDefaultNewCameraMatrix
|
||||
cv.undistortPoints
|
||||
cv.undistortPoints
|
||||
cv.fisheye.projectPoints
|
||||
cv.fisheye.distortPoints
|
||||
cv.fisheye.undistortPoints
|
||||
cv.fisheye.initUndistortRectifyMap
|
||||
cv.fisheye.undistortImage
|
||||
cv.fisheye.estimateNewCameraMatrixForUndistortRectify
|
||||
cv.fisheye.calibrate
|
||||
cv.fisheye.stereoRectify
|
||||
cv.fisheye.stereoCalibrate
|
||||
|
@@ -0,0 +1,332 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# This file is part of OpenCV project.
|
||||
# It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
# of this distribution and at http://opencv.org/license.html
|
||||
# Copyright (C) 2020 by Archit Rungta
|
||||
|
||||
from __future__ import unicode_literals # Needed for python2
|
||||
|
||||
import hdr_parser, sys, re, os
|
||||
from string import Template
|
||||
from pprint import pprint
|
||||
from collections import namedtuple
|
||||
|
||||
import os, shutil
|
||||
|
||||
if sys.version_info[0] >= 3:
|
||||
from io import StringIO
|
||||
else:
|
||||
from cStringIO import StringIO
|
||||
|
||||
|
||||
from parse_tree import *
|
||||
|
||||
mod_template = ""
|
||||
with open("binding_templates_cpp/cv_core.cpp", "r") as f:
|
||||
mod_template = Template(f.read())
|
||||
|
||||
|
||||
def normalize_name(name):
|
||||
return name.replace('.', '::')
|
||||
|
||||
def normalize_class_name(name):
|
||||
_, classes, name = split_decl_name(normalize_name(name))
|
||||
return "_".join(classes+[name])
|
||||
|
||||
def normalize_full_name(name):
|
||||
ns, classes, name = split_decl_name(normalize_name(name))
|
||||
return "::".join(ns)+'::'+'_'.join(classes+[name])
|
||||
|
||||
|
||||
|
||||
def split_decl_name(name):
|
||||
chunks = name.split('::')
|
||||
namespace = chunks[:-1]
|
||||
classes = []
|
||||
while namespace and '::'.join(namespace) not in namespaces:
|
||||
classes.insert(0, namespace.pop())
|
||||
|
||||
ns = '::'.join(namespace)
|
||||
if ns not in namespaces and ns:
|
||||
assert(0)
|
||||
|
||||
return namespace, classes, chunks[-1]
|
||||
|
||||
def registered_tp_search(tp):
|
||||
found = False
|
||||
if not tp:
|
||||
return True
|
||||
for tpx in registered_types:
|
||||
if re.findall(tpx, tp):
|
||||
found = True
|
||||
break
|
||||
return found
|
||||
|
||||
namespaces = {}
|
||||
enums = []
|
||||
classes = {}
|
||||
functions = {}
|
||||
registered_types = ["int", "Size.*", "Rect.*", "Scalar", "RotatedRect", "Point.*", "explicit", "string", "bool", "uchar",
|
||||
"Vec.*", "float", "double", "char", "Mat", "size_t", "RNG", "TermCriteria"]
|
||||
|
||||
class ClassInfo(ClassInfo):
|
||||
def get_cpp_code_header(self):
|
||||
if self.ismap:
|
||||
return 'mod.map_type<%s>("%s");\n'%(self.name, self.mapped_name)
|
||||
if not self.base:
|
||||
return 'mod.add_type<%s>("%s");\n' % (self.name, self.mapped_name)
|
||||
else:
|
||||
return 'mod.add_type<%s>("%s", jlcxx::julia_base_type<%s>());\n' % (self.name, self.mapped_name, self.base)
|
||||
|
||||
def get_cpp_code_body(self):
|
||||
if self.ismap:
|
||||
return ''
|
||||
cpp_code = StringIO()
|
||||
for cons in self.constructors:
|
||||
cons.__class__ = FuncVariant
|
||||
cpp_code.write(cons.get_cons_code(self.name, self.mapped_name))
|
||||
#add get/set
|
||||
cpp_code.write('\n')
|
||||
cpp_code.write(self.get_setters())
|
||||
cpp_code.write('\n')
|
||||
cpp_code.write(self.get_getters())
|
||||
cpp_code.write(';')
|
||||
return cpp_code.getvalue()
|
||||
|
||||
# return code for functions and setters and getters if simple class or functions and map type
|
||||
|
||||
def get_prop_func_cpp(self, mode, propname):
|
||||
return "jlopencv_" + self.mapped_name + "_"+mode+"_"+propname
|
||||
|
||||
def get_getters(self):
|
||||
stra = ""
|
||||
for prop in self.props:
|
||||
if not self.isalgorithm:
|
||||
stra = stra + '\nmod.method("%s", [](const %s &cobj) {return %scobj.%s;});' % (self.get_prop_func_cpp("get", prop.name), self.name, '(int)' if prop.tp in enums else '', prop.name)
|
||||
else:
|
||||
stra = stra + '\nmod.method("%s", [](const cv::Ptr<%s> &cobj) {return %scobj->%s;});' % (self.get_prop_func_cpp("get", prop.name), self.name,'(int)' if prop.tp in enums else '', prop.name)
|
||||
return stra
|
||||
|
||||
def get_setters(self):
|
||||
stra = ""
|
||||
for prop in self.props:
|
||||
if prop.readonly:
|
||||
continue
|
||||
if not self.isalgorithm:
|
||||
stra = stra + '\nmod.method("%s", [](%s &cobj,const force_enum_int<%s>::Type &v) {cobj.%s=(%s)v;});' % (self.get_prop_func_cpp("set", prop.name), self.name, prop.tp, prop.name, prop.tp)
|
||||
else:
|
||||
stra = stra + '\nmod.method("%s", [](cv::Ptr<%s> cobj, const force_enum_int<%s>::Type &v) {cobj->%s=(%s)v;});' % (self.get_prop_func_cpp("set", prop.name), self.name, prop.tp, prop.name, prop.tp)
|
||||
return stra
|
||||
|
||||
class FuncVariant(FuncVariant):
|
||||
|
||||
def get_return(self):
|
||||
outstr = ""
|
||||
for arg in self.inlist+self.optlist:
|
||||
if arg.tp not in pass_by_val_types and arg.tp not in enums and self.promote_type(arg.tp)!=arg.tp:
|
||||
outstr = outstr + "%s=%s_down;\n"%(arg.name, arg.name)
|
||||
|
||||
if len(self.outlist)==0:
|
||||
return outstr+";"
|
||||
elif len(self.outlist)==1:
|
||||
return outstr+"return %s;" % ( ('(int64_t)' if self.outlist[0].tp in enums else ('' if self.promote_type(self.outlist[0].tp)==self.outlist[0].tp else '(%s)'%self.promote_type(self.outlist[0].tp))) + self.outlist[0].name)
|
||||
return outstr+"return make_tuple(%s);" % ",".join(["move(%s)" % (('(int64_t)' if x.tp in enums else ('' if self.promote_type(x.tp)==x.tp else '(%s)'%self.promote_type(x.tp))) +x.name) for x in self.outlist])
|
||||
|
||||
def promote_type(self, tp):
|
||||
if tp=='int':
|
||||
return 'long long'
|
||||
elif tp =='float':
|
||||
return 'double'
|
||||
return tp
|
||||
|
||||
def get_argument(self, isalgo):
|
||||
args = self.inlist + self.optlist
|
||||
if self.classname!="" and not self.isconstructor and not self.isstatic:
|
||||
if isalgo:
|
||||
args = [ArgInfo("cobj", ("cv::Ptr<%s>" % self.classname))] + args
|
||||
else:
|
||||
args = [ArgInfo("cobj", self.classname)] + args
|
||||
|
||||
argnamelist = []
|
||||
for arg in args:
|
||||
if arg.tp in pass_by_val_types:
|
||||
print("PATHWAY NOT TESTED")
|
||||
argnamelist.append(arg.tp[:-1] +"& "+arg.name)
|
||||
elif arg.tp in enums:
|
||||
argnamelist.append("int64_t& " + arg.name)
|
||||
else:
|
||||
if arg.tp=='bool':
|
||||
# Bool pass-by-reference is broken
|
||||
argnamelist.append(arg.tp+" " +arg.name)
|
||||
else:
|
||||
argnamelist.append(self.promote_type(arg.tp) + "& "+arg.name)
|
||||
# argnamelist = [(arg.tp if arg.tp not in pass_by_val_types else arg.tp[:-1]) +"& "+arg.name for arg in args]
|
||||
argstr = ", ".join(argnamelist)
|
||||
return argstr
|
||||
|
||||
def get_def_outtypes(self):
|
||||
outstr = ""
|
||||
for arg in self.deflist:
|
||||
outstr = outstr + "%s %s;"%(arg.tp if arg.tp not in pass_by_val_types else arg.tp[:-1], arg.name)
|
||||
for arg in self.inlist+self.optlist:
|
||||
if arg.tp not in pass_by_val_types and arg.tp not in enums and self.promote_type(arg.tp)!=arg.tp:
|
||||
outstr = outstr + "%s %s_down=(%s)%s;"%(arg.tp if arg.tp not in pass_by_val_types else arg.tp[:-1], arg.name, arg.tp, arg.name)
|
||||
|
||||
return outstr
|
||||
|
||||
def get_retval(self, isalgo):
|
||||
if self.rettype:
|
||||
stra = "auto retval = "
|
||||
else:
|
||||
stra = ""
|
||||
arlist = []
|
||||
for x in self.args:
|
||||
if x.tp in pass_by_val_types:
|
||||
arlist.append("&"+x.name)
|
||||
elif x.tp in enums:
|
||||
arlist.append("(%s)%s" %(x.tp, x.name))
|
||||
else:
|
||||
if self.promote_type(x.tp) == x.tp:
|
||||
arlist.append(x.name)
|
||||
else:
|
||||
if len([y for y in self.inlist+self.optlist if y.name==x.name])>0:
|
||||
# print("ss")
|
||||
arlist.append("%s_down" %(x.name))
|
||||
else:
|
||||
arlist.append(x.name)
|
||||
|
||||
argstr = ", ".join(arlist)
|
||||
if self.classname and not self.isstatic:
|
||||
stra = stra + "cobj%s%s(%s); " %("->" if isalgo else ".",self.name.split('::')[-1], argstr)
|
||||
else:
|
||||
stra = stra + "%s(%s);" % (self.name, argstr)
|
||||
return stra
|
||||
|
||||
def get_cons_code(self, name, mapped_name):
|
||||
# if self.get_argument(False) == '':
|
||||
# return ''
|
||||
arglist = []
|
||||
for x in self.args:
|
||||
if x.tp in pass_by_val_types:
|
||||
arglist.append("&"+x.name)
|
||||
elif x.tp in enums:
|
||||
arglist.append("(%s)%s" %(x.tp, x.name))
|
||||
else:
|
||||
if self.promote_type(x.tp) == x.tp:
|
||||
arglist.append(x.name)
|
||||
else:
|
||||
# print("ss")
|
||||
arglist.append("%s_down" %(x.name))
|
||||
return 'mod.method("%s", [](%s) { %s return jlcxx::create<%s>(%s);});' % (self.get_wrapper_name(), self.get_argument(False), self.get_def_outtypes(), name, " ,".join(arglist))
|
||||
|
||||
def get_complete_code(self, classname, isalgo=False):
|
||||
outstr = '.method("%s", [](%s) {%s %s %s})' % (self.get_wrapper_name(), self.get_argument(isalgo),self.get_def_outtypes(), self.get_retval(isalgo), self.get_return())
|
||||
return outstr
|
||||
|
||||
|
||||
|
||||
def gen(srcfiles):
|
||||
namespaces, default_values = gen_tree(srcfiles)
|
||||
cpp_code = StringIO()
|
||||
include_code = StringIO()
|
||||
nsi = sorted(namespaces.items(), key =lambda x: x[0])
|
||||
|
||||
for name, ns in nsi:
|
||||
cpp_code.write("using namespace %s;\n" % name.replace(".", "::"))
|
||||
|
||||
if name.split('.')[-1] == '':
|
||||
continue
|
||||
nsname = name
|
||||
nsprefix = '_'.join(nsname.split('::')[1:])
|
||||
|
||||
def sort_classes(classes):
|
||||
class_inherits = []
|
||||
class_inherits_names = set()
|
||||
class_noinherits = []
|
||||
parent = {}
|
||||
for name, cl in classes:
|
||||
if cl.base:
|
||||
class_inherits.append((name, cl))
|
||||
parent[name] = cl.base
|
||||
class_inherits_names.add(name)
|
||||
else:
|
||||
class_noinherits.append((name,cl))
|
||||
|
||||
final_order = class_noinherits
|
||||
|
||||
while len(class_inherits)>0:
|
||||
for cli in class_inherits:
|
||||
if parent[cli[0]] not in class_inherits_names:
|
||||
final_order.append(cli)
|
||||
class_inherits.remove(cli)
|
||||
class_inherits_names.remove(cli[0])
|
||||
|
||||
|
||||
return final_order
|
||||
|
||||
sorted_cls = sort_classes(ns.classes.items())
|
||||
for name, cl in sorted_cls:
|
||||
cl.__class__ = ClassInfo
|
||||
cpp_code.write(cl.get_cpp_code_header())
|
||||
if cl.base:
|
||||
include_code.write("""
|
||||
template <>
|
||||
struct SuperType<%s>
|
||||
{
|
||||
typedef %s type;
|
||||
};
|
||||
""" % (cl.name.replace('.', '::'), cl.base.replace('.', '::')))
|
||||
|
||||
for e1,e2 in ns.enums.items():
|
||||
# cpp_code.write('\n mod.add_bits<{0}>("{1}", jlcxx::julia_type("CppEnum"));'.format(e2[0], e2[1]))
|
||||
enums.append(e2[0])
|
||||
enums.append(e2[1])
|
||||
enums.append(e2[0].replace("cv::", "").replace("::", '_'))
|
||||
|
||||
|
||||
for tp in ns.register_types:
|
||||
cpp_code.write(' mod.add_type<%s>("%s");\n' %(tp, normalize_class_name(tp)))
|
||||
|
||||
# print(enums)
|
||||
for name, ns in namespaces.items():
|
||||
|
||||
nsname = name.replace("::", "_")
|
||||
for name, cl in ns.classes.items():
|
||||
cl.__class__ = ClassInfo
|
||||
cpp_code.write(cl.get_cpp_code_body())
|
||||
for mname, fs in cl.methods.items():
|
||||
for f in fs:
|
||||
f.__class__ = FuncVariant
|
||||
cpp_code.write('\n mod%s;' % f.get_complete_code(cl.name, cl.isalgorithm))
|
||||
# for f in cl.constructors:
|
||||
# cpp_code.write('\n %s; \n' % f.get_cons_code(cl.name, cl.mapped_name))
|
||||
|
||||
|
||||
for mname, fs in ns.funcs.items():
|
||||
for f in fs:
|
||||
f.__class__ = FuncVariant
|
||||
cpp_code.write('\n mod%s;' % f.get_complete_code("", False))
|
||||
|
||||
for mapname, name in sorted(ns.consts.items()):
|
||||
cpp_code.write(' mod.set_const("%s_%s", (force_enum_int<decltype(%s)>::Type)%s);\n'%(nsname, name, mapname, mapname))
|
||||
compat_name = re.sub(r"([a-z])([A-Z])", r"\1_\2", name).upper()
|
||||
if name != compat_name:
|
||||
cpp_code.write(' mod.set_const("%s_%s", (force_enum_int<decltype(%s)>::Type)%s);\n'%(nsname, compat_name, mapname, mapname))
|
||||
default_values = list(set(default_values))
|
||||
for val in default_values:
|
||||
# val = handle_cpp_arg(val)
|
||||
|
||||
cpp_code.write(' mod.method("%s", [](){return (force_enum_int<decltype(%s)>::Type)%s;});\n'%(get_var(val), val, val))
|
||||
|
||||
with open ('autogen_cpp/cv_core.cpp', 'w') as fd:
|
||||
fd.write(mod_template.substitute(include_code = include_code.getvalue(), cpp_code=cpp_code.getvalue()))
|
||||
|
||||
|
||||
|
||||
srcfiles = hdr_parser.opencv_hdr_list
|
||||
if len(sys.argv) > 1:
|
||||
srcfiles = [l.strip() for l in sys.argv[1].split(';')]
|
||||
|
||||
|
||||
gen(srcfiles)
|
||||
@@ -0,0 +1,99 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# This file is part of OpenCV project.
|
||||
# It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
# of this distribution and at http://opencv.org/license.html
|
||||
# Copyright (C) 2020 by Archit Rungta
|
||||
|
||||
|
||||
from __future__ import unicode_literals # Needed for python2
|
||||
|
||||
import hdr_parser, sys, re, os
|
||||
from string import Template
|
||||
from pprint import pprint
|
||||
from collections import namedtuple
|
||||
if sys.version_info[0] >= 3:
|
||||
from io import StringIO
|
||||
else:
|
||||
from cStringIO import StringIO
|
||||
import os, shutil
|
||||
|
||||
from parse_tree import *
|
||||
|
||||
|
||||
|
||||
submodule_template = Template('')
|
||||
root_template = Template('')
|
||||
with open("binding_templates_jl/template_cv2_submodule.jl", "r") as f:
|
||||
submodule_template = Template(f.read())
|
||||
with open("binding_templates_jl/template_cv2_root.jl", "r") as f:
|
||||
root_template = Template(f.read())
|
||||
|
||||
|
||||
class FuncVariant(FuncVariant):
|
||||
|
||||
def get_complete_code(self, classname='', isalgo = False, iscons = False, gen_default = True, ns = ''):
|
||||
return 'const %s = OpenCV.%s_%s' %(self.mapped_name, ns, self.mapped_name)
|
||||
|
||||
|
||||
def gen(srcfiles):
|
||||
namespaces, _ = gen_tree(srcfiles)
|
||||
|
||||
jl_code = StringIO()
|
||||
for name, ns in namespaces.items():
|
||||
# cv_types.extend(ns.registered)
|
||||
jl_code = StringIO()
|
||||
nsname = '_'.join(name.split('::')[1:])
|
||||
|
||||
# Do not duplicate functions. This should prevent overwriting of Mat function by UMat functions
|
||||
function_signatures = []
|
||||
if name != 'cv':
|
||||
for cname, cl in ns.classes.items():
|
||||
cl.__class__ = ClassInfo
|
||||
for mname, fs in cl.methods.items():
|
||||
for f in fs:
|
||||
f.__class__ = FuncVariant
|
||||
if f.mapped_name in function_signatures:
|
||||
print("Skipping entirely: ", f.name)
|
||||
continue
|
||||
jl_code.write('\n%s' % f.get_complete_code(isalgo = cl.isalgorithm, ns=nsname))
|
||||
function_signatures.append(f.mapped_name)
|
||||
for f in cl.constructors:
|
||||
f.__class__ = FuncVariant
|
||||
jl_code.write('\n%s' % f.get_complete_code(classname = cl.mapped_name, isalgo = cl.isalgorithm, iscons = True, ns=nsname))
|
||||
break
|
||||
for mname, fs in ns.funcs.items():
|
||||
for f in fs:
|
||||
f.__class__ = FuncVariant
|
||||
if f.mapped_name in function_signatures:
|
||||
continue
|
||||
jl_code.write('\n%s' % f.get_complete_code(ns=nsname))
|
||||
function_signatures.append(f.mapped_name)
|
||||
jl_code.write('\n')
|
||||
for mapname, cname in sorted(ns.consts.items()):
|
||||
jl_code.write(' const %s = OpenCV.%s_%s\n'%(cname, name.replace('::', '_'), cname))
|
||||
compat_name = re.sub(r"([a-z])([A-Z])", r"\1_\2", cname).upper()
|
||||
if cname != compat_name:
|
||||
jl_code.write(' const %s = OpenCV.%s_%s;\n'%(compat_name, name.replace('::', '_'), compat_name))
|
||||
|
||||
imports = ''
|
||||
for namex in namespaces:
|
||||
if namex.startswith(name) and len(namex.split('::')) == 1 + len(name.split('::')):
|
||||
imports = imports + '\ninclude("%s_wrap.jl")'%namex.replace('::', '_')
|
||||
code = ''
|
||||
if name == 'cv':
|
||||
code = root_template.substitute(modname = name, code = jl_code.getvalue(), submodule_imports = imports)
|
||||
else:
|
||||
code = submodule_template.substitute(modname = name.split('::')[-1], code = jl_code.getvalue(), submodule_imports = imports)
|
||||
|
||||
with open ('autogen_jl/%s_wrap.jl' % ns.name.replace('::', '_'), 'w') as fd:
|
||||
fd.write(code)
|
||||
|
||||
|
||||
|
||||
srcfiles = hdr_parser.opencv_hdr_list
|
||||
if len(sys.argv) > 1:
|
||||
srcfiles = [l.strip() for l in sys.argv[1].split(';')]
|
||||
|
||||
|
||||
gen(srcfiles)
|
||||
Executable
+244
@@ -0,0 +1,244 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# This file is part of OpenCV project.
|
||||
# It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
# of this distribution and at http://opencv.org/license.html
|
||||
# Copyright (C) 2020 by Archit Rungta
|
||||
|
||||
from __future__ import unicode_literals # Needed for python2
|
||||
|
||||
import hdr_parser, sys, re, os
|
||||
from string import Template
|
||||
from pprint import pprint
|
||||
from collections import namedtuple
|
||||
if sys.version_info[0] >= 3:
|
||||
from io import StringIO
|
||||
else:
|
||||
from cStringIO import StringIO
|
||||
import os, shutil
|
||||
|
||||
from parse_tree import *
|
||||
|
||||
|
||||
jl_cpp_argmap = {}
|
||||
jl_cpp_defmap = {}
|
||||
julia_types = ["Int32", "Float32", "Float64", "Bool", "String", "Array", "Any"]
|
||||
cv_types = ["UMat","Size" ]
|
||||
|
||||
submodule_template = Template('')
|
||||
root_template = Template('')
|
||||
with open("binding_templates_jl/template_cv2_submodule_cxx.jl", "r") as f:
|
||||
submodule_template = Template(f.read())
|
||||
with open("binding_templates_jl/template_cv2_root.jl", "r") as f:
|
||||
root_template = Template(f.read())
|
||||
with open("typemap.txt", 'r') as f:
|
||||
tmp = f.readlines()
|
||||
for ln in tmp:
|
||||
ln = ln.strip('\n').split(':')
|
||||
jl_cpp_argmap[ln[0]] = ln[1]
|
||||
with open("defval.txt", 'r') as f:
|
||||
tmp = f.readlines()
|
||||
for ln in tmp:
|
||||
ln = ln.strip('\n').split('|')
|
||||
if ln[0] not in jl_cpp_defmap:
|
||||
jl_cpp_defmap[ln[0]] = {}
|
||||
jl_cpp_defmap[ln[0]][ln[1]] = ln[2]
|
||||
|
||||
|
||||
def handle_def_arg(inp, tp = '', ns=''):
|
||||
tp = tp.strip()
|
||||
inp = inp.strip()
|
||||
|
||||
out = ''
|
||||
|
||||
if inp in jl_cpp_defmap[tp]:
|
||||
out = jl_cpp_defmap[tp][inp]
|
||||
elif inp != '':
|
||||
print(inp+" not found")
|
||||
# print(inp, tp, out)
|
||||
return out
|
||||
|
||||
def handle_jl_arg(inp):
|
||||
if not inp:
|
||||
return ''
|
||||
inp = inp.replace('std::', '')
|
||||
if inp in jl_cpp_argmap:
|
||||
return jl_cpp_argmap[inp]
|
||||
inp = inp.replace('cv::', '')
|
||||
return inp
|
||||
# return outs
|
||||
|
||||
class ClassInfo(ClassInfo):
|
||||
|
||||
def get_jl_code(self):
|
||||
|
||||
if self.ismap:
|
||||
return ''
|
||||
return self.overload_get()+self.overload_set()
|
||||
|
||||
def overload_get(self):
|
||||
stra = "function Base.getproperty(m::%s, s::Symbol)\n" %(self.mapped_name)
|
||||
if self.isalgorithm:
|
||||
stra = "function Base.getproperty(m::cv_Ptr{%s}, s::Symbol)\n" %(self.mapped_name)
|
||||
for prop in self.props:
|
||||
stra = stra + " if s==:" + prop.name+"\n"
|
||||
stra = stra + " return cpp_to_julia(%s(m))\n"%self.get_prop_func_cpp("get", prop.name)
|
||||
stra = stra + " end\n"
|
||||
stra = stra + " return Base.getfield(m, s)\nend\n"
|
||||
return stra
|
||||
|
||||
def overload_set(self):
|
||||
|
||||
stra = "function Base.setproperty!(m::%s, s::Symbol, v)\n" %(self.mapped_name)
|
||||
if self.isalgorithm:
|
||||
stra = "function Base.setproperty!(m::cv_Ptr{%s}, s::Symbol, v)\n" %(self.mapped_name)
|
||||
|
||||
for prop in self.props:
|
||||
if not prop.readonly:
|
||||
continue
|
||||
stra = stra + " if s==:" + prop.name+"\n"
|
||||
stra = stra + " %s(m, julia_to_cpp(v))\n"%(self.get_prop_func_cpp("set", prop.name))
|
||||
stra = stra + " end\n"
|
||||
stra = stra + " return Base.setfield!(m, s, v)\nend\n"
|
||||
return stra
|
||||
|
||||
class FuncVariant(FuncVariant):
|
||||
|
||||
def promote_type(self, tp):
|
||||
if tp=='int':
|
||||
return 'long long'
|
||||
elif tp =='float':
|
||||
return 'double'
|
||||
return tp
|
||||
|
||||
|
||||
def get_argument_full(self, classname='', isalgo = False):
|
||||
arglist = self.inlist + self.optlist
|
||||
|
||||
argnamelist = [arg.name+"::"+(handle_jl_arg(self.promote_type(arg.tp)) if handle_jl_arg(arg.tp) not in pass_by_val_types else handle_jl_arg(self.promote_type(arg.tp[:-1]))) for arg in arglist]
|
||||
argstr = ", ".join(argnamelist)
|
||||
return argstr
|
||||
|
||||
def get_argument_opt(self, ns=''):
|
||||
# [print(arg.default_value,":",handle_def_arg(arg.default_value, handle_jl_arg(arg.tp))) for arg in self.optlist]
|
||||
try:
|
||||
str2 = ", ".join(["%s::%s = %s(%s)" % (arg.name, handle_jl_arg(self.promote_type(arg.tp)), handle_jl_arg(self.promote_type(arg.tp)) if (arg.tp == 'int' or arg.tp=='float' or arg.tp=='double') else '', handle_def_arg(arg.default_value, handle_jl_arg(self.promote_type(arg.tp)), ns)) for arg in self.optlist])
|
||||
return str2
|
||||
except KeyError:
|
||||
return ''
|
||||
|
||||
def get_argument_def(self, classname, isalgo):
|
||||
arglist = self.inlist
|
||||
argnamelist = [arg.name+"::"+(handle_jl_arg(self.promote_type(arg.tp)) if handle_jl_arg(self.promote_type(arg.tp)) not in pass_by_val_types else handle_jl_arg(self.promote_type(arg.tp[:-1]))) for arg in arglist]
|
||||
argstr = ", ".join(argnamelist)
|
||||
return argstr
|
||||
|
||||
def get_return(self, classname=''):
|
||||
argstr = ''
|
||||
arglist = self.inlist + self.optlist
|
||||
return "return cpp_to_julia(%s(%s))" %(self.get_wrapper_name(), ",".join(["julia_to_cpp(%s)" % (x.name) for x in arglist]))
|
||||
|
||||
def get_algo_tp(self, classname, isalgo):
|
||||
if not isalgo or not classname:
|
||||
return ''
|
||||
return ' where {T <: %s}' % classname
|
||||
|
||||
def get_complete_code(self, classname='', isalgo = False, iscons = False, gen_default = True, ns = ''):
|
||||
if classname and not iscons:
|
||||
if isalgo:
|
||||
self.inlist = [ArgInfo("cobj", "cv_Ptr{T}")] + self.inlist
|
||||
else:
|
||||
self.inlist = [ArgInfo("cobj", classname)] + self.inlist
|
||||
map_name = self.mapped_name
|
||||
if ns!='cv':
|
||||
map_name = '%s_%s' %(ns.split('::')[-1], map_name)
|
||||
outstr = 'function %s(%s)%s\n\t%s\nend\n' % (map_name, self.get_argument_full(classname, isalgo), self.get_algo_tp(classname, isalgo),self.get_return())
|
||||
|
||||
|
||||
str2 = ", ".join([x.name for x in self.inlist + self.optlist])
|
||||
# outstr = outstr +
|
||||
if self.get_argument_opt() != '' and gen_default:
|
||||
outstr = outstr + ('%s(%s; %s)%s = %s(%s)\n' % (map_name, self.get_argument_def(classname, isalgo), self.get_argument_opt(ns), self.get_algo_tp(classname, isalgo), map_name, str2))
|
||||
|
||||
if iscons and len(self.inlist+self.optlist)==0 and ns=='cv':
|
||||
return ''
|
||||
|
||||
return outstr
|
||||
|
||||
|
||||
|
||||
def gen(srcfiles):
|
||||
namespaces, _ = gen_tree(srcfiles)
|
||||
|
||||
jl_code = StringIO()
|
||||
for name, ns in namespaces.items():
|
||||
cv_types.extend(ns.registered)
|
||||
jl_code = StringIO()
|
||||
nsname = name
|
||||
for e1,e2 in ns.enums.items():
|
||||
# jl_code.write('\n const {0} = Int32'.format(e2[0]))
|
||||
jl_code.write('\n const {0} = Int64 \n'.format(e2[0].replace("cv::", "").replace("::", "_")))
|
||||
|
||||
# Do not duplicate functions. This should prevent overwriting of Mat function by UMat functions
|
||||
function_signatures = []
|
||||
for cname, cl in ns.classes.items():
|
||||
cl.__class__ = ClassInfo
|
||||
jl_code.write(cl.get_jl_code())
|
||||
for mname, fs in cl.methods.items():
|
||||
for f in fs:
|
||||
f.__class__ = FuncVariant
|
||||
sign = (f.name, f.mapped_name, f.classname, [x.tp for x in f.inlist+f.optlist])
|
||||
if sign in function_signatures:
|
||||
print("Skipping entirely: ", f.name)
|
||||
continue
|
||||
sign2 = (f.name, f.mapped_name, f.classname, [x.tp for x in f.inlist])
|
||||
gend = True
|
||||
if sign2 in function_signatures:
|
||||
print("Skipping default declaration: ", f.name)
|
||||
gend = False
|
||||
jl_code.write('\n%s' % f.get_complete_code(classname = cl.mapped_name, isalgo = cl.isalgorithm, gen_default = gend, ns=nsname))
|
||||
function_signatures.append(sign)
|
||||
function_signatures.append(sign2)
|
||||
for f in cl.constructors:
|
||||
f.__class__ = FuncVariant
|
||||
jl_code.write('\n%s' % f.get_complete_code(classname = cl.mapped_name, isalgo = cl.isalgorithm, iscons = True, ns=nsname))
|
||||
for mname, fs in ns.funcs.items():
|
||||
for f in fs:
|
||||
f.__class__ = FuncVariant
|
||||
sign = (f.name, f.mapped_name, f.classname, [x.tp for x in f.inlist+f.optlist])
|
||||
if sign in function_signatures:
|
||||
print("Skipping entirely: ", f.name)
|
||||
continue
|
||||
gend = True
|
||||
sign2 = (f.name, f.mapped_name, f.classname, [x.tp for x in f.inlist])
|
||||
if sign2 in function_signatures:
|
||||
print("Skipping default declaration: ", f.name)
|
||||
gend = False
|
||||
|
||||
jl_code.write('\n%s' % f.get_complete_code(gen_default = gend, ns=nsname))
|
||||
function_signatures.append(sign)
|
||||
function_signatures.append(sign2)
|
||||
|
||||
|
||||
imports = ''
|
||||
for namex in namespaces:
|
||||
if namex.startswith(name) and len(namex.split('::')) == 1 + len(name.split('::')):
|
||||
imports = imports + '\ninclude("%s_cxx_wrap.jl")'%namex.replace('::', '_')
|
||||
code = ''
|
||||
if name == 'cv':
|
||||
code = root_template.substitute(modname = name, code = jl_code.getvalue(), submodule_imports = imports)
|
||||
else:
|
||||
code = submodule_template.substitute(code = jl_code.getvalue(), submodule_imports = imports)
|
||||
|
||||
with open ('autogen_jl/%s_cxx_wrap.jl' % ns.name.replace('::', '_'), 'w') as fd:
|
||||
fd.write(code)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
srcfiles = hdr_parser.opencv_hdr_list
|
||||
if len(sys.argv) > 1:
|
||||
srcfiles = [l.strip() for l in sys.argv[1].split(';')]
|
||||
|
||||
gen(srcfiles)
|
||||
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
# This file is part of OpenCV project.
|
||||
# It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
# of this distribution and at http://opencv.org/license.html
|
||||
# Copyright (C) 2020 by Archit Rungta
|
||||
|
||||
import sys
|
||||
import subprocess
|
||||
import os
|
||||
|
||||
mod_path = sys.argv[1]
|
||||
|
||||
|
||||
hdr_list = [
|
||||
mod_path+"/core/include/opencv2/core.hpp",
|
||||
mod_path+"/core/include/opencv2/core/base.hpp",
|
||||
mod_path+"/core/include/opencv2/core/bindings_utils.hpp",
|
||||
mod_path+"/core/include/opencv2/core/optim.hpp",
|
||||
mod_path+"/core/include/opencv2/core/persistence.hpp",
|
||||
mod_path+"/core/include/opencv2/core/types.hpp",
|
||||
mod_path+"/core/include/opencv2/core/utility.hpp"]
|
||||
|
||||
for module in sys.argv[2:]:
|
||||
if module=='opencv_imgproc':
|
||||
hdr_list.append(mod_path+"/imgproc/include/opencv2/imgproc.hpp")
|
||||
elif module =='opencv_dnn':
|
||||
hdr_list.append(mod_path+"/dnn/include/opencv2/dnn/dnn.hpp")
|
||||
elif module == 'opencv_imgcodecs':
|
||||
hdr_list.append(mod_path+"/imgcodecs/include/opencv2/imgcodecs.hpp")
|
||||
elif module =='opencv_videoio':
|
||||
hdr_list.append(mod_path+"/videoio/include/opencv2/videoio.hpp")
|
||||
elif module =='opencv_highgui':
|
||||
hdr_list.append(mod_path+"/highgui/include/opencv2/highgui.hpp")
|
||||
elif module =='opencv_calib3d':
|
||||
hdr_list.append(mod_path+"/calib3d/include/opencv2/calib3d.hpp")
|
||||
|
||||
if not os.path.exists('autogen_cpp'):
|
||||
os.makedirs('autogen_cpp')
|
||||
os.makedirs('autogen_jl')
|
||||
|
||||
subprocess.call([sys.executable, 'gen3_cpp.py', str(';'.join(hdr_list))])
|
||||
subprocess.call([sys.executable, 'gen3_julia_cxx.py', str(';'.join(hdr_list))])
|
||||
subprocess.call([sys.executable, 'gen3_julia.py', str(';'.join(hdr_list))])
|
||||
@@ -0,0 +1,49 @@
|
||||
#Adapted from IndirectArray
|
||||
|
||||
struct Mat{T <: dtypes} <: AbstractArray{T,3}
|
||||
mat
|
||||
data_raw
|
||||
data
|
||||
|
||||
@inline function Mat{T}(mat, data_raw::AbstractArray{T,3}) where {T <: dtypes}
|
||||
data = reinterpret(T, data_raw)
|
||||
new{T}(mat, data_raw, data)
|
||||
end
|
||||
|
||||
@inline function Mat(data_raw::AbstractArray{T, 3}) where {T <: dtypes}
|
||||
data = reinterpret(T, data_raw)
|
||||
mat = nothing
|
||||
new{T}(mat, data_raw, data)
|
||||
end
|
||||
end
|
||||
|
||||
function Base.deepcopy_internal(x::Mat{T}, y::IdDict) where {T}
|
||||
if haskey(y, x)
|
||||
return y[x]
|
||||
end
|
||||
ret = Base.copy(x)
|
||||
y[x] = ret
|
||||
return ret
|
||||
end
|
||||
|
||||
Base.size(A::Mat) = size(A.data)
|
||||
Base.axes(A::Mat) = axes(A.data)
|
||||
Base.IndexStyle(::Type{Mat{T}}) where {T} = IndexCartesian()
|
||||
|
||||
Base.strides(A::Mat{T}) where {T} = strides(A.data)
|
||||
Base.copy(A::Mat{T}) where {T} = Mat(copy(A.data_raw))
|
||||
Base.pointer(A::Mat) = Base.pointer(A.data)
|
||||
|
||||
Base.unsafe_convert(::Type{Ptr{T}}, A::Mat{S}) where {T, S} = Base.unsafe_convert(Ptr{T}, A.data)
|
||||
|
||||
@inline function Base.getindex(A::Mat{T}, I::Vararg{Int,3}) where {T}
|
||||
@boundscheck checkbounds(A.data, I...)
|
||||
@inbounds ret = A.data[I...]
|
||||
ret
|
||||
end
|
||||
|
||||
@inline function Base.setindex!(A::Mat, x, I::Vararg{Int,3})
|
||||
@boundscheck checkbounds(A.data, I...)
|
||||
A.data[I...] = x
|
||||
return A
|
||||
end
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
module OpenCV
|
||||
|
||||
import Base.size
|
||||
|
||||
include("cv_cxx.jl")
|
||||
|
||||
|
||||
include("cv_wrap.jl")
|
||||
|
||||
end
|
||||
@@ -0,0 +1,50 @@
|
||||
#Adapted from IndirectArray
|
||||
|
||||
struct Vec{T, N} <: AbstractArray{T,1}
|
||||
cpp_object
|
||||
data::AbstractArray{T, 1}
|
||||
cpp_allocated::Bool
|
||||
@inline function Vec{T, N}(obj) where {T, N}
|
||||
|
||||
new{T, N}(obj, Base.unsafe_wrap(Array{T, 1}, Ptr{T}(obj.cpp_object), N), true)
|
||||
end
|
||||
|
||||
@inline function Vec{T, N}(data_raw::AbstractArray{T, 1}) where {T, N}
|
||||
if size(data_raw, 1) != N
|
||||
throw("Array is improper Size for Vec declared")
|
||||
end
|
||||
new{T, N}(nothing, data_raw, false)
|
||||
end
|
||||
end
|
||||
|
||||
function Base.deepcopy_internal(x::Vec{T,N}, y::IdDict) where {T, N}
|
||||
if haskey(y, x)
|
||||
return y[x]
|
||||
end
|
||||
ret = Base.copy(x)
|
||||
y[x] = ret
|
||||
return ret
|
||||
end
|
||||
|
||||
Base.size(A::Vec) = Base.size(A.data)
|
||||
Base.axes(A::Vec) = Base.axes(A.data)
|
||||
Base.IndexStyle(::Type{Vec{T,N}}) where {T, N} = IndexLinear()
|
||||
|
||||
Base.strides(A::Vec{T,N}) where {T, N} = (1)
|
||||
function Base.copy(A::Vec{T,N}) where {T, N}
|
||||
return Vec{T, N}(copy(A.data))
|
||||
end
|
||||
Base.pointer(A::Vec) = Base.pointer(A.data)
|
||||
|
||||
Base.unsafe_convert(::Type{Ptr{T}}, A::Vec{S, N}) where {T, S, N} = Base.unsafe_convert(Ptr{T}, A.data)
|
||||
|
||||
@inline function Base.getindex(A::Vec{T,N}, I::Int) where {T, N}
|
||||
@boundscheck checkbounds(A.data, I)
|
||||
return A.data[I]
|
||||
end
|
||||
|
||||
@inline function Base.setindex!(A::Vec, x, I::Int)
|
||||
@boundscheck checkbounds(A.data, I)
|
||||
A.data[I] = x
|
||||
return A
|
||||
end
|
||||
@@ -0,0 +1,52 @@
|
||||
# using StaticArrays
|
||||
|
||||
include("typestructs.jl")
|
||||
include("Vec.jl")
|
||||
const dtypes = Union{UInt8, Int8, UInt16, Int16, Int32, Float32, Float64}
|
||||
size_t = UInt64
|
||||
|
||||
using CxxWrap
|
||||
@wrapmodule(joinpath(@__DIR__,"lib","libopencv_julia"), :cv_wrap)
|
||||
function __init__()
|
||||
@initcxx
|
||||
|
||||
if jlopencv_core_get_sizet()==4
|
||||
size_t = UInt32
|
||||
end
|
||||
end
|
||||
const Scalar = Union{Tuple{}, Tuple{Number}, Tuple{Number, Number}, Tuple{Number, Number, Number}, NTuple{4, Number}}
|
||||
|
||||
include("Mat.jl")
|
||||
|
||||
const InputArray = Union{AbstractArray{T, 3} where {T <: dtypes}, CxxMat}
|
||||
|
||||
include("mat_conversion.jl")
|
||||
include("types_conversion.jl")
|
||||
|
||||
function cpp_to_julia(var)
|
||||
return var
|
||||
end
|
||||
function julia_to_cpp(var)
|
||||
return var
|
||||
end
|
||||
|
||||
function cpp_to_julia(var::Tuple)
|
||||
ret_arr = Array{Any, 1}()
|
||||
for it in var
|
||||
push!(ret_arr, cpp_to_julia(it))
|
||||
end
|
||||
return tuple(ret_arr...)
|
||||
end
|
||||
|
||||
function cpp_to_julia(var::CxxBool)
|
||||
return Bool(var)
|
||||
end
|
||||
|
||||
function julia_to_cpp(var::Bool)
|
||||
return CxxBool(var)
|
||||
end
|
||||
|
||||
|
||||
include("cv_cxx_wrap.jl")
|
||||
|
||||
include("cv_manual_wrap.jl")
|
||||
@@ -0,0 +1,49 @@
|
||||
|
||||
function createButton(bar_name::String, on_change, userdata, type::Int32 = 0, initial_button_state::Bool = false)
|
||||
func = (x)->on_change(x, userdata)
|
||||
CxxWrap.gcprotect(userdata)
|
||||
CxxWrap.gcprotect(func)
|
||||
CxxWrap.gcprotect(on_change)
|
||||
return jl_cpp_cv2.createButton(bar_name,func, type, initial_button_state)
|
||||
end
|
||||
|
||||
function setMouseCallback(winname::String, onMouse, userdata)
|
||||
func = (event, x, y, flags)->onMouse(event, x, y, flags, userdata)
|
||||
CxxWrap.gcprotect(userdata)
|
||||
CxxWrap.gcprotect(func)
|
||||
CxxWrap.gcprotect(onMouse)
|
||||
return jl_cpp_cv2.setMouseCallback(winname,func)
|
||||
end
|
||||
|
||||
function createTrackbar(trackbarname::String, winname::String, value::Ref{Int32}, count::Int32, onChange, userdata)
|
||||
func = (x)->onChange(x, userdata)
|
||||
CxxWrap.gcprotect(userdata)
|
||||
CxxWrap.gcprotect(func)
|
||||
CxxWrap.gcprotect(onChange)
|
||||
return jl_cpp_cv2.createTrackbar(trackbarname, winname, value, count, func)
|
||||
end
|
||||
|
||||
function CascadeClassifier(filename::String)
|
||||
return cpp_to_julia(jlopencv_cv_cv_CascadeClassifier_cv_CascadeClassifier_CascadeClassifier(julia_to_cpp(filename)))
|
||||
end
|
||||
|
||||
|
||||
function detect(cobj::cv_Ptr{T}, image::InputArray, mask::InputArray) where {T <: Feature2D}
|
||||
return cpp_to_julia(jlopencv_cv_cv_Feature2D_cv_Feature2D_detect(julia_to_cpp(cobj),julia_to_cpp(image),julia_to_cpp(mask)))
|
||||
end
|
||||
detect(cobj::cv_Ptr{T}, image::InputArray; mask::InputArray = (CxxMat())) where {T <: Feature2D} = detect(cobj, image, mask)
|
||||
|
||||
|
||||
function detectMultiScale(cobj::CascadeClassifier, image::InputArray, scaleFactor::Float64, minNeighbors::Int32, flags::Int32, minSize::Size{Int32}, maxSize::Size{Int32})
|
||||
return cpp_to_julia(jlopencv_cv_cv_CascadeClassifier_cv_CascadeClassifier_detectMultiScale(julia_to_cpp(cobj),julia_to_cpp(image),julia_to_cpp(scaleFactor),julia_to_cpp(minNeighbors),julia_to_cpp(flags),julia_to_cpp(minSize),julia_to_cpp(maxSize)))
|
||||
end
|
||||
detectMultiScale(cobj::CascadeClassifier, image::InputArray; scaleFactor::Float64 = Float64(1.1), minNeighbors::Int32 = Int32(3), flags::Int32 = Int32(0), minSize::Size{Int32} = (Size{Int32}(0,0)), maxSize::Size{Int32} = (Size{Int32}(0,0))) = detectMultiScale(cobj, image, scaleFactor, minNeighbors, flags, minSize, maxSize)
|
||||
|
||||
function empty(cobj::CascadeClassifier)
|
||||
return cpp_to_julia(jlopencv_cv_cv_CascadeClassifier_cv_CascadeClassifier_empty(julia_to_cpp(cobj)))
|
||||
end
|
||||
|
||||
function SimpleBlobDetector_create(parameters::SimpleBlobDetector_Params)
|
||||
return cpp_to_julia(jlopencv_cv_cv_SimpleBlobDetector_create(julia_to_cpp(parameters)))
|
||||
end
|
||||
SimpleBlobDetector_create(; parameters::SimpleBlobDetector_Params = (SimpleBlobDetector_Params())) = SimpleBlobDetector_create(parameters)
|
||||
@@ -0,0 +1,106 @@
|
||||
const CV_CN_MAX = 512
|
||||
const CV_CN_SHIFT = 3
|
||||
const CV_DEPTH_MAX = (1 << CV_CN_SHIFT)
|
||||
|
||||
const CV_8U = 0
|
||||
const CV_8S = 1
|
||||
const CV_16U = 2
|
||||
const CV_16S = 3
|
||||
const CV_32S = 4
|
||||
const CV_32F = 5
|
||||
const CV_64F = 6
|
||||
|
||||
const CV_MAT_DEPTH_MASK = (CV_DEPTH_MAX - 1)
|
||||
CV_MAT_DEPTH(flags) = ((flags) & CV_MAT_DEPTH_MASK)
|
||||
|
||||
CV_MAKETYPE(depth,cn) = (CV_MAT_DEPTH(depth) + (((cn)-1) << CV_CN_SHIFT))
|
||||
CV_MAKE_TYPE = CV_MAKETYPE
|
||||
|
||||
function cpp_to_julia(mat::CxxMat)
|
||||
rets = jlopencv_core_Mat_mutable_data(mat)
|
||||
if rets[2] == CV_MAKE_TYPE(CV_8U, rets[3])
|
||||
dtype = UInt8
|
||||
elseif rets[2]==CV_MAKE_TYPE(CV_8S, rets[3])
|
||||
dtype = Int8
|
||||
elseif rets[2]==CV_MAKE_TYPE(CV_16U, rets[3])
|
||||
dtype = UInt16
|
||||
elseif rets[2]==CV_MAKE_TYPE(CV_16S, rets[3])
|
||||
dtype = Int16
|
||||
elseif rets[2]==CV_MAKE_TYPE(CV_32S, rets[3])
|
||||
dtype = Int32
|
||||
elseif rets[2]==CV_MAKE_TYPE(CV_32F, rets[3])
|
||||
dtype = Float32
|
||||
elseif rets[2]==CV_MAKE_TYPE(CV_64F, rets[3])
|
||||
dtype = Float64
|
||||
else
|
||||
error("Bad type returned from OpenCV")
|
||||
end
|
||||
steps = [rets[6]/sizeof(dtype), rets[7]/sizeof(dtype)]
|
||||
# println(steps[1]/rets[3], steps[2]/rets[3]/rets[4])
|
||||
#TODO: Implement views when steps do not result in continous memory
|
||||
arr = Base.unsafe_wrap(Array{dtype, 3}, Ptr{dtype}(rets[1].cpp_object), (rets[3], rets[4], rets[5]))
|
||||
|
||||
#Preserve Mat so that array allocated by C++ isn't deallocated
|
||||
return Mat{dtype}(mat, arr)
|
||||
end
|
||||
|
||||
function julia_to_cpp(img::InputArray)
|
||||
if typeof(img) <: CxxMat
|
||||
return img
|
||||
end
|
||||
steps = 0
|
||||
try
|
||||
steps = strides(img)
|
||||
catch
|
||||
# Copy array since array is not strided
|
||||
img = img[:, :, :]
|
||||
steps = strides(img)
|
||||
end
|
||||
|
||||
if steps[1] <= steps[2] <= steps[3] && steps[1]==1
|
||||
steps_a = Array{size_t, 1}()
|
||||
ndims_a = Array{Int32, 1}()
|
||||
sz = sizeof(eltype(img))
|
||||
push!(steps_a, UInt64(steps[3]*sz))
|
||||
push!(steps_a, UInt64(steps[2]*sz))
|
||||
push!(steps_a, UInt64(steps[1]*sz))
|
||||
|
||||
push!(ndims_a, Int32(size(img)[3]))
|
||||
push!(ndims_a, Int32(size(img)[2]))
|
||||
if eltype(img) == UInt8
|
||||
return CxxMat(2, pointer(ndims_a), CV_MAKE_TYPE(CV_8U, size(img)[1]), Ptr{Nothing}(pointer(img)), pointer(steps_a))
|
||||
elseif eltype(img) == UInt16
|
||||
return CxxMat(2, pointer(ndims_a), CV_MAKE_TYPE(CV_16U, size(img)[1]), Ptr{Nothing}(pointer(img)), pointer(steps_a))
|
||||
elseif eltype(img) == Int8
|
||||
return CxxMat(2, pointer(ndims_a), CV_MAKE_TYPE(CV_8S, size(img)[1]), Ptr{Nothing}(pointer(img)), pointer(steps_a))
|
||||
elseif eltype(img) == Int16
|
||||
return CxxMat(2, pointer(ndims_a), CV_MAKE_TYPE(CV_16S, size(img)[1]), Ptr{Nothing}(pointer(img)), pointer(steps_a))
|
||||
elseif eltype(img) == Int32
|
||||
return CxxMat(2, pointer(ndims_a), CV_MAKE_TYPE(CV_32S, size(img)[1]), Ptr{Nothing}(pointer(img)), pointer(steps_a))
|
||||
elseif eltype(img) == Float32
|
||||
return CxxMat(2, pointer(ndims_a), CV_MAKE_TYPE(CV_32F, size(img)[1]), Ptr{Nothing}(pointer(img)), pointer(steps_a))
|
||||
elseif eltype(img) == Float64
|
||||
return CxxMat(2, pointer(ndims_a), CV_MAKE_TYPE(CV_64F, size(img)[1]), Ptr{Nothing}(pointer(img)), pointer(steps_a))
|
||||
end
|
||||
else
|
||||
# Copy array, invalid config
|
||||
return julia_to_cpp(img[:, :, :])
|
||||
end
|
||||
end
|
||||
|
||||
function julia_to_cpp(var::Array{T, 1}) where {T <: InputArray}
|
||||
ret = CxxWrap.StdVector{CxxMat}()
|
||||
for x in var
|
||||
push!(ret, julia_to_cpp(x))
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
|
||||
function cpp_to_julia(var::CxxWrap.StdVector{T}) where {T <: CxxMat}
|
||||
ret = Array{Mat, 1}()
|
||||
for x in var
|
||||
push!(ret, cpp_to_julia(x))
|
||||
end
|
||||
return ret
|
||||
end
|
||||
@@ -0,0 +1,79 @@
|
||||
function cpp_to_julia(var::CxxScalar{T}) where {T}
|
||||
var = Vec{T, 4}(var)
|
||||
return (var[1], var[2], var[3], var[4])
|
||||
end
|
||||
|
||||
function cpp_to_julia(var::CxxVec{T, N}) where {T, N}
|
||||
return Vec{T, N}(var)
|
||||
end
|
||||
|
||||
function julia_to_cpp(sc::Scalar)
|
||||
if size(sc,1)==0
|
||||
return CxxScalar{Float64}(0,0,0,0)
|
||||
elseif size(sc, 1) == 1
|
||||
return CxxScalar{Float64}(Float64(sc[1]), 0, 0, 0)
|
||||
elseif size(sc,1) == 2
|
||||
return CxxScalar{Float64}(Float64(sc[1]), Float64(sc[2]), 0, 0)
|
||||
elseif size(sc,1) == 3
|
||||
return CxxScalar{Float64}(Float64(sc[1]), Float64(sc[2]), Float64(sc[3]), 0)
|
||||
end
|
||||
return CxxScalar{Float64}(Float64(sc[1]), Float64(sc[2]), Float64(sc[3]), Float64(sc[4]))
|
||||
end
|
||||
|
||||
function julia_to_cpp(vec::Vec{T, N}) where {T, N}
|
||||
return CxxVec{T, N}(Base.pointer(vec))
|
||||
end
|
||||
|
||||
function julia_to_cpp(var::Array{T, 1}) where {T <: Scalar}
|
||||
ret = CxxWrap.StdVector{CxxScalar}()
|
||||
for x in var
|
||||
push!(ret, julia_to_cpp(x))
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
function julia_to_cpp(var::Array{Vec{T, N}, 1}) where {T, N}
|
||||
ret = CxxWrap.StdVector{CxxVec{T, N}}()
|
||||
for x in var
|
||||
push!(ret, julia_to_cpp(x))
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
function julia_to_cpp(var::Array{T, 1}) where {T}
|
||||
if size(var, 1) == 0
|
||||
return CxxWrap.StdVector{T}()
|
||||
end
|
||||
ret = CxxWrap.StdVector{typeof(julia_to_cpp(var[1]))}()
|
||||
for x in var
|
||||
push!(ret, julia_to_cpp(x))
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
function cpp_to_julia(var::CxxWrap.StdVector{T}) where {T <: CxxScalar}
|
||||
ret = Array{Scalar, 1}()
|
||||
for x in var
|
||||
push!(ret, cpp_to_julia(x))
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
function cpp_to_julia(var::CxxWrap.StdVector{CxxVec{T, N}}) where {T, N}
|
||||
ret = Array{Vec{T, N}, 1}()
|
||||
for x in var
|
||||
push!(ret, cpp_to_julia(x))
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
function cpp_to_julia(var::CxxWrap.StdVector{T}) where {T}
|
||||
if size(var, 1) == 0
|
||||
return Array{T, 1}()
|
||||
end
|
||||
ret = Array{typeof(cpp_to_julia(var[1])), 1}()
|
||||
for x in var
|
||||
push!(ret, cpp_to_julia(x))
|
||||
end
|
||||
return ret
|
||||
end
|
||||
@@ -0,0 +1,47 @@
|
||||
|
||||
struct Point{T}
|
||||
x::T
|
||||
y::T
|
||||
end
|
||||
|
||||
struct Point3{T}
|
||||
x::T
|
||||
y::T
|
||||
z::T
|
||||
end
|
||||
|
||||
|
||||
struct Size{T}
|
||||
width::T
|
||||
height::T
|
||||
end
|
||||
|
||||
|
||||
struct Rect{T}
|
||||
x::T
|
||||
y::T
|
||||
width::T
|
||||
height::T
|
||||
end
|
||||
|
||||
struct RotatedRect
|
||||
center::Point{Float32}
|
||||
size::Size{Float32}
|
||||
angle::Float32
|
||||
end
|
||||
|
||||
struct Range
|
||||
start::Int32
|
||||
end_::Int32
|
||||
end
|
||||
|
||||
struct TermCriteria
|
||||
type::Int32
|
||||
maxCount::Int32
|
||||
epsilon::Float64
|
||||
end
|
||||
|
||||
struct cvComplex{T}
|
||||
re::T
|
||||
im::T
|
||||
end
|
||||
@@ -0,0 +1,531 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# This file is part of OpenCV project.
|
||||
# It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
# of this distribution and at http://opencv.org/license.html
|
||||
# Copyright (C) 2020 by Archit Rungta
|
||||
|
||||
|
||||
import hdr_parser, sys, re, os
|
||||
from string import Template
|
||||
from pprint import pprint
|
||||
from collections import namedtuple
|
||||
import json
|
||||
import os, shutil
|
||||
from io import StringIO
|
||||
|
||||
|
||||
forbidden_arg_types = ["void*"]
|
||||
|
||||
ignored_arg_types = ["RNG*"]
|
||||
|
||||
pass_by_val_types = ["Point*", "Point2f*", "Rect*", "String*", "double*", "float*", "int*"]
|
||||
|
||||
|
||||
def get_char(c):
|
||||
if c.isalpha():
|
||||
return c
|
||||
if ord(c)%52 < 26:
|
||||
return chr(ord('a')+ord(c)%26)
|
||||
return chr(ord('A')+ord(c)%26)
|
||||
|
||||
|
||||
def get_var(inp):
|
||||
out = ''
|
||||
for c in inp:
|
||||
out = out+get_char(c)
|
||||
return out
|
||||
|
||||
def normalize_name(name):
|
||||
return name.replace('.', '::')
|
||||
|
||||
def normalize_class_name(name):
|
||||
_, classes, name = split_decl_name(normalize_name(name))
|
||||
return "_".join(classes+[name])
|
||||
|
||||
def normalize_full_name(name):
|
||||
ns, classes, name = split_decl_name(normalize_name(name))
|
||||
return "::".join(ns)+'::'+'_'.join(classes+[name])
|
||||
|
||||
|
||||
|
||||
def split_decl_name(name):
|
||||
chunks = name.split('::')
|
||||
namespace = chunks[:-1]
|
||||
classes = []
|
||||
while namespace and '::'.join(namespace) not in namespaces:
|
||||
classes.insert(0, namespace.pop())
|
||||
|
||||
ns = '::'.join(namespace)
|
||||
if ns not in namespaces and ns:
|
||||
assert(0)
|
||||
|
||||
return namespace, classes, chunks[-1]
|
||||
|
||||
|
||||
def handle_cpp_arg(inp):
|
||||
def handle_vector(match):
|
||||
return handle_cpp_arg("%svector<%s>" % (match.group(1), match.group(2)))
|
||||
def handle_ptr(match):
|
||||
return handle_cpp_arg("%sPtr<%s>" % (match.group(1), match.group(2)))
|
||||
inp = re.sub("(.*)vector_(.*)", handle_vector, inp)
|
||||
inp = re.sub("(.*)Ptr_(.*)", handle_ptr, inp)
|
||||
|
||||
|
||||
return inp.replace("String", "string")
|
||||
|
||||
def get_template_arg(inp):
|
||||
inp = inp.replace(' ','').replace('*', '').replace('cv::', '').replace('std::', '')
|
||||
def handle_vector(match):
|
||||
return get_template_arg("%s" % (match.group(1)))
|
||||
def handle_ptr(match):
|
||||
return get_template_arg("%s" % (match.group(1)))
|
||||
inp = re.sub("vector<(.*)>", handle_vector, inp)
|
||||
inp = re.sub("Ptr<(.*)>", handle_ptr, inp)
|
||||
ns, cl, n = split_decl_name(inp)
|
||||
inp = "::".join(cl+[n])
|
||||
# print(inp)
|
||||
return inp.replace("String", "string")
|
||||
|
||||
def registered_tp_search(tp):
|
||||
found = False
|
||||
if not tp:
|
||||
return True
|
||||
for tpx in registered_types:
|
||||
if re.findall(tpx, tp):
|
||||
found = True
|
||||
break
|
||||
return found
|
||||
|
||||
namespaces = {}
|
||||
type_paths = {}
|
||||
enums = {}
|
||||
classes = {}
|
||||
functions = {}
|
||||
registered_types = ["int", "Size.*", "Rect.*", "Scalar", "RotatedRect", "Point.*", "explicit", "string", "bool", "uchar",
|
||||
"Vec.*", "float", "double", "char", "Mat", "size_t", "RNG", "DescriptorExtractor", "FeatureDetector", "TermCriteria"]
|
||||
|
||||
class ClassProp(object):
|
||||
"""
|
||||
Helper class to store field information(type, name and flags) of classes and structs
|
||||
"""
|
||||
def __init__(self, decl):
|
||||
self.tp = decl[0]
|
||||
self.name = decl[1]
|
||||
self.readonly = True
|
||||
if "/RW" in decl[3]:
|
||||
self.readonly = False
|
||||
|
||||
class ClassInfo(object):
|
||||
def __init__(self, name, decl=None):
|
||||
self.name = name
|
||||
self.mapped_name = normalize_class_name(name)
|
||||
self.ismap = False #CV_EXPORTS_W_MAP
|
||||
self.isalgorithm = False #if class inherits from cv::Algorithm
|
||||
self.methods = {} #Dictionary of methods
|
||||
self.props = [] #Collection of ClassProp associated with this class
|
||||
self.base = None #name of base class if current class inherits another class
|
||||
self.constructors = [] #Array of constructors for this class
|
||||
self.add_decl(decl)
|
||||
classes[name] = self
|
||||
|
||||
def add_decl(self, decl):
|
||||
if decl:
|
||||
# print(decl)
|
||||
bases = decl[1].split(',')
|
||||
if len(bases[0].split()) > 1:
|
||||
bases[0] = bases[0].split()[1]
|
||||
|
||||
bases = [x.replace(' ','') for x in bases]
|
||||
# print(bases)
|
||||
if len(bases) > 1:
|
||||
# Clear the set a bit
|
||||
bases = list(set(bases))
|
||||
bases.remove('cv::class')
|
||||
bases_clear = []
|
||||
for bb in bases:
|
||||
if self.name not in bb:
|
||||
bases_clear.append(bb)
|
||||
bases = bases_clear
|
||||
if len(bases) > 1:
|
||||
print("Note: Class %s has more than 1 base class (not supported by CxxWrap)" % (self.name,))
|
||||
print(" Bases: ", " ".join(bases))
|
||||
print(" Only the first base class will be used")
|
||||
if len(bases) >= 1:
|
||||
self.base = bases[0].replace('.', '::')
|
||||
if "cv::Algorithm" in bases:
|
||||
self.isalgorithm = True
|
||||
|
||||
for m in decl[2]:
|
||||
if m.startswith("="):
|
||||
self.mapped_name = m[1:]
|
||||
# if m == "/Map":
|
||||
# self.ismap = True
|
||||
self.props = [ClassProp(p) for p in decl[3]]
|
||||
# return code for functions and setters and getters if simple class or functions and map type
|
||||
|
||||
def get_prop_func_cpp(self, mode, propname):
|
||||
return "jlopencv_" + self.mapped_name + "_"+mode+"_"+propname
|
||||
|
||||
argumentst = []
|
||||
default_values = []
|
||||
class ArgInfo(object):
|
||||
"""
|
||||
Helper class to parse and contain information about function arguments
|
||||
"""
|
||||
|
||||
def sec(self, arg_tuple):
|
||||
self.isbig = arg_tuple[0] in ["Mat", "vector_Mat", "cuda::GpuMat", "GpuMat", "vector_GpuMat", "UMat", "vector_UMat"] # or self.tp.startswith("vector")
|
||||
|
||||
self.tp = handle_cpp_arg(arg_tuple[0]) #C++ Type of argument
|
||||
argumentst.append(self.tp)
|
||||
self.name = arg_tuple[1] #Name of argument
|
||||
# TODO: Handle default values nicely
|
||||
self.default_value = arg_tuple[2] #Default value
|
||||
self.inputarg = True #Input argument
|
||||
self.outputarg = False #output argument
|
||||
self.ref = False
|
||||
|
||||
for m in arg_tuple[3]:
|
||||
if m == "/O":
|
||||
self.inputarg = False
|
||||
self.outputarg = True
|
||||
elif m == "/IO":
|
||||
self.inputarg = True
|
||||
self.outputarg = True
|
||||
elif m == '/Ref':
|
||||
self.ref = True
|
||||
|
||||
if self.tp in pass_by_val_types:
|
||||
self.outputarg = True
|
||||
|
||||
|
||||
|
||||
def __init__(self, name, tp = None):
|
||||
if not tp:
|
||||
self.sec(name)
|
||||
else:
|
||||
self.name = name
|
||||
self.tp = tp
|
||||
|
||||
|
||||
class FuncVariant(object):
|
||||
"""
|
||||
Helper class to parse and contain information about different overloaded versions of same function
|
||||
"""
|
||||
def __init__(self, classname, name, mapped_name, decl, namespace, istatic=False):
|
||||
self.classname = classname
|
||||
self.name = name
|
||||
self.mapped_name = mapped_name
|
||||
|
||||
self.isconstructor = name.split('::')[-1]==classname.split('::')[-1]
|
||||
self.isstatic = istatic
|
||||
self.namespace = namespace
|
||||
|
||||
self.rettype = decl[4]
|
||||
if self.rettype == "void" or not self.rettype:
|
||||
self.rettype = ""
|
||||
else:
|
||||
self.rettype = handle_cpp_arg(self.rettype)
|
||||
|
||||
self.args = []
|
||||
|
||||
for ainfo in decl[3]:
|
||||
a = ArgInfo(ainfo)
|
||||
if a.default_value and ('(' in a.default_value or ':' in a.default_value):
|
||||
default_values.append(a.default_value)
|
||||
assert not a.tp in forbidden_arg_types, 'Forbidden type "{}" for argument "{}" in "{}" ("{}")'.format(a.tp, a.name, self.name, self.classname)
|
||||
if a.tp in ignored_arg_types:
|
||||
continue
|
||||
|
||||
self.args.append(a)
|
||||
self.init_proto()
|
||||
|
||||
if name not in functions:
|
||||
functions[name]= []
|
||||
functions[name].append(self)
|
||||
|
||||
if not registered_tp_search(get_template_arg(self.rettype)):
|
||||
namespaces[namespace].register_types.append(get_template_arg(self.rettype))
|
||||
for arg in self.args:
|
||||
if not registered_tp_search(get_template_arg(arg.tp)):
|
||||
namespaces[namespace].register_types.append(get_template_arg(arg.tp))
|
||||
|
||||
|
||||
def get_wrapper_name(self):
|
||||
"""
|
||||
Return wrapping function name
|
||||
"""
|
||||
name = self.name.replace('::', '_')
|
||||
if self.classname:
|
||||
classname = self.classname.replace('::', '_') + "_"
|
||||
else:
|
||||
classname = ""
|
||||
return "jlopencv_" + self.namespace.replace('::','_') + '_' + classname + name
|
||||
|
||||
|
||||
def init_proto(self):
|
||||
# string representation of argument list, with '[', ']' symbols denoting optional arguments, e.g.
|
||||
# "src1, src2[, dst[, mask]]" for cv.add
|
||||
prototype = ""
|
||||
|
||||
inlist = []
|
||||
optlist = []
|
||||
outlist = []
|
||||
deflist = []
|
||||
biglist = []
|
||||
|
||||
# This logic can almost definitely be simplified
|
||||
|
||||
for a in self.args:
|
||||
if a.isbig and not (a.inputarg and not a.default_value):
|
||||
optlist.append(a)
|
||||
if a.outputarg:
|
||||
outlist.append(a)
|
||||
if a.inputarg and not a.default_value:
|
||||
inlist.append(a)
|
||||
elif a.inputarg and a.default_value and not a.isbig:
|
||||
optlist.append(a)
|
||||
elif not (a.isbig and not (a.inputarg and not a.default_value)):
|
||||
deflist.append(a)
|
||||
|
||||
if self.rettype:
|
||||
outlist = [ArgInfo("retval", self.rettype)] + outlist
|
||||
|
||||
if self.isconstructor:
|
||||
assert outlist == [] or outlist[0].tp == "explicit"
|
||||
outlist = [ArgInfo("retval", self.classname)]
|
||||
|
||||
|
||||
self.outlist = outlist
|
||||
self.optlist = optlist
|
||||
self.deflist = deflist
|
||||
|
||||
self.inlist = inlist
|
||||
|
||||
self.prototype = prototype
|
||||
|
||||
class NameSpaceInfo(object):
|
||||
def __init__(self, name):
|
||||
self.funcs = {}
|
||||
self.classes = {} #Dictionary of classname : ClassInfo objects
|
||||
self.enums = {}
|
||||
self.consts = {}
|
||||
self.register_types = []
|
||||
self.name = name
|
||||
|
||||
def add_func(decl):
|
||||
"""
|
||||
Creates functions based on declaration and add to appropriate classes and/or namespaces
|
||||
"""
|
||||
decl[0] = decl[0].replace('.', '::')
|
||||
namespace, classes, barename = split_decl_name(decl[0])
|
||||
name = "::".join(namespace+classes+[barename])
|
||||
full_classname = "::".join(namespace + classes)
|
||||
classname = "::".join(classes)
|
||||
namespace = '::'.join(namespace)
|
||||
is_static = False
|
||||
isphantom = False
|
||||
mapped_name = ''
|
||||
|
||||
for m in decl[2]:
|
||||
if m == "/S":
|
||||
is_static = True
|
||||
elif m == "/phantom":
|
||||
print("phantom not supported yet ")
|
||||
return
|
||||
elif m.startswith("="):
|
||||
mapped_name = m[1:]
|
||||
elif m.startswith("/mappable="):
|
||||
print("Mappable not supported yet")
|
||||
return
|
||||
# if m == "/V":
|
||||
# print("skipping ", name)
|
||||
# return
|
||||
|
||||
if classname and full_classname not in namespaces[namespace].classes:
|
||||
# print("HH1")
|
||||
# print(namespace, classname)
|
||||
namespaces[namespace].classes[full_classname] = ClassInfo(full_classname)
|
||||
assert(0)
|
||||
|
||||
|
||||
if is_static:
|
||||
# Add it as global function
|
||||
func_map = namespaces[namespace].funcs
|
||||
if name not in func_map:
|
||||
func_map[name] = []
|
||||
if not mapped_name:
|
||||
mapped_name = "_".join(classes + [barename])
|
||||
func_map[name].append(FuncVariant("", name, mapped_name, decl, namespace, True))
|
||||
else:
|
||||
if classname:
|
||||
func = FuncVariant(full_classname, name, barename, decl, namespace, False)
|
||||
if func.isconstructor:
|
||||
namespaces[namespace].classes[full_classname].constructors.append(func)
|
||||
else:
|
||||
func_map = namespaces[namespace].classes[full_classname].methods
|
||||
if name not in func_map:
|
||||
func_map[name] = []
|
||||
func_map[name].append(func)
|
||||
else:
|
||||
func_map = namespaces[namespace].funcs
|
||||
if name not in func_map:
|
||||
func_map[name] = []
|
||||
if not mapped_name:
|
||||
mapped_name = barename
|
||||
func_map[name].append(FuncVariant("", name, mapped_name, decl, namespace, False))
|
||||
|
||||
|
||||
def add_class(stype, name, decl):
|
||||
"""
|
||||
Creates class based on name and declaration. Add it to list of classes and to JSON file
|
||||
"""
|
||||
# print("n", name)
|
||||
name = name.replace('.', '::')
|
||||
classinfo = ClassInfo(name, decl)
|
||||
namespace, classes, barename = split_decl_name(name)
|
||||
namespace = '::'.join(namespace)
|
||||
|
||||
if classinfo.name in classes:
|
||||
namespaces[namespace].classes[name].add_decl(decl)
|
||||
else:
|
||||
namespaces[namespace].classes[name] = classinfo
|
||||
|
||||
|
||||
|
||||
def add_const(name, decl, tp = ''):
|
||||
name = name.replace('.','::')
|
||||
namespace, classes, barename = split_decl_name(name)
|
||||
namespace = '::'.join(namespace)
|
||||
mapped_name = '_'.join(classes+[barename])
|
||||
ns = namespaces[namespace]
|
||||
if mapped_name in ns.consts:
|
||||
print("Generator error: constant %s (name=%s) already exists" \
|
||||
% (name, name))
|
||||
sys.exit(-1)
|
||||
ns.consts[name] = mapped_name
|
||||
|
||||
def add_enum(name, decl):
|
||||
name = name.replace('.', '::')
|
||||
mapped_name = normalize_class_name(name)
|
||||
# print(name)
|
||||
if mapped_name.endswith("<unnamed>"):
|
||||
mapped_name = None
|
||||
else:
|
||||
enums[name.replace(".", "::")] = mapped_name
|
||||
const_decls = decl[3]
|
||||
|
||||
if mapped_name:
|
||||
namespace, classes, name2 = split_decl_name(name)
|
||||
namespace = '::'.join(namespace)
|
||||
mapped_name = '_'.join(classes+[name2])
|
||||
# print(mapped_name)
|
||||
namespaces[namespace].enums[name] = (name.replace(".", "::"),mapped_name)
|
||||
|
||||
for decl in const_decls:
|
||||
name = decl[0]
|
||||
add_const(name.replace("const ", "", ).strip(), decl, "int")
|
||||
|
||||
|
||||
|
||||
def gen_tree(srcfiles):
|
||||
parser = hdr_parser.CppHeaderParser(generate_umat_decls=False, generate_gpumat_decls=False)
|
||||
|
||||
allowed_func_list = []
|
||||
|
||||
with open("funclist.csv", "r") as f:
|
||||
allowed_func_list = f.readlines()
|
||||
allowed_func_list = [x[:-1] for x in allowed_func_list]
|
||||
|
||||
|
||||
count = 0
|
||||
# step 1: scan the headers and build more descriptive maps of classes, consts, functions
|
||||
for hdr in srcfiles:
|
||||
decls = parser.parse(hdr)
|
||||
for ns in parser.namespaces:
|
||||
ns = ns.replace('.', '::')
|
||||
if ns not in namespaces:
|
||||
namespaces[ns] = NameSpaceInfo(ns)
|
||||
count += len(decls)
|
||||
if len(decls) == 0:
|
||||
continue
|
||||
if hdr.find('opencv2/') >= 0: #Avoid including the shadow files
|
||||
# code_include.write( '#include "{0}"\n'.format(hdr[hdr.rindex('opencv2/'):]) )
|
||||
pass
|
||||
for decl in decls:
|
||||
name = decl[0]
|
||||
if name.startswith("struct") or name.startswith("class"):
|
||||
# class/struct
|
||||
p = name.find(" ")
|
||||
stype = name[:p]
|
||||
name = name[p+1:].strip()
|
||||
add_class(stype, name, decl)
|
||||
elif name.startswith("const"):
|
||||
# constant
|
||||
assert(0)
|
||||
add_const(name.replace("const ", "").strip(), decl)
|
||||
elif name.startswith("enum"):
|
||||
# enum
|
||||
add_enum(name.rsplit(" ", 1)[1], decl)
|
||||
else:
|
||||
# function
|
||||
if decl[0] in allowed_func_list:
|
||||
add_func(decl)
|
||||
# step 1.5 check if all base classes exist
|
||||
# print(classes)
|
||||
for name, classinfo in classes.items():
|
||||
if classinfo.base:
|
||||
base = classinfo.base
|
||||
# print(base)
|
||||
if base not in classes:
|
||||
print("Generator error: unable to resolve base %s for %s"
|
||||
% (classinfo.base, classinfo.name))
|
||||
sys.exit(-1)
|
||||
base_instance = classes[base]
|
||||
classinfo.base = base
|
||||
classinfo.isalgorithm |= base_instance.isalgorithm # wrong processing of 'isalgorithm' flag:
|
||||
# doesn't work for trees(graphs) with depth > 2
|
||||
classes[name] = classinfo
|
||||
|
||||
# tree-based propagation of 'isalgorithm'
|
||||
processed = dict()
|
||||
def process_isalgorithm(classinfo):
|
||||
if classinfo.isalgorithm or classinfo in processed:
|
||||
return classinfo.isalgorithm
|
||||
res = False
|
||||
if classinfo.base:
|
||||
res = process_isalgorithm(classes[classinfo.base])
|
||||
#assert not (res == True or classinfo.isalgorithm is False), "Internal error: " + classinfo.name + " => " + classinfo.base
|
||||
classinfo.isalgorithm |= res
|
||||
res = classinfo.isalgorithm
|
||||
processed[classinfo] = True
|
||||
return res
|
||||
for name, classinfo in classes.items():
|
||||
process_isalgorithm(classinfo)
|
||||
|
||||
for name, ns in namespaces.items():
|
||||
if name.split('.')[-1] == '':
|
||||
continue
|
||||
ns.registered = []
|
||||
for name, cl in ns.classes.items():
|
||||
registered_types.append(get_template_arg(name))
|
||||
ns.registered.append(cl.mapped_name)
|
||||
nss, clss, bs = split_decl_name(name)
|
||||
type_paths[bs] = [name.replace("::", ".")]
|
||||
type_paths["::".join(clss+[bs])] = [name.replace("::", ".")]
|
||||
|
||||
|
||||
for e1,e2 in ns.enums.items():
|
||||
registered_types.append(get_template_arg(e2[0]))
|
||||
registered_types.append(get_template_arg(e2[0]).replace('::', '_')) #whyyy typedef
|
||||
ns.registered.append(e2[1])
|
||||
|
||||
ns.register_types = list(set(ns.register_types))
|
||||
ns.register_types = [tp for tp in ns.register_types if not registered_tp_search(tp) and not tp in ns.registered]
|
||||
for tp in ns.register_types:
|
||||
registered_types.append(get_template_arg(tp))
|
||||
ns.registered.append(get_template_arg(tp))
|
||||
default_valuesr = list(set(default_values))
|
||||
# registered_types = registered_types + ns.register_types
|
||||
return namespaces, default_valuesr
|
||||
@@ -0,0 +1,53 @@
|
||||
double*:NONCONVERT1
|
||||
vector<vector<Point2f>>:Array{Array{Point{Float32}, 1}, 1}
|
||||
TermCriteria:TermCriteria
|
||||
char:Char
|
||||
RotatedRect:RotatedRect
|
||||
Point2f:Point{Float32}
|
||||
Rect:Rect{Int32}
|
||||
vector<KeyPoint>:Array{KeyPoint, 1}
|
||||
double:Float64
|
||||
Point*:NONCONVERT2
|
||||
vector<Point>:Array{Point{Int32}, 1}
|
||||
vector<uchar>:Array{UInt8, 1}
|
||||
String:String
|
||||
string:String
|
||||
vector<Vec4f>:Array{Vec{Float32, 4}, 1}
|
||||
bool:Bool
|
||||
vector<Rect2d>:Array{Rect{Float64}, 1}
|
||||
LayerId:LayerId
|
||||
vector<int>:Array{Int32, 1}
|
||||
Rect*:NONCONVERT3
|
||||
MatShape:Array{Int32, 1}
|
||||
c_string:Cstring
|
||||
vector<RotatedRect>:Array{RotatedRect, 1}
|
||||
Net:Net
|
||||
size_t:size_t
|
||||
vector<double>:Array{Float64, 1}
|
||||
Point:Point{Int32}
|
||||
Mat:InputArray
|
||||
KeyPoint:KeyPoint
|
||||
Moments:Moments
|
||||
RNG*:NONCONVERT4
|
||||
int:Int64
|
||||
vector<float>:Array{Float32, 1}
|
||||
vector<Rect>:Array{Rect{Int32}, 1}
|
||||
Scalar:Scalar
|
||||
Point2f*:NONCONVERT5
|
||||
int*:NONCONVERT6
|
||||
vector<vector<Mat>>:Array{Array{InputArray, 1}, 1}
|
||||
vector<Mat>:Array{InputArray, 1}
|
||||
vector<String>:Array{String, 1}
|
||||
vector<string>:Array{String, 1}
|
||||
vector<Point2f>:Array{Point{Float32}, 1}
|
||||
Size:Size{Int32}
|
||||
vector<MatShape>:Array{Array{Int32, 1}, 1}
|
||||
float:Float64
|
||||
Ptr<float>:Ptr{Float32}
|
||||
vector<Vec6f>:Array{Vec{Float32, 6}, 1}
|
||||
Ptr<FeatureDetector>:Ptr{Feature2D}
|
||||
Point2d:Point{Float64}
|
||||
SolvePnPMethod:SolvePnPMethod
|
||||
CirclesGridFinderParameters:CirclesGridFinderParameters
|
||||
HandEyeCalibrationMethod:HandEyeCalibrationMethod
|
||||
long long:Int64
|
||||
Reference in New Issue
Block a user