16 std::vector<unsigned char> bytes;
19 uLong sourceLen = uLong(data.total())*uLong(data.elemSize());
20 uLong destLen = compressBound(sourceLen);
21 bytes.resize(destLen);
23 (Bytef *)bytes.data(),
25 (
const Bytef *)data.data,
28 bytes.resize(destLen+3*
sizeof(
int));
29 *((
int*)&bytes[destLen]) = data.rows;
30 *((
int*)&bytes[destLen+
sizeof(
int)]) = data.cols;
31 *((
int*)&bytes[destLen+2*
sizeof(int)]) = data.type();
33 if(errCode == Z_MEM_ERROR)
35 UERROR(
"Z_MEM_ERROR : Insufficient memory.");
37 else if(errCode == Z_BUF_ERROR)
39 UERROR(
"Z_BUF_ERROR : The buffer dest was not large enough to hold the uncompressed data.");
48 if(bytes && size>=3*
sizeof(
int))
51 int height = *((
int*)&bytes[size-3*
sizeof(
int)]);
52 int width = *((
int*)&bytes[size-2*
sizeof(
int)]);
53 int type = *((
int*)&bytes[size-1*
sizeof(
int)]);
55 data = cv::Mat(height, width, type);
56 uLongf totalUncompressed = uLongf(data.total())*uLongf(data.elemSize());
58 int errCode = uncompress(
64 if(errCode == Z_MEM_ERROR)
66 UERROR(
"Z_MEM_ERROR : Insufficient memory.");
68 else if(errCode == Z_BUF_ERROR)
70 UERROR(
"Z_BUF_ERROR : The buffer dest was not large enough to hold the uncompressed data.");
72 else if(errCode == Z_DATA_ERROR)
74 UERROR(
"Z_DATA_ERROR : The compressed data (referenced by source) was corrupted.");
cv::Mat uncompressData(const unsigned char *bytes, unsigned long size)
std::vector< unsigned char > compressData(const cv::Mat &data)
ULogger class and convenient macros.