I get a buffer from a function in a library. It should be an image buffer. I use OpenCV's function cv::imdecode(...)
to transform it in a cv::Mat
. Sometimes the image is removed before I get the buffer, so in that case I expected that the buffer is empty, but I just found that it contains an .xml
, containing some kind of message that the image is not found. So: Is there a way to verify that the buffer contains an .xml
and not a .jpg
? Or how to verify this?
EDIT:
Based on the comment I want to search if the buffer begins with "<?xml"
.
imgOut = cv::imdecode(imgBuf, CV_LOAD_IMAGE_COLOR);
if (imgOut.empty())
{
std::string xmlStart = "<?xml";
std::string bufStart(imgBuf.begin(), imgBuf.begin() + 5);
if (bufStart == xmlStart)
{
throw ImageNotAvailableException()
}
throw ImageDecodeException(bucketNameIn, objectNameIn);
}
cv::imdecode
is returning an empty cv::Mat
if the decode fails. Is it OK to do it like this (imgBuf
is a std::vector< uchar >
)?