-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utils.h
50 lines (34 loc) · 804 Bytes
/
Utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef UTILS_H
#define UTILS_H
#include <opencv.hpp>
#include <atlimage.h>
#include <fstream>
using namespace cv;
bool Mat2CImage(Mat& mat, CImage& img)
{
if (mat.empty()) {
return false;
}
if (!img.IsNull()) {
img.Destroy();
}
int nBPP = mat.channels() * 8;
img.Create(mat.cols, mat.rows, nBPP);
if (nBPP == 8) {
static RGBQUAD pRGB[256];
for (int i = 0; i < 256; i++) {
pRGB[i].rgbBlue = pRGB[i].rgbGreen = pRGB[i].rgbRed = i;
}
img.SetColorTable(0, 256, pRGB);
}
uchar* psrc = mat.data;
uchar* pdst = (uchar*)img.GetBits();
int imgPitch = img.GetPitch();
for (int y = 0; y < mat.rows; y++) {
memcpy(pdst, psrc, mat.cols * mat.channels());
psrc += mat.step;
pdst += imgPitch;
}
return true;
}
#endif