-
Notifications
You must be signed in to change notification settings - Fork 6
/
AlgorithmsCpp.cpp
40 lines (32 loc) · 902 Bytes
/
AlgorithmsCpp.cpp
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
#include "stdafx.h"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <Windows.h>
using namespace cv;
using namespace std;
#define DllExport extern "C" __declspec(dllexport)
struct ImageInfo
{
unsigned char *data;
int size;
};
//release memory
DllExport bool ReleaseMemoryFromC(unsigned char* buf)
{
if (buf == NULL)
return false;
free(buf);
return true;
}
DllExport void convertToGray(unsigned char* data, int dataLen, ImageInfo & imInfo)
{
vector<unsigned char> inputImageBytes(data, data + dataLen);
Mat image = imdecode(inputImageBytes, CV_LOAD_IMAGE_COLOR);
Mat processed;
cvtColor(image, processed, CV_BGR2GRAY);
vector<unsigned char> bytes;
imencode(".png", processed, bytes);
imInfo.size = bytes.size();
imInfo.data = (unsigned char *)calloc(imInfo.size, sizeof(unsigned char));
std::copy(bytes.begin(), bytes.end(), imInfo.data);
}