#ifndef INC_SEETA_STRUCT_H
#define INC_SEETA_STRUCT_H
#include "CStruct.h"
#include
#include
#include
#include
#include
#include
#define INCLUDED_SEETA_STRUCT
namespace seeta
{
class ImageData : public SeetaImageData {
public:
using self = ImageData;
using supper = SeetaImageData;
using byte = unsigned char;
~ImageData() = default;
ImageData( const supper &image )
: ImageData( image.data, image.width, image.height, image.channels ) {}
ImageData( int width, int height, int channels )
: supper( {
width, height, channels, nullptr
} ) {
this->m_data.reset( new byte[this->count()], std::default_delete() );
this->data = this->m_data.get();
}
ImageData() : ImageData( 0, 0, 0 ) {}
ImageData( const byte *data, int width, int height, int channels )
: ImageData( width, height, channels ) {
this->copy_from( data );
}
ImageData( const self & ) = default;
ImageData &operator=( const self & ) = default;
ImageData &operator=( const supper &other ) {
this->operator=( self( other ) );
return *this;
}
ImageData( self &&other )
: supper( {
other.width, other.height, other.channels, nullptr
} ) {
this->m_data = std::move( other.m_data );
this->data = this->m_data.get();
}
ImageData &operator=( self &&other ) {
this->width = other.width;
this->height = other.height;
this->channels = other.channels;
this->m_data = std::move( other.m_data );
this->data = this->m_data.get();
return *this;
}
void copy_from( const byte *data, int size = -1 ) {
int copy_size = this->count();
copy_size = size < 0 ? copy_size : std::min( copy_size, size );
copy( this->data, data, copy_size );
}
void copy_to( byte *data, int size = -1 ) const {
int copy_size = this->count();
copy_size = size < 0 ? copy_size : std::min( copy_size, size );
copy( data, this->data, copy_size );
}
static void copy( byte *dst, const byte *src, size_t size ) {
std::memcpy( dst, src, size );
}
int count() const {
return this->width * this->height * this->channels;
}
ImageData clone() const {
return ImageData( this->data, this->width, this->height, this->channels );
}
private:
std::shared_ptr m_data;
};
class Point : public SeetaPoint {
public:
using self = Point;
using supper = SeetaPoint;
Point( const supper &other ) : supper( other ) {}
Point( int x, int y ) : supper( {
x, y
} ) {}
Point() : Point( 0, 0 ) {}
};
class PointF : public SeetaPointF {
public:
using self = PointF;
using supper = SeetaPointF;
PointF( const supper &other ) : supper( other ) {}
PointF( double x, double y ) : supper( {
x, y
} ) {}
PointF() : PointF( 0, 0 ) {}
};
class Size : public SeetaSize {
public:
using self = Size;
using supper = SeetaSize;
Size( const supper &other ) : supper( other ) {}
Size( int width, int height ) : supper( {
width, height
} ) {}
Size() : Size( 0, 0 ) {}
};
class Rect : public SeetaRect {
public:
using self = Rect;
using supper = SeetaRect;
Rect( const supper &other ) : supper( other ) {}
Rect( int x, int y, int width, int height ) : supper( {
x, y, width, height
} ) {}
Rect() : Rect( 0, 0, 0, 0 ) {}
Rect( int x, int y, const Size &size ) : supper( {
x, y, size.width, size.height
} ) {}
Rect( const Point &top_left, int width, int height ) : supper( {
top_left.x, top_left.y, width, height
} ) {}
Rect( const Point &top_left, const Size &size ) : supper( {
top_left.x, top_left.y, size.width, size.height
} ) {}
Rect( const Point &top_left, const Point &bottom_right ) : supper( {
top_left.x, top_left.y, bottom_right.x - top_left.x, bottom_right.y - top_left.y
} ) {}
operator Point() const {
return{ this->x, this->y };
}
operator Size() const {
return{ this->width, this->height };
}
};
class Region : public SeetaRegion {
public:
using self = Region;
using supper = SeetaRegion;
Region( const supper &other ) : supper( other ) {}
Region( int top, int bottom, int left, int right ) : supper( {
top, bottom, left, right
} ) {}
Region() : Region( 0, 0, 0, 0 ) {}
Region( const Rect &rect ) : Region( rect.y, rect.y + rect.height, rect.x, rect.x + rect.width ) {}
operator Rect() const {
return{ left, top, right - left, bottom - top };
}
};
class ModelSetting : public SeetaModelSetting {
public:
using self = ModelSetting;
using supper = SeetaModelSetting;
enum Device
{
AUTO,
CPU,
GPU
};
~ModelSetting() = default;
ModelSetting()
: supper( {
SEETA_DEVICE_AUTO, 0, nullptr
} ) {
this->update();
}
ModelSetting( const supper &other )
: supper( {
other.device, other.id, nullptr
} ) {
if( other.model ) {
int i = 0;
while( other.model[i] ) {
m_model_string.emplace_back( other.model[i] );
++i;
}
}
this->update();
}
ModelSetting( const self &other )
: supper( {
other.device, other.id, nullptr
} ) {
this->m_model_string = other.m_model_string;
this->update();
}
ModelSetting &operator=( const supper &other ) {
this->operator=( self( other ) );
return *this;
}
ModelSetting &operator=( const self &other ) {
this->device = other.device;
this->id = other.id;
this->m_model_string = other.m_model_string;
this->update();
return *this;
}
ModelSetting( self &&other )
: supper( {
other.device, other.id, nullptr
} ) {
this->m_model_string = std::move( other.m_model_string );
this->update();
}
ModelSetting &operator=( self &&other ) {
this->device = other.device;
this->id = other.id;
this->m_model_string = std::move( other.m_model_string );
this->update();
return *this;
}
ModelSetting( const std::string &model, SeetaDevice device, int id )
: supper( {
device, id, nullptr
} ) {
this->append( model );
}
ModelSetting( const std::string &model, SeetaDevice device ) : self( model, device, 0 ) {}
ModelSetting( const std::string &model, Device device, int id ) : self( model, SeetaDevice( device ), id ) {}
ModelSetting( const std::string &model, Device device ) : self( model, SeetaDevice( device ) ) {}
ModelSetting( const std::string &model ) : self( model, SEETA_DEVICE_AUTO ) {}
ModelSetting( const std::vector &model, SeetaDevice device, int id )
: supper( {
device, id, nullptr
} ) {