MCPcopy Create free account
hub / github.com/OAID/Tengine / ReadImageFile

Function ReadImageFile

examples/tensorflow_wrapper/label_image/label_image.cpp:57–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55}
56
57static float* ReadImageFile(const char* image_file, cv::Mat& img, const int input_height, const int input_width,
58 const float input_mean, const float input_std)
59{
60 // Read image
61 cv::Mat frame = cv::imread(image_file);
62 if(!frame.data)
63 {
64 cout << image_file << " does not exist" << endl;
65 return nullptr;
66 }
67
68 // Convert BGR to RGB
69 cv::cvtColor(frame, frame, cv::COLOR_BGR2RGB);
70
71 // Resize the image
72 cv::Mat img_resized;
73 cv::Size input_geometry = cv::Size(input_width, input_height);
74 cv::resize(frame, img_resized, input_geometry);
75
76 // Convert to float 32, channel 3
77 img_resized.convertTo(img_resized, CV_32FC3);
78
79 // Normalization
80 img = (img_resized - input_mean) / input_std;
81
82 std::vector<cv::Mat> input_channels;
83 float* input_data = ( float* )std::malloc(input_height * input_width * 3 * 4);
84
85 memcpy(input_data, img.data, input_height * input_width * sizeof(float) * 3);
86
87 return input_data;
88}
89
90static int ReadLabelsFile(const char* labels_file, vector<string>* result)
91{

Callers 1

mainFunction · 0.70

Calls 1

imreadFunction · 0.85

Tested by

no test coverage detected