forked from espressif/arduino-esp32
IDF release/v4.4 f23dcd3555 (#5996)
esp-dsp: master 6b25cbb esp-face: master d141502 esp-rainmaker: f1b82c7 esp32-camera: master 61400bc esp_littlefs: master 3c29afc
This commit is contained in:
@ -48,6 +48,15 @@ namespace dl
|
||||
output[2] = input & 0xF8; // red
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convert RGB565 image to RGB888 image.
|
||||
*
|
||||
* @param image ptr of RGB565 image
|
||||
* @param image_shape shape of the input image
|
||||
* @return Tensor<uint8_t>* output RGB88 image
|
||||
*/
|
||||
Tensor<uint8_t> *convert_image_rgb565_to_rgb888(uint16_t *image, std::vector<int> &image_shape);
|
||||
|
||||
/**
|
||||
* @brief Convert RGB565 pixel to Gray.
|
||||
*
|
||||
@ -435,5 +444,48 @@ namespace dl
|
||||
*/
|
||||
Tensor<uint8_t> *rgb2hsv(Tensor<uint8_t> &image, bool bgr = false, bool fast = true);
|
||||
|
||||
/**
|
||||
* @brief resize an image to the target shape.
|
||||
*
|
||||
* @param image the input image Tensor
|
||||
* @param target_shape the target shape of the resized image.
|
||||
* @param resize_type one of IMAGE_RESIZE_BILINEAR or IMAGE_RESIZE_MEAN or IMAGE_RESIZE_NEAREST
|
||||
* @return Tensor<uint8_t>* the pointer of the resized image Tensor
|
||||
*/
|
||||
Tensor<uint8_t> *resize_image(Tensor<uint8_t> &image, std::vector<int> target_shape, resize_type_t resize_type);
|
||||
|
||||
/**
|
||||
* @brief resize an image to the target shape.
|
||||
*
|
||||
* @param image the input image Tensor
|
||||
* @param resized_image the resized image Tensor
|
||||
* @param resize_type one of IMAGE_RESIZE_BILINEAR or IMAGE_RESIZE_MEAN or IMAGE_RESIZE_NEAREST
|
||||
*/
|
||||
void resize_image(Tensor<uint8_t> &image, Tensor<uint8_t> &resized_image, resize_type_t resize_type);
|
||||
|
||||
/**
|
||||
* @brief resize an image to the target shape with nearest method.
|
||||
*
|
||||
* @tparam T
|
||||
* @param image the pointer of the input image
|
||||
* @param input_shape the input shape of the image
|
||||
* @param target_shape the target shape of the resized image
|
||||
* @return T* the pointer of the resized image
|
||||
*/
|
||||
template <typename T>
|
||||
T *resize_image_nearest(T *image, std::vector<int> input_shape, std::vector<int> target_shape);
|
||||
|
||||
/**
|
||||
* @brief resize an image to the target shape with nearest method.
|
||||
*
|
||||
* @tparam T
|
||||
* @param image the pointer of the input image
|
||||
* @param input_shape the input shape of the image
|
||||
* @param resized_image the pointer of the resized image
|
||||
* @param target_shape the target shape of the resized image
|
||||
*/
|
||||
template <typename T>
|
||||
void resize_image_nearest(T *image, std::vector<int> input_shape, T *resized_image, std::vector<int> target_shape);
|
||||
|
||||
} // namespace image
|
||||
} // namespace dl
|
||||
|
@ -57,10 +57,10 @@ namespace dl
|
||||
const char *name = "AvgPool2D") : Layer(name),
|
||||
output_exponent(output_exponent),
|
||||
filter_shape(filter_shape),
|
||||
padding_type(padding_type),
|
||||
padding(padding),
|
||||
stride_y(stride_y),
|
||||
stride_x(stride_x),
|
||||
padding_type(padding_type),
|
||||
padding(padding),
|
||||
output_shape({})
|
||||
{
|
||||
this->output = new Tensor<feature_t>;
|
||||
|
@ -36,7 +36,10 @@ namespace dl
|
||||
* false: the output will store to a separate memory
|
||||
*/
|
||||
ExpandDims(std::vector<int> axis, const char *name = "ExpandDims", bool inplace = false) : Layer(name),
|
||||
axis(axis), inplace(inplace), output_shape({})
|
||||
output_shape({}),
|
||||
axis(axis),
|
||||
output(NULL),
|
||||
inplace(inplace)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ namespace dl
|
||||
* @param inplace true: the output will store to input0
|
||||
* false: the output will store to a separate memory
|
||||
*/
|
||||
Flatten(const char *name = "Flatten", bool inplace = false) : Layer(name), inplace(inplace), output_shape({})
|
||||
Flatten(const char *name = "Flatten", bool inplace = false) : Layer(name), output(NULL), inplace(inplace), output_shape({})
|
||||
{}
|
||||
|
||||
/**
|
||||
|
@ -53,10 +53,10 @@ namespace dl
|
||||
const int stride_x = 1,
|
||||
const char *name = "MaxPool2D") : Layer(name),
|
||||
filter_shape(filter_shape),
|
||||
padding_type(padding_type),
|
||||
padding(padding),
|
||||
stride_y(stride_y),
|
||||
stride_x(stride_x),
|
||||
padding_type(padding_type),
|
||||
padding(padding),
|
||||
output_shape({})
|
||||
{
|
||||
this->output = new Tensor<feature_t>;
|
||||
|
@ -18,7 +18,7 @@ namespace dl
|
||||
* - int8_t: stands for operation in int8_t quantize
|
||||
*/
|
||||
template <typename feature_t>
|
||||
class ReLU : public Layer
|
||||
class Relu : public Layer
|
||||
{
|
||||
private:
|
||||
Tensor<feature_t> *output; /*<! output ptr of relu >*/
|
||||
@ -33,7 +33,7 @@ namespace dl
|
||||
* @param inplace true: the output will store to input0
|
||||
* false: the output will store to a separate memory
|
||||
*/
|
||||
ReLU(const char *name = "ReLU", bool inplace = false) : Layer(name),
|
||||
Relu(const char *name = "Relu", bool inplace = false) : Layer(name),
|
||||
output(NULL), inplace(inplace), output_shape({})
|
||||
{
|
||||
}
|
||||
@ -42,7 +42,7 @@ namespace dl
|
||||
* @brief Destroy the ReLU object
|
||||
*
|
||||
*/
|
||||
~ReLU()
|
||||
~Relu()
|
||||
{
|
||||
if ((!this->inplace) && (this->output != NULL))
|
||||
{
|
||||
|
@ -35,7 +35,9 @@ namespace dl
|
||||
* false: the output will store to a separate memory
|
||||
*/
|
||||
Reshape(std::vector<int> shape, const char *name = "Reshape", bool inplace = false) : Layer(name),
|
||||
output_shape(shape), inplace(inplace)
|
||||
output(NULL),
|
||||
inplace(inplace),
|
||||
output_shape(shape)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,11 @@ namespace dl
|
||||
* @param inplace true: the output will store to input0
|
||||
* false: the output will store to a separate memory
|
||||
*/
|
||||
Squeeze(int axis = INT32_MAX, const char *name = "Squeeze", bool inplace = false) : Layer(name), axis(axis), inplace(inplace), output_shape({})
|
||||
Squeeze(int axis = INT32_MAX, const char *name = "Squeeze", bool inplace = false) : Layer(name),
|
||||
output(NULL),
|
||||
inplace(inplace),
|
||||
axis(axis),
|
||||
output_shape({})
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,11 @@ namespace dl
|
||||
* false: the output will store to a separate memory
|
||||
*/
|
||||
Sub2D(const int output_exponent, const Activation<feature_t> *activation = NULL, const char *name = "Sub2D", bool inplace = false) : Layer(name),
|
||||
output_exponent(output_exponent), activation(activation), output(NULL), inplace(inplace), output_shape({})
|
||||
output_exponent(output_exponent),
|
||||
activation(activation),
|
||||
output(NULL),
|
||||
inplace(inplace),
|
||||
output_shape({})
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,11 @@ namespace dl
|
||||
* @param inplace true: the output will store to input
|
||||
* false: the output will store to a separate memory
|
||||
*/
|
||||
Transpose(std::vector<int> perm = {}, const char *name = "Transpose", bool inplace = false) : Layer(name), perm(perm), inplace(inplace), output_shape({})
|
||||
Transpose(std::vector<int> perm = {}, const char *name = "Transpose", bool inplace = false) : Layer(name),
|
||||
output(NULL),
|
||||
inplace(inplace),
|
||||
perm(perm),
|
||||
output_shape({})
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -7,46 +7,143 @@ typedef struct
|
||||
int area; /*!< Area of connected domains >*/
|
||||
std::vector<int> center; /*<! centroid of connected domains [x, y] >*/
|
||||
std::vector<int> box; /*<! [left_up_x, left_up_y, right_down_x, right_down_y] >*/
|
||||
} components_stats_t;
|
||||
} color_detect_result_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
std::vector<int> start_col;
|
||||
std::vector<int> end_col;
|
||||
std::vector<int> row;
|
||||
std::vector<int> index;
|
||||
std::vector<int> area;
|
||||
} color_segment_result_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
std::vector<uint8_t> color_thresh; /*!< threshold of colors, The threshold of each color is composed of 6 numbers >*/
|
||||
int area_thresh; /*!< the area threshold of each color,
|
||||
the area that is smaller than the threshold is filtered >*/
|
||||
std::string name; /*!<name of the color>*/
|
||||
} color_info_t;
|
||||
|
||||
class ColorDetector
|
||||
{
|
||||
private:
|
||||
std::vector<std::vector<components_stats_t>> results; /*!< detection results >*/
|
||||
std::vector<std::vector<color_detect_result_t>> detection_results; /*!< detection results >*/
|
||||
std::vector<color_segment_result_t> segmentation_results; /*!< segmentation results >*/
|
||||
std::vector<color_info_t> registered_colors; /*!< the infomation of registered colors >*/
|
||||
std::vector<uint8_t> color_thresh_offset; /*!< HSV offset of the registered colors>*/
|
||||
std::vector<int> detection_shape; /*!< the inference shape of images, the input image will be resized to this shape.
|
||||
if the shape == {}, the input image will not be resized >*/
|
||||
bool bgr; /*!< true: the input image is in BGR format
|
||||
false: the input image is in RGB format >*/
|
||||
int id_nums; /*!< the number of registered colors in history>*/
|
||||
float h_ratio;
|
||||
float w_ratio;
|
||||
void color_detection_forward(dl::Tensor<uint8_t> &bin, int area_thresh);
|
||||
|
||||
public:
|
||||
std::vector<std::vector<uint8_t>> color_thresh; /*!< threshold of colors, The threshold of each color is composed of 6 numbers >*/
|
||||
std::vector<int> area_thresh; /*!< the area threshold of each color,
|
||||
the area that is smaller than the threshold is filtered >*/
|
||||
bool bgr; /*!< true: the input image is in BGR format
|
||||
false: the input image is in RGB format >*/
|
||||
|
||||
/**
|
||||
* @brief get the color threshold of rectangular region in the image
|
||||
*
|
||||
* @param image the input image
|
||||
* @param image the input image in RGB888 format.
|
||||
* @param box the coordinates of the rectanglar region : [left_up_x, left_up_y, right_down_x, right_down_y]
|
||||
* @return std::vector<uint8_t> the threshold.
|
||||
*/
|
||||
std::vector<uint8_t> cal_color_thresh(dl::Tensor<uint8_t> &image, std::vector<int> box);
|
||||
|
||||
/**
|
||||
* @brief get the color threshold of rectangular region in the image
|
||||
*
|
||||
* @param input the ptr of RGB565 image.
|
||||
* @param input_shape shape of the input image.
|
||||
* @param box the coordinates of the rectanglar region : [left_up_x, left_up_y, right_down_x, right_down_y]
|
||||
* @return std::vector<uint8_t> the threshold.
|
||||
*/
|
||||
std::vector<uint8_t> cal_color_thresh(uint16_t *input, std::vector<int> input_shape, std::vector<int> box);
|
||||
|
||||
/**
|
||||
* @brief register a new color to the color detector
|
||||
*
|
||||
* @param image the input image in RGB888 format.
|
||||
* @param box the coordinates of the rectanglar region : [left_up_x, left_up_y, right_down_x, right_down_y]
|
||||
* @param area_thresh the area threshold of the color
|
||||
* @param id the index of the color
|
||||
* @return int the number of the registered colors. if the id is not valid, return -1.
|
||||
*/
|
||||
int register_color(dl::Tensor<uint8_t> &image, std::vector<int> box, int area_thresh = 256, std::string color_name = "", int id = -1);
|
||||
|
||||
/**
|
||||
* @brief register a new color to the color detector
|
||||
*
|
||||
* @param input the ptr of RGB565 image.
|
||||
* @param input_shape shape of the input image.
|
||||
* @param box the coordinates of the rectanglar region : [left_up_x, left_up_y, right_down_x, right_down_y]
|
||||
* @param area_thresh the area threshold of the color
|
||||
* @param id the index of the color
|
||||
* @return int the number of the registered colors. if the id is not valid, return -1.
|
||||
*/
|
||||
int register_color(uint16_t *input, std::vector<int> input_shape, std::vector<int> box, int area_thresh = 256, std::string color_name = "", int id = -1);
|
||||
|
||||
/**
|
||||
* @brief register a new color to the color detector
|
||||
*
|
||||
* @param color_thresh the color threshold
|
||||
* @param area_thresh the area threshold of the color
|
||||
* @param id the index of the color
|
||||
* @return int the number of the registered colors. if the id is not valid, return -1.
|
||||
*/
|
||||
int register_color(std::vector<uint8_t> color_thresh, int area_thresh = 256, std::string color_name = "", int id = -1);
|
||||
|
||||
/**
|
||||
* @brief delete a registered color
|
||||
*
|
||||
* @param id the index of the color
|
||||
* @return int the number of the registered colors. if the id is not valid, return -1.
|
||||
*/
|
||||
int delete_color(int id = -1);
|
||||
|
||||
/**
|
||||
* @brief delete a registered color
|
||||
*
|
||||
* @param color_name name of the registered_color
|
||||
* @return int the number of the registered colors. if the id is not valid, return -1.
|
||||
*/
|
||||
int delete_color(std::string color_name);
|
||||
|
||||
/**
|
||||
* @brief delete all the registered colors
|
||||
*
|
||||
*/
|
||||
void clear_color();
|
||||
|
||||
/**
|
||||
* @brief detect the colors based on the color thresholds
|
||||
*
|
||||
* @param image the input image.
|
||||
* @return std::vector<std::vector<components_stats_t>>& detection result.
|
||||
* @return std::vector<std::vector<color_detect_result_t>>& detection result.
|
||||
*/
|
||||
std::vector<std::vector<components_stats_t>> &detect(dl::Tensor<uint8_t> &image);
|
||||
std::vector<std::vector<color_detect_result_t>> &detect(dl::Tensor<uint8_t> &image, std::vector<int> color_ids = {});
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param input
|
||||
* @param input_shape
|
||||
* @return std::vector<std::vector<color_detect_result_t>>&
|
||||
*/
|
||||
std::vector<std::vector<color_detect_result_t>> &detect(uint16_t *input_shape, std::vector<int> shape, std::vector<int> color_ids = {});
|
||||
|
||||
/**
|
||||
* @brief Construct a new Color Detector object
|
||||
*
|
||||
* @param color_thresh threshold of colors, The threshold of each color is composed of 6 numbers
|
||||
* @param area_thresh the area threshold of each color,the area that is smaller than the threshold is filtered
|
||||
* @param color_thresh_offset HSV offset of the registered colors>
|
||||
* @param detection_shape the inference shape of images, the input image will be resized to this shape
|
||||
* @param bgr true: the input image is in BGR format
|
||||
* false: the input image is in RGB format
|
||||
*/
|
||||
ColorDetector(std::vector<std::vector<uint8_t>> color_thresh, std::vector<int> area_thresh, bool bgr = false) : color_thresh(color_thresh), area_thresh(area_thresh), bgr(bgr)
|
||||
ColorDetector(std::vector<uint8_t> color_thresh_offset = {}, std::vector<int> detection_shape = {}, bool bgr = true) : color_thresh_offset(color_thresh_offset),
|
||||
detection_shape(detection_shape), bgr(bgr), id_nums(0)
|
||||
{
|
||||
}
|
||||
|
||||
@ -57,12 +154,213 @@ public:
|
||||
~ColorDetector() {}
|
||||
|
||||
/**
|
||||
* @brief Get the results object
|
||||
* @brief Get the detection results object
|
||||
*
|
||||
* @return std::vector<std::vector<components_stats_t>>& the detection result.
|
||||
* @return std::vector<std::vector<color_detect_result_t>>& the detection result.
|
||||
*/
|
||||
std::vector<std::vector<components_stats_t>> &get_results()
|
||||
std::vector<std::vector<color_detect_result_t>> &get_detection_results()
|
||||
{
|
||||
return this->results;
|
||||
return this->detection_results;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the segmentation results object
|
||||
*
|
||||
* @return std::vector<color_segment_result_t>& the segmentation result.
|
||||
*/
|
||||
std::vector<color_segment_result_t> &get_segmentation_results()
|
||||
{
|
||||
return this->segmentation_results;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the registered colors object
|
||||
*
|
||||
* @return std::vector<color_info_t> the information of resgistered colors
|
||||
*/
|
||||
std::vector<color_info_t> get_registered_colors()
|
||||
{
|
||||
return this->registered_colors;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the color thresh offset object
|
||||
*
|
||||
* @param color_thresh_offset the offset of color thresh for registered colors
|
||||
* @return ColorDetector&
|
||||
*/
|
||||
ColorDetector &set_color_thresh_offset(std::vector<uint8_t> color_thresh_offset)
|
||||
{
|
||||
assert(color_thresh_offset.size() == 3);
|
||||
this->color_thresh_offset = color_thresh_offset;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the color thresh offset object
|
||||
*
|
||||
* @return std::vector<uint8_t> color_thresh_offset
|
||||
*/
|
||||
std::vector<uint8_t> get_color_thresh_offset()
|
||||
{
|
||||
return this->color_thresh_offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the area thresh object
|
||||
*
|
||||
* @param area_thresh the area thresh for each registered colors
|
||||
* @return ColorDetector&
|
||||
*/
|
||||
ColorDetector &set_area_thresh(std::vector<int> area_thresh)
|
||||
{
|
||||
assert((area_thresh.size() == this->registered_colors.size()) || (area_thresh.size() == 1));
|
||||
if (area_thresh.size() == 1)
|
||||
{
|
||||
for (int i = 0; i < this->registered_colors.size(); ++i)
|
||||
{
|
||||
this->registered_colors[i].area_thresh = area_thresh[0];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < this->registered_colors.size(); ++i)
|
||||
{
|
||||
this->registered_colors[i].area_thresh = area_thresh[i];
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the area thresh object
|
||||
*
|
||||
* @param area_thresh the area thresh for each registered colors
|
||||
* @param id index of the registered color
|
||||
* @return ColorDetector&
|
||||
*/
|
||||
ColorDetector &set_area_thresh(int area_thresh, int id)
|
||||
{
|
||||
assert((id >= 0) && (id < this->registered_colors.size()));
|
||||
this->registered_colors[id].area_thresh = area_thresh;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the bgr object
|
||||
*
|
||||
* @param bgr
|
||||
* @return ColorDetector&
|
||||
*/
|
||||
ColorDetector &set_bgr(bool bgr)
|
||||
{
|
||||
this->bgr = bgr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the bgr object
|
||||
*
|
||||
* @return bool bgr flag
|
||||
*/
|
||||
bool get_bgr()
|
||||
{
|
||||
return this->bgr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the detection shape object
|
||||
*
|
||||
* @return std::vector<int>
|
||||
*/
|
||||
std::vector<int> get_detection_shape()
|
||||
{
|
||||
return this->detection_shape;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the detection shape object
|
||||
*
|
||||
* @param detection_shape the inference shape of images, the input image will be resized to this shape
|
||||
* @return ColorDetector&
|
||||
*/
|
||||
ColorDetector &set_detection_shape(std::vector<int> detection_shape)
|
||||
{
|
||||
assert(detection_shape.size() == 3);
|
||||
this->detection_shape = detection_shape;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the registered colors num
|
||||
*
|
||||
* @return int the registered colors num
|
||||
*/
|
||||
int get_registered_colors_num()
|
||||
{
|
||||
return this->registered_colors.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief print the detection detection results
|
||||
*
|
||||
* @param tag
|
||||
*/
|
||||
void print_detection_results(const char *tag = "RGB")
|
||||
{
|
||||
printf("\n%s | color detection result:\n", tag);
|
||||
for (int i = 0; i < this->detection_results.size(); ++i)
|
||||
{
|
||||
printf("color %d: detected box :%d\n", i, this->detection_results[i].size());
|
||||
for (int j = 0; j < this->detection_results[i].size(); ++j)
|
||||
{
|
||||
printf("center: (%d, %d)\n", this->detection_results[i][j].center[0], this->detection_results[i][j].center[1]);
|
||||
printf("box: (%d, %d), (%d, %d)\n", this->detection_results[i][j].box[0], this->detection_results[i][j].box[1], this->detection_results[i][j].box[2], this->detection_results[i][j].box[3]);
|
||||
printf("area: %d\n", this->detection_results[i][j].area);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief print the segmentation results
|
||||
*
|
||||
* @param tag
|
||||
*/
|
||||
void print_segmentation_results(const char *tag = "RGB")
|
||||
{
|
||||
printf("\n%s | color segmentation result:\n", tag);
|
||||
for (int i = 0; i < this->segmentation_results.size(); ++i)
|
||||
{
|
||||
printf("color %d: detected box :%d\n", i, this->detection_results[i].size());
|
||||
for (int j = 0; j < this->segmentation_results[i].index.size(); ++j)
|
||||
{
|
||||
printf("box_index: %d, start col: %d, end col: %d, row: %d, area: %d\n",
|
||||
this->segmentation_results[i].index[j], this->segmentation_results[i].start_col[j], this->segmentation_results[i].end_col[j],
|
||||
this->segmentation_results[i].row[j], this->segmentation_results[i].area[j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief draw the color segmentation result on the input image
|
||||
*
|
||||
* @param image the input RGB image
|
||||
* @param draw_colors RGB values for each detected colors
|
||||
* @param draw_backgound draw the background if it is true
|
||||
* @param background_color RGB values for the background color
|
||||
*/
|
||||
void draw_segmentation_results(dl::Tensor<uint8_t> &image, std::vector<std::vector<uint8_t>> draw_colors, bool draw_backgound = true, std::vector<uint8_t> background_color = {0, 0, 0});
|
||||
|
||||
/**
|
||||
* @brief draw the color segmentation result on the input image
|
||||
*
|
||||
* @param image the pointer of the input RGB565 image
|
||||
* @param image_shape the shape of the input image
|
||||
* @param draw_colors RGB565 values for each detected colors
|
||||
* @param draw_backgound draw the background if it is true
|
||||
* @param background_color RGB565 values for the background color
|
||||
*/
|
||||
void draw_segmentation_results(uint16_t *image, std::vector<int> image_shape, std::vector<uint16_t> draw_colors, bool draw_backgound = true, uint16_t background_color = 0x0000);
|
||||
};
|
@ -10,6 +10,7 @@
|
||||
#include <algorithm>
|
||||
#include <math.h>
|
||||
#include <string>
|
||||
#include "esp_partition.h"
|
||||
|
||||
/**
|
||||
* @brief struct of face similarity
|
||||
@ -45,6 +46,13 @@ public:
|
||||
*/
|
||||
FaceID(int id, dl::Tensor<feature_t> &id_emb, std::string name = "");
|
||||
|
||||
/**
|
||||
* @brief Construct a new Face ID which is same as input face_id
|
||||
*
|
||||
* @param face_id input face_id
|
||||
*/
|
||||
FaceID(FaceID<feature_t> &face_id);
|
||||
|
||||
/**
|
||||
* @brief Destroy the Face ID object
|
||||
*
|
||||
|
@ -148,7 +148,7 @@ class FaceRecognizer
|
||||
* @param name name of the face id.
|
||||
* @return int the face id index of the enrolled embedding.
|
||||
*/
|
||||
int enroll_id(uint16_t *image_input, std::vector<int> shape, std::vector<int> &landmarks, std::string name="");
|
||||
int enroll_id(uint16_t *image_input, std::vector<int> shape, std::vector<int> &landmarks, std::string name="", bool update_flash = false);
|
||||
|
||||
/**
|
||||
* @brief enroll face id
|
||||
@ -158,9 +158,11 @@ class FaceRecognizer
|
||||
* @param aligned_face the Tensor to store the intermeidate aligned face.
|
||||
* @param landmarks face landmarks coordinates
|
||||
* @param name name of the face id.
|
||||
* @param update_flash true: the enrolled ids will be stored to flash
|
||||
* false: the enrolled ids will not be stored to flash
|
||||
* @return int the face id index of the enrolled embedding.
|
||||
*/
|
||||
int enroll_id(uint16_t *image_input, std::vector<int> shape, Tensor<uint8_t> &aligned_face, std::vector<int> &landmarks, std::string name="");
|
||||
int enroll_id(uint16_t *image_input, std::vector<int> shape, Tensor<uint8_t> &aligned_face, std::vector<int> &landmarks, std::string name="", bool update_flash = false);
|
||||
|
||||
/**
|
||||
* @brief enroll face id
|
||||
@ -168,9 +170,11 @@ class FaceRecognizer
|
||||
* @param image_input the Tensor of input image with format bgr888.
|
||||
* @param landmarks face landmarks coordinates
|
||||
* @param name name of the face id.
|
||||
* @param update_flash true: the enrolled ids will be stored to flash
|
||||
* false: the enrolled ids will not be stored to flash
|
||||
* @return int the face id index of the enrolled embedding.
|
||||
*/
|
||||
int enroll_id(Tensor<uint8_t> &image_input, std::vector<int> &landmarks, std::string name="");
|
||||
int enroll_id(Tensor<uint8_t> &image_input, std::vector<int> &landmarks, std::string name="", bool update_flash = false);
|
||||
|
||||
/**
|
||||
* @brief enroll face id
|
||||
@ -179,42 +183,114 @@ class FaceRecognizer
|
||||
* @param aligned_face the Tensor to store the intermeidate aligned face.
|
||||
* @param landmarks face landmarks coordinates
|
||||
* @param name name of the face id.
|
||||
* @param update_flash true: the enrolled ids will be stored to flash
|
||||
* false: the enrolled ids will not be stored to flash
|
||||
* @return int the face id index of the enrolled embedding.
|
||||
*/
|
||||
int enroll_id(Tensor<uint8_t> &image_input, Tensor<uint8_t> &aligned_face, std::vector<int> &landmarks, std::string name="");
|
||||
int enroll_id(Tensor<uint8_t> &image_input, Tensor<uint8_t> &aligned_face, std::vector<int> &landmarks, std::string name="", bool update_flash = false);
|
||||
|
||||
/**
|
||||
* @brief enroll face id
|
||||
*
|
||||
* @param aligned_face the Tensor of the input aligned face with format bgr888.
|
||||
* @param name name of the face id.
|
||||
* @param update_flash true: the enrolled ids will be stored to flash
|
||||
* false: the enrolled ids will not be stored to flash
|
||||
* @return int the face id index of the enrolled embedding.
|
||||
*/
|
||||
int enroll_id(Tensor<uint8_t> &aligned_face, std::string name="");
|
||||
int enroll_id(Tensor<uint8_t> &aligned_face, std::string name="", bool update_flash = false);
|
||||
|
||||
/**
|
||||
* @brief enroll the normalzied face embedding.
|
||||
*
|
||||
* @param emb the normalized face embbeding.
|
||||
* @param name name of the face id.
|
||||
* @return int the face id index of the enrolled embedding.
|
||||
* @param emb the normalized face embbeding.
|
||||
* @param name name of the face id.
|
||||
* @param update_flash true: the enrolled ids will be stored to flash
|
||||
* false: the enrolled ids will not be stored to flash
|
||||
* @return int the face id index of the enrolled embedding.
|
||||
*/
|
||||
int enroll_id(Tensor<float> &emb, std::string name="");
|
||||
int enroll_id(Tensor<float> &emb, std::string name="", bool update_flash = false);
|
||||
|
||||
/**
|
||||
* @brief delete the last enrolled face id.
|
||||
* @brief delete the last enrolled face id.
|
||||
* @param update_flash true: the ids will be updated to flash
|
||||
* false: the ids will not be stored to flash
|
||||
*
|
||||
* @return int the number of remained face ids.
|
||||
* if the face ids list is empty, return -1
|
||||
*/
|
||||
int delete_id();
|
||||
int delete_id(bool update_flash = false);
|
||||
|
||||
/**
|
||||
* @brief delete the face id with id index.
|
||||
* @brief delete the face id with id index.
|
||||
*
|
||||
* @param id face id index.
|
||||
* @return int the number of remained face ids.
|
||||
* if there is no matched id return -1
|
||||
* @param id face id index.
|
||||
* @param update_flash true: the ids will be updated to flash
|
||||
* false: the ids will not be stored to flash
|
||||
* @return int the number of remained face ids.
|
||||
* if there is no matched id return -1
|
||||
*/
|
||||
int delete_id(int id);
|
||||
int delete_id(int id, bool update_flash = false);
|
||||
|
||||
/**
|
||||
* @brief Set the enrolled ids
|
||||
*
|
||||
* @param ids the ids to be set
|
||||
* @param update_flash true: the ids will be updated to flash
|
||||
* false: the ids will not be stored to flash
|
||||
* @return int the number of enrolled ids.
|
||||
*/
|
||||
int set_ids(std::vector<FaceID<float> *> &ids, bool update_flash = false);
|
||||
|
||||
/**
|
||||
* @brief Set the enrolled ids from flash
|
||||
*
|
||||
* @return int the number of enrolled ids.
|
||||
*/
|
||||
int set_ids_from_flash();
|
||||
|
||||
/**
|
||||
* @brief write the enrolled ids to flash
|
||||
*
|
||||
* @return int the number of enrolled ids.
|
||||
*/
|
||||
int write_ids_to_flash();
|
||||
|
||||
/**
|
||||
* @brief Get the enrolled ids with name object
|
||||
*
|
||||
* @param name
|
||||
* @return std::vector<face_info_t>
|
||||
*/
|
||||
std::vector<face_info_t> get_enrolled_ids_with_name(std::string name);
|
||||
|
||||
/**
|
||||
* @brief Check whether the Flash partition is available
|
||||
*
|
||||
* @return int -2: the partition has not been set
|
||||
* -1: the data in the flash does not match the current model.
|
||||
* model_check_code: the Flash partition is available.
|
||||
* number of ids in flash: The IDs in Flash and RAM does not sync.
|
||||
*/
|
||||
int check_partition();
|
||||
|
||||
/**
|
||||
* @brief delete all the enrolled face ids.
|
||||
* @param update_flash true: the ids will be updated to flash
|
||||
* false: the ids will not be stored to flash
|
||||
*
|
||||
*/
|
||||
void clear_id(bool update_flash = false);
|
||||
|
||||
/**
|
||||
* @brief Set the partition for saving face ids to flash or reading face ids from flash.
|
||||
*
|
||||
* @param type esp_partition_type
|
||||
* @param subtype esp_partition_subtype
|
||||
* @param label the partition label
|
||||
* @return int 0: set the partition failed
|
||||
* 1: set the partition successfully
|
||||
*/
|
||||
int set_partition(esp_partition_type_t type, esp_partition_subtype_t subtype, const char *label);
|
||||
|
||||
};
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include "dl_define.hpp"
|
||||
#include <vector>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace dl
|
||||
{
|
||||
@ -48,10 +49,11 @@ namespace dl
|
||||
/*<! - 2D: [dilation_in_height, dilation_in_width] >*/
|
||||
std::vector<int> shape_with_dilation; /*<! - 1D: reserved >*/
|
||||
/*<! - 2D: [filter_height_with_dilation, filter_width_with_dilation, input_channel, output_channel] >*/
|
||||
std::vector<int> channel_exponent; /*<! exponent for per-channel >*/
|
||||
const int8_t* channel_exponent; /*<! exponent for per-channel >*/
|
||||
const int channel_exponent_size;
|
||||
|
||||
/**
|
||||
* @brief Construct a new Filter object.
|
||||
* @brief Construct a new Filter object.
|
||||
*
|
||||
* @param element point to element
|
||||
* @param exponent exponent of element
|
||||
@ -66,16 +68,17 @@ namespace dl
|
||||
Filter(const T *element, const int exponent, const std::vector<int> shape, const std::vector<int> dilation = {1, 1});
|
||||
|
||||
/**
|
||||
* @brief Construct a new Filter object.
|
||||
* @brief Construct a new Filter object. it is only avaliable to int16_t
|
||||
*
|
||||
* @param element point to element
|
||||
* @param channel_exponent exponent for per-channel
|
||||
* @param shape shape of element
|
||||
* @param dilation dilation of Filter
|
||||
* - 1D: reserved
|
||||
* - 2D: [dilation_in_height, dilation_in_width]
|
||||
* @param element point to element
|
||||
* @param channel_exponent exponent for per-channel
|
||||
* @param channel_exponent_size size of exponent
|
||||
* @param shape shape of element
|
||||
* @param dilation dilation of Filter
|
||||
* - 1D: reserved
|
||||
* - 2D: [dilation_in_height, dilation_in_width]
|
||||
*/
|
||||
Filter(const T *element, const std::vector<int> channel_exponent, const std::vector<int> shape, const std::vector<int> dilation = {1, 1});
|
||||
Filter(const T *element, const int8_t* channel_exponent, const int channel_exponent_size, const std::vector<int> shape, const std::vector<int> dilation = {1, 1});
|
||||
|
||||
/**
|
||||
* @brief Print the n-th filter.
|
||||
@ -98,9 +101,6 @@ namespace dl
|
||||
{
|
||||
public:
|
||||
using Constant<T>::Constant;
|
||||
std::vector<int> channel_exponent; /*<! exponent for per-channel >*/
|
||||
|
||||
Bias(const T *element, const std::vector<int> channel_exponent, const std::vector<int> shape);
|
||||
};
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user