-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit daf101e
Showing
23 changed files
with
1,846 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
bin | ||
windows/.vs | ||
windows/python/x64 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#ifdef USE_OPENCV | ||
#include <opencv2/opencv.hpp> | ||
#endif | ||
#include "zero/python/python.h" | ||
|
||
|
||
|
||
int main(int argc, char* argv[]) { | ||
// open python engine | ||
// zero::Python python(python_root) if can't find python with "where/which python" in cmd. | ||
zero::Python python; | ||
|
||
|
||
//import cv2 | ||
auto cv2 = python["cv2"]; | ||
|
||
//image = cv2.imread("data/lena.jpg") | ||
auto python_image = cv2["imread"]("E:/zero/data/lena.jpg"); | ||
cv2["imwrite"]("E:/zero/data/lena.png", python_image); | ||
|
||
#ifdef USE_OPENCV | ||
try { | ||
auto cpp_image = python_image.get<zero::Mat<uchar>>().get<cv::Mat>(); | ||
cv::imshow("cpp", cpp_image); | ||
cv::waitKey(0); | ||
} | ||
catch (std::exception& error) { | ||
std::cout << error.what(); | ||
}; | ||
|
||
#endif | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#pragma once | ||
#include <string> | ||
#include "zero/common.h" | ||
namespace zero { | ||
std::string ZERO_API Lower(const std::string &input); | ||
std::string ZERO_API Execute(const std::string& command, const bool error = false); | ||
std::string ZERO_API Convert(const std::wstring& input); | ||
std::wstring ZERO_API Convert(const std::string& input); | ||
// template <typename To, typename From> | ||
// typename std::enable_if<!std::is_same<To, From>::value, To>::type lexical_cast(const From& from); | ||
// template <typename To, typename From> | ||
// typename std::enable_if<std::is_same<To, From>::value, To>::type lexical_cast(const From& from); | ||
// | ||
// template ZERO_API double lexical_cast<double>(const double& from); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
#pragma once | ||
#include <stdexcept> | ||
#include <vector> | ||
namespace zero { | ||
|
||
class Object { | ||
public: | ||
Object() {}; | ||
virtual ~Object() {}; | ||
}; | ||
template <typename Type> | ||
class Template : public Object { | ||
public: | ||
Template(const Type &data) :data_(data) {}; | ||
|
||
const Type& get() const { return data_; } | ||
Type& get() { return data_; } | ||
private: | ||
Type data_; | ||
}; | ||
|
||
template<typename Type> | ||
Type RemoveReference(const Type& s) { | ||
throw std::runtime_error("this function can't callable."); | ||
return Type(); | ||
} | ||
|
||
template <typename Type> | ||
struct Range { | ||
Type minimum; | ||
Type maximum; | ||
}; | ||
|
||
template <typename Type> | ||
class Storage: public Object { | ||
public: | ||
virtual inline bool empty() const { | ||
return this->datas_.empty(); | ||
} | ||
virtual inline void clear() { | ||
datas_.clear(); | ||
} | ||
|
||
protected: | ||
Type datas_; | ||
}; | ||
|
||
template <typename Type> | ||
class Iterator: virtual public Storage<Type> { | ||
public: | ||
using iterator = typename Type::iterator; | ||
using const_iterator = typename Type::const_iterator; | ||
|
||
virtual inline iterator begin() { | ||
return this->datas_.begin(); | ||
} | ||
virtual inline const_iterator begin() const { | ||
return this->datas_.begin(); | ||
} | ||
virtual inline iterator end() { | ||
return this->datas_.end(); | ||
} | ||
|
||
virtual inline const_iterator end() const { | ||
return this->datas_.end(); | ||
} | ||
|
||
virtual inline size_t size() const { | ||
return this->datas_.size(); | ||
} | ||
}; | ||
|
||
|
||
template <typename Type, typename Stype> | ||
class Array: virtual public Storage<Stype> { | ||
public: | ||
Array() {}; | ||
~Array() {}; | ||
virtual inline Type &operator[](const int id) { | ||
if (id >= 0) { | ||
return this->datas_[id]; | ||
} | ||
else { | ||
int size = static_cast<int>(this->datas_.size()); | ||
return this->datas_[id + size]; | ||
} | ||
} | ||
virtual inline const Type &operator[](const int id) const { | ||
if (id >= 0) { | ||
return this->datas_[id]; | ||
} | ||
else { | ||
int size = static_cast<int>(this->datas_.size()); | ||
return this->datas_[id + size]; | ||
} | ||
} | ||
virtual void resize(const size_t size, const Type &value) { | ||
this->datas_.resize(size, value); | ||
} | ||
virtual void resize(const size_t size) { | ||
this->datas_.resize(size); | ||
} | ||
virtual inline void push_back(const Type &data) { | ||
this->datas_.push_back(data); | ||
} | ||
}; | ||
|
||
template <typename Type, typename Stype> | ||
class Array<Type&, Stype>: virtual public Storage<Stype> { | ||
public: | ||
Array() {}; | ||
~Array() { | ||
clear(); | ||
}; | ||
virtual inline Type &operator[](const int id) { | ||
if (id >= 0) { | ||
return *(this->datas_[id]); | ||
} | ||
else { | ||
int size = static_cast<int>(this->datas_.size()); | ||
return *(this->datas_[id + size]); | ||
} | ||
} | ||
virtual inline const Type &operator[](const int id) const { | ||
if (id >= 0) { | ||
return *(this->datas_[id]); | ||
} | ||
else { | ||
int size = static_cast<int>(this->datas_.size()); | ||
return *(this->datas_[id + size]); | ||
} | ||
} | ||
template<typename... Atype> | ||
Type * New(Atype&&... args) { | ||
auto pt = new Type(args...); | ||
storage_.push_back(pt); | ||
push_back(pt); | ||
return pt; | ||
} | ||
|
||
Type * New() { | ||
auto pt = new Type; | ||
storage_.push_back(pt); | ||
push_back(pt); | ||
return pt; | ||
} | ||
// template <typename ...Ptype> | ||
// virtual inline Type *New(Ptype&&... args) { | ||
// auto ptr = std::make_shared<Type>(args...); | ||
// storage_.pop_back(ptr); | ||
// return ptr; | ||
// return nullptr; | ||
// } | ||
|
||
virtual void resize(const size_t size, Type *value) { | ||
this->datas_.resize(size, value); | ||
} | ||
virtual void resize(const size_t size) { | ||
this->datas_.resize(size); | ||
} | ||
virtual inline void push_back(Type *data) { | ||
this->datas_.push_back(data); | ||
} | ||
|
||
virtual inline void clear() { | ||
Storage<Stype>::clear(); | ||
for (const auto &storage : storage_) { | ||
if(storage) delete storage; | ||
} | ||
storage_.clear(); | ||
} | ||
private: | ||
std::vector<Type *> storage_; | ||
}; | ||
|
||
|
||
template<size_t id = 0, typename FType, typename ...AType> | ||
inline typename std::enable_if_t<id == sizeof ...(AType)> for_each(std::tuple<AType ...>&, FType) { } | ||
|
||
template<size_t id = 0, typename FType, typename ...AType> | ||
inline typename std::enable_if_t < id < sizeof ...(AType)> for_each(std::tuple<AType ...>& argv, FType &function) { | ||
function(std::get<id>(argv)); | ||
for_each<id + 1, FType, AType...>(argv, function); | ||
} | ||
|
||
template<size_t id = 0, typename FType, typename ...AType> | ||
inline typename std::enable_if_t<id == sizeof ...(AType)> for_each(std::tuple<AType& ...>, FType) { } | ||
|
||
template<size_t id = 0, typename FType, typename ...AType> | ||
inline typename std::enable_if_t < id < sizeof ...(AType)> for_each(std::tuple<AType& ...> argv, FType function) { | ||
function(std::get<id>(argv)); | ||
for_each<id + 1, FType, AType...>(argv, function); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#pragma once | ||
#include <vector> | ||
#include <map> | ||
//#include <algorithm> | ||
#include "base.h" | ||
|
||
namespace zero { | ||
template<typename Type> | ||
class vector : public Iterator<std::vector<Type>>, public Array<Type, std::vector<Type>> { | ||
public: | ||
vector() {}; | ||
~vector() {}; | ||
|
||
vector(size_t size) { | ||
this->datas_.resize(size); | ||
} | ||
vector(size_t size, Type value) { | ||
this->datas_.resize(size, value); | ||
} | ||
vector(const std::initializer_list<Type> &datas) { | ||
this->datas_ = datas; | ||
} | ||
|
||
virtual vector &operator=(std::initializer_list<Type> datas) { | ||
this->datas_ = datas; | ||
return *this; | ||
} | ||
|
||
// virtual vector operator-(const vector &datas) { | ||
// vector reval; | ||
// auto size = std::min(datas.size(), this->size()); | ||
// reval.resize(size); | ||
// for (auto i = 0; i < size; i++) { | ||
// reval[i] = this->datas_[i] - datas[i]; | ||
// } | ||
// return reval; | ||
// } | ||
}; | ||
|
||
template<typename Type> | ||
class vector<Type &>: public Iterator<std::vector<Type *>>, public Array<Type &, std::vector<Type *>> { | ||
public: | ||
vector() {}; | ||
~vector() {}; | ||
|
||
vector(size_t size) { | ||
this->datas_.resize(size); | ||
} | ||
vector(size_t size, Type value) { | ||
this->datas_.resize(size, value); | ||
} | ||
vector(const std::initializer_list<Type *> &datas) { | ||
this->datas_ = datas; | ||
} | ||
|
||
virtual vector &operator=(const std::initializer_list<Type *> &datas) { | ||
this->datas_ = datas; | ||
return *this; | ||
} | ||
private: | ||
|
||
}; | ||
} |
Oops, something went wrong.