Merge pull request !6076 from xulei/lite_test0905tags/v1.0.0
| @@ -208,6 +208,9 @@ static void ResizeBilinear1C(const unsigned char *src, int src_width, int src_he | |||||
| } | } | ||||
| bool ResizeBilinear(const LiteMat &src, LiteMat &dst, int dst_w, int dst_h) { | bool ResizeBilinear(const LiteMat &src, LiteMat &dst, int dst_w, int dst_h) { | ||||
| if (dst_h <= 0 || dst_w <= 0) { | |||||
| return false; | |||||
| } | |||||
| if (src.data_type_ != LDataType::UINT8) { | if (src.data_type_ != LDataType::UINT8) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| @@ -269,6 +272,9 @@ static bool ConvertRGBAToGRAY(const unsigned char *data, LDataType data_type, in | |||||
| } | } | ||||
| bool InitFromPixel(const unsigned char *data, LPixelType pixel_type, LDataType data_type, int w, int h, LiteMat &m) { | bool InitFromPixel(const unsigned char *data, LPixelType pixel_type, LDataType data_type, int w, int h, LiteMat &m) { | ||||
| if (w <= 0 || h <= 0) { | |||||
| return false; | |||||
| } | |||||
| if (pixel_type == LPixelType::RGBA2BGR) { | if (pixel_type == LPixelType::RGBA2BGR) { | ||||
| return ConvertRGBAToBGR(data, data_type, w, h, m); | return ConvertRGBAToBGR(data, data_type, w, h, m); | ||||
| } else if (pixel_type == LPixelType::RGBA2GRAY) { | } else if (pixel_type == LPixelType::RGBA2GRAY) { | ||||
| @@ -314,7 +320,10 @@ static void CropInternal(const LiteMat &src, LiteMat &dst, int x, int y, int w, | |||||
| } | } | ||||
| bool Crop(const LiteMat &src, LiteMat &dst, int x, int y, int w, int h) { | bool Crop(const LiteMat &src, LiteMat &dst, int x, int y, int w, int h) { | ||||
| if (y < 0 || y + h > src.height_ || x < 0 || x + w > src.width_) { | |||||
| if (x <= 0 || y <= 0 || w <= 0 || h <= 0) { | |||||
| return false; | |||||
| } | |||||
| if (y + h > src.height_ || x + w > src.width_) { | |||||
| return false; | return false; | ||||
| } | } | ||||
| @@ -371,9 +380,9 @@ bool SubStractMeanNormalize(const LiteMat &src, LiteMat &dst, float *mean, float | |||||
| } | } | ||||
| template <typename T> | template <typename T> | ||||
| static void PaddWithConstant(const LiteMat &src, LiteMat &dst, const int top, const int bottom, const int left, | |||||
| const int right, const PaddBorderType pad_type, uint8_t fill_b_or_gray, uint8_t fill_g, | |||||
| uint8_t fill_r) { | |||||
| static void PadWithConstant(const LiteMat &src, LiteMat &dst, const int top, const int bottom, const int left, | |||||
| const int right, const PaddBorderType pad_type, uint8_t fill_b_or_gray, uint8_t fill_g, | |||||
| uint8_t fill_r) { | |||||
| dst.Init(src.width_ + left + right, src.height_ + top + bottom, src.channel_, src.data_type_); | dst.Init(src.width_ + left + right, src.height_ + top + bottom, src.channel_, src.data_type_); | ||||
| const T *src_start_p = src; | const T *src_start_p = src; | ||||
| T *dst_start_p = dst; | T *dst_start_p = dst; | ||||
| @@ -444,12 +453,15 @@ static void PaddWithConstant(const LiteMat &src, LiteMat &dst, const int top, co | |||||
| } | } | ||||
| } | } | ||||
| bool Padd(const LiteMat &src, LiteMat &dst, int top, int bottom, int left, int right, PaddBorderType pad_type, | |||||
| uint8_t fill_b_or_gray, uint8_t fill_g, uint8_t fill_r) { | |||||
| bool Pad(const LiteMat &src, LiteMat &dst, int top, int bottom, int left, int right, PaddBorderType pad_type, | |||||
| uint8_t fill_b_or_gray, uint8_t fill_g, uint8_t fill_r) { | |||||
| if (top <= 0 || bottom <= 0 || left <= 0 || right <= 0) { | |||||
| return false; | |||||
| } | |||||
| if (pad_type == PADD_BORDER_CONSTANT && src.data_type_ == LDataType::FLOAT32) { | if (pad_type == PADD_BORDER_CONSTANT && src.data_type_ == LDataType::FLOAT32) { | ||||
| PaddWithConstant<float>(src, dst, top, bottom, left, right, pad_type, fill_b_or_gray, fill_g, fill_r); | |||||
| PadWithConstant<float>(src, dst, top, bottom, left, right, pad_type, fill_b_or_gray, fill_g, fill_r); | |||||
| } else if (pad_type == PADD_BORDER_CONSTANT && src.data_type_ == LDataType::UINT8) { | } else if (pad_type == PADD_BORDER_CONSTANT && src.data_type_ == LDataType::UINT8) { | ||||
| PaddWithConstant<uint8_t>(src, dst, top, bottom, left, right, pad_type, fill_b_or_gray, fill_g, fill_r); | |||||
| PadWithConstant<uint8_t>(src, dst, top, bottom, left, right, pad_type, fill_b_or_gray, fill_g, fill_r); | |||||
| } else { | } else { | ||||
| return false; | return false; | ||||
| } | } | ||||
| @@ -66,8 +66,8 @@ bool Crop(const LiteMat &src, LiteMat &dst, int x, int y, int w, int h); | |||||
| bool SubStractMeanNormalize(const LiteMat &src, LiteMat &dst, float *mean, float *norm); | bool SubStractMeanNormalize(const LiteMat &src, LiteMat &dst, float *mean, float *norm); | ||||
| /// \brief padd image, the channel supports is 3 and 1 | /// \brief padd image, the channel supports is 3 and 1 | ||||
| bool Padd(const LiteMat &src, LiteMat &dst, int top, int bottom, int left, int right, PaddBorderType pad_type, | |||||
| uint8_t fill_b_or_gray, uint8_t fill_g, uint8_t fill_r); | |||||
| bool Pad(const LiteMat &src, LiteMat &dst, int top, int bottom, int left, int right, PaddBorderType pad_type, | |||||
| uint8_t fill_b_or_gray, uint8_t fill_g, uint8_t fill_r); | |||||
| /// \brief Apply affine transformation for 1 channel image | /// \brief Apply affine transformation for 1 channel image | ||||
| void Affine(LiteMat &src, LiteMat &out_img, double M[6], std::vector<size_t> dsize, UINT8_C1 borderValue); | void Affine(LiteMat &src, LiteMat &out_img, double M[6], std::vector<size_t> dsize, UINT8_C1 borderValue); | ||||
| @@ -210,8 +210,15 @@ if (BUILD_MINDDATA STREQUAL "lite" OR BUILD_MINDDATA STREQUAL "full") | |||||
| endif () | endif () | ||||
| if (BUILD_MINDDATA STREQUAL "lite_cv") | if (BUILD_MINDDATA STREQUAL "lite_cv") | ||||
| # TODO: add sentencepiece dependency | |||||
| #include(${TOP_DIR}/cmake/external_libs/sentencepiece.cmake) | |||||
| if (PLATFORM_ARM64) | |||||
| set(COMPONENT_NAME minddata-arm64-${PROCESS_UNIT}) | |||||
| elseif (PLATFORM_ARM32) | |||||
| set(COMPONENT_NAME minddata-arm32-${PROCESS_UNIT}) | |||||
| elseif (WIN32) | |||||
| set(COMPONENT_NAME minddata-win-${PROCESS_UNIT}) | |||||
| else () | |||||
| set(COMPONENT_NAME minddata-ubuntu-${PROCESS_UNIT}) | |||||
| endif() | |||||
| add_compile_definitions(ENABLE_ANDROID) | add_compile_definitions(ENABLE_ANDROID) | ||||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/minddata) | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/minddata) | ||||
| endif () | endif () | ||||
| @@ -51,7 +51,7 @@ LiteMat Lite3CImageProcess(LiteMat &lite_mat_bgr) { | |||||
| MS_LOG(ERROR) << "ResizeBilinear error"; | MS_LOG(ERROR) << "ResizeBilinear error"; | ||||
| } | } | ||||
| LiteMat lite_mat_convert_float; | LiteMat lite_mat_convert_float; | ||||
| ret = ConvertTo(lite_mat_resize, lite_mat_convert_float, 1.0 ); | |||||
| ret = ConvertTo(lite_mat_resize, lite_mat_convert_float, 1.0); | |||||
| if (!ret) { | if (!ret) { | ||||
| MS_LOG(ERROR) << "ConvertTo error"; | MS_LOG(ERROR) << "ConvertTo error"; | ||||
| } | } | ||||
| @@ -222,7 +222,7 @@ TEST_F(MindDataImageProcess, TestPadd) { | |||||
| ResizeBilinear(lite_mat_bgr, lite_mat_resize, 256, 256); | ResizeBilinear(lite_mat_bgr, lite_mat_resize, 256, 256); | ||||
| LiteMat makeborder; | LiteMat makeborder; | ||||
| Padd(lite_mat_resize, makeborder, top, bottom, left, right, PaddBorderType::PADD_BORDER_CONSTANT, 255, 255, 255); | |||||
| Pad(lite_mat_resize, makeborder, top, bottom, left, right, PaddBorderType::PADD_BORDER_CONSTANT, 255, 255, 255); | |||||
| cv::Mat dst_image(256 + top + bottom, 256 + left + right, CV_8UC3, makeborder.data_ptr_); | cv::Mat dst_image(256 + top + bottom, 256 + left + right, CV_8UC3, makeborder.data_ptr_); | ||||
| @@ -245,7 +245,7 @@ TEST_F(MindDataImageProcess, TestGetDefaultBoxes) { | |||||
| int cols = 4; | int cols = 4; | ||||
| std::vector<double> benchmark_boxes(rows * cols); | std::vector<double> benchmark_boxes(rows * cols); | ||||
| std::ifstream in(benchmark, std::ios::in | std::ios::binary); | std::ifstream in(benchmark, std::ios::in | std::ios::binary); | ||||
| in.read(reinterpret_cast<char*>(benchmark_boxes.data()), benchmark_boxes.size() * sizeof(double)); | |||||
| in.read(reinterpret_cast<char *>(benchmark_boxes.data()), benchmark_boxes.size() * sizeof(double)); | |||||
| in.close(); | in.close(); | ||||
| std::vector<std::vector<float>> default_boxes = GetDefaultBoxes(config); | std::vector<std::vector<float>> default_boxes = GetDefaultBoxes(config); | ||||
| @@ -284,13 +284,13 @@ TEST_F(MindDataImageProcess, TestAffine) { | |||||
| for (size_t i = 0; i < rows; i++) { | for (size_t i = 0; i < rows; i++) { | ||||
| for (size_t j = 0; j < cols; j++) { | for (size_t j = 0; j < cols; j++) { | ||||
| if (i == 2 && j == 2) { | if (i == 2 && j == 2) { | ||||
| static_cast<UINT8_C1*>(src.data_ptr_)[i * cols + j] = 3; | |||||
| static_cast<UINT8_C1 *>(src.data_ptr_)[i * cols + j] = 3; | |||||
| } else if (i == 2) { | } else if (i == 2) { | ||||
| static_cast<UINT8_C1*>(src.data_ptr_)[i * cols + j] = 2; | |||||
| static_cast<UINT8_C1 *>(src.data_ptr_)[i * cols + j] = 2; | |||||
| } else if (j == 2) { | } else if (j == 2) { | ||||
| static_cast<UINT8_C1*>(src.data_ptr_)[i * cols + j] = 1; | |||||
| static_cast<UINT8_C1 *>(src.data_ptr_)[i * cols + j] = 1; | |||||
| } else { | } else { | ||||
| static_cast<UINT8_C1*>(src.data_ptr_)[i * cols + j] = 0; | |||||
| static_cast<UINT8_C1 *>(src.data_ptr_)[i * cols + j] = 0; | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -305,13 +305,13 @@ TEST_F(MindDataImageProcess, TestAffine) { | |||||
| for (size_t i = 0; i < rows; i++) { | for (size_t i = 0; i < rows; i++) { | ||||
| for (size_t j = 0; j < cols; j++) { | for (size_t j = 0; j < cols; j++) { | ||||
| if (i == 2 && j == 2) { | if (i == 2 && j == 2) { | ||||
| static_cast<UINT8_C1*>(expect.data_ptr_)[i * cols + j] = 3; | |||||
| static_cast<UINT8_C1 *>(expect.data_ptr_)[i * cols + j] = 3; | |||||
| } else if (i == 2) { | } else if (i == 2) { | ||||
| static_cast<UINT8_C1*>(expect.data_ptr_)[i * cols + j] = 1; | |||||
| static_cast<UINT8_C1 *>(expect.data_ptr_)[i * cols + j] = 1; | |||||
| } else if (j == 2) { | } else if (j == 2) { | ||||
| static_cast<UINT8_C1*>(expect.data_ptr_)[i * cols + j] = 2; | |||||
| static_cast<UINT8_C1 *>(expect.data_ptr_)[i * cols + j] = 2; | |||||
| } else { | } else { | ||||
| static_cast<UINT8_C1*>(expect.data_ptr_)[i * cols + j] = 0; | |||||
| static_cast<UINT8_C1 *>(expect.data_ptr_)[i * cols + j] = 0; | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -329,8 +329,8 @@ TEST_F(MindDataImageProcess, TestAffine) { | |||||
| for (size_t i = 0; i < rows; i++) { | for (size_t i = 0; i < rows; i++) { | ||||
| for (size_t j = 0; j < cols; j++) { | for (size_t j = 0; j < cols; j++) { | ||||
| EXPECT_EQ(static_cast<UINT8_C1*>(expect.data_ptr_)[i * cols + j].c1, | |||||
| static_cast<UINT8_C1*>(dst.data_ptr_)[i * cols + j].c1); | |||||
| EXPECT_EQ(static_cast<UINT8_C1 *>(expect.data_ptr_)[i * cols + j].c1, | |||||
| static_cast<UINT8_C1 *>(dst.data_ptr_)[i * cols + j].c1); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||