Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Commit

Permalink
Fix issue with color images and localization
Browse files Browse the repository at this point in the history
This bug leads to an assertion failure when object localization is performed
on color images. This affects scripts where the DataLoader is instantiated
with target_conversion='read_contents'.
  • Loading branch information
anlthms authored and Jennifer Myers committed Jul 7, 2016
1 parent 508c517 commit 426ad0a
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions loader/src/image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ friend class Video;
createRandomAugParams(decodedDatum.size());
transformDecodedImage(decodedDatum, datumBuf, datumLen);
Mat decodedTarget;
decode(encTarget, encTargetLen, &decodedTarget);
// Assume grayscale masks for now.
decodeGrayscale(encTarget, encTargetLen, &decodedTarget);
transformDecodedImage(decodedTarget, targetBuf, targetLen);
}

Expand Down Expand Up @@ -367,13 +368,21 @@ friend class Video;
}

private:
void decodeGrayscale(char* item, int itemSize, Mat* dst) {
Mat image(1, itemSize, CV_8UC1, item);
cv::imdecode(image, CV_LOAD_IMAGE_GRAYSCALE, dst);
}

void decodeColor(char* item, int itemSize, Mat* dst) {
Mat image(1, itemSize, CV_8UC3, item);
cv::imdecode(image, CV_LOAD_IMAGE_COLOR, dst);
}

void decode(char* item, int itemSize, Mat* dst) {
if (_params->_channelCount == 1) {
Mat image(1, itemSize, CV_8UC1, item);
cv::imdecode(image, CV_LOAD_IMAGE_GRAYSCALE, dst);
decodeGrayscale(item, itemSize, dst);
} else if (_params->_channelCount == 3) {
Mat image(1, itemSize, CV_8UC3, item);
cv::imdecode(image, CV_LOAD_IMAGE_COLOR, dst);
decodeColor(item, itemSize, dst);
} else {
stringstream ss;
ss << "Unsupported number of channels in image: " << _params->_channelCount;
Expand Down

0 comments on commit 426ad0a

Please sign in to comment.