Browse Source

add code

tags/v1.0.0
xulei2020 5 years ago
parent
commit
153672b8d3
2 changed files with 23 additions and 0 deletions
  1. +22
    -0
      mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/image_process.cc
  2. +1
    -0
      mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/lite_mat.h

+ 22
- 0
mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/image_process.cc View File

@@ -250,6 +250,26 @@ static bool ConvertRGBAToBGR(const unsigned char *data, LDataType data_type, int
return true;
}

static bool ConvertRGBAToRGB(const unsigned char *data, LDataType data_type, int w, int h, LiteMat &mat) {
if (data_type == LDataType::UINT8) {
mat.Init(w, h, 3, LDataType::UINT8);
unsigned char *ptr = mat;
const unsigned char *data_ptr = data;
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
ptr[0] = data_ptr[0];
ptr[1] = data_ptr[1];
ptr[2] = data_ptr[2];
ptr += 3;
data_ptr += 4;
}
}
} else {
return false;
}
return true;
}

static bool ConvertRGBAToGRAY(const unsigned char *data, LDataType data_type, int w, int h, LiteMat &mat) {
if (data_type == LDataType::UINT8) {
mat.Init(w, h, 1, LDataType::UINT8);
@@ -279,6 +299,8 @@ bool InitFromPixel(const unsigned char *data, LPixelType pixel_type, LDataType d
return ConvertRGBAToBGR(data, data_type, w, h, m);
} else if (pixel_type == LPixelType::RGBA2GRAY) {
return ConvertRGBAToGRAY(data, data_type, w, h, m);
} else if (pixel_type == LPixelType::RGBA2RGB) {
return ConvertRGBAToRGB(data, data_type, w, h, m);
} else {
return false;
}


+ 1
- 0
mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/lite_mat.h View File

@@ -91,6 +91,7 @@ enum LPixelType {
RGBA = 2,
RGBA2GRAY = 3,
RGBA2BGR = 4,
RGBA2RGB = 5,
};

class LDataType {


Loading…
Cancel
Save