Skip to content

Commit 5a51ba0

Browse files
committed
fix: convert BGR to RGB after resizing
1 parent ef00fd4 commit 5a51ba0

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

packages/react-native-executorch/common/rnexecutorch/data_processing/ImageProcessing.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ std::pair<TensorPtr, cv::Size>
130130
readImageToTensor(const std::string &path,
131131
const std::vector<int32_t> &tensorDim) {
132132
cv::Mat input = imageprocessing::readImage(path);
133-
cv::cvtColor(input, input, cv::COLOR_BGR2RGB);
134133
cv::Size imageSize = input.size();
135134

136135
if (tensorDim.size() < 2) {
@@ -146,6 +145,8 @@ readImageToTensor(const std::string &path,
146145

147146
cv::resize(input, input, tensorSize);
148147

148+
cv::cvtColor(input, input, cv::COLOR_BGR2RGB);
149+
149150
return {imageprocessing::getTensorFromMatrix(tensorDim, input), imageSize};
150151
}
151152
} // namespace imageprocessing

packages/react-native-executorch/common/rnexecutorch/data_processing/ImageProcessing.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ std::vector<float> colorMatToVector(const cv::Mat &mat);
2424
cv::Mat bufferToColorMat(const std::span<const float> &buffer,
2525
cv::Size matSize);
2626
std::string saveToTempFile(const cv::Mat &image);
27+
/// @brief Read image in a BGR format to a cv::Mat
2728
cv::Mat readImage(const std::string &imageURI);
2829
TensorPtr getTensorFromMatrix(const std::vector<int32_t> &tensorDim,
2930
const cv::Mat &mat);

0 commit comments

Comments
 (0)