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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
#include <iostream>
#include <boost/python.hpp>
#include <omp.h>
#include <opencv4/opencv2/imgproc.hpp>
#include <opencv4/opencv2/opencv.hpp>
#include <boost/python/numpy.hpp>
#include <numpy/arrayobject.h>
using namespace cv;
namespace py = boost::python;
namespace np = boost::python::numpy;
#define WIDTH 2048
#define HEIGHT 2896
void bold_preprocess(PyObject* args, PyObject* res_1)
{
cv::Size newImageSize, source_ImageSize;
Mat img_resized;
Py_Initialize();
import_array();
npy_intp shape [2] = {WIDTH, HEIGHT};
Mat MORPH_RECT_KERNEL = getStructuringElement(MORPH_RECT, Size(6, 6), Point(-1,-1));
Mat MORPH_RECT_KERNEL_H = getStructuringElement(MORPH_RECT, Size(6, 1), Point(-1,-1));
Mat MORPH_RECT_KERNEL_V = getStructuringElement(MORPH_RECT, Size(1, 6), Point(-1,-1));
Mat MORPH_RECT_KERNEL_4 = getStructuringElement(MORPH_RECT, Size(4, 4), Point(-1,-1));
Mat MORPH_RECT_KERNEL_HOR = getStructuringElement(MORPH_RECT, Size(1, 30), Point(-1,-1));
source_ImageSize = cv::Size(static_cast<int>(WIDTH), static_cast<int>(HEIGHT));
newImageSize = cv::Size(static_cast<int>(WIDTH*3), static_cast<int>(HEIGHT*3));
int len = PyList_Size(args);
Mat images[len];
#pragma omp parallel
{
char* x_1 = (char*)malloc(HEIGHT*3*WIDTH*3*8);
Mat* r_1 = (Mat*)malloc(len);
PyArrayObject* tmp;
void* tmp_v;
#pragma omp parallel for
for (int i = 0; i < len; i++) {
images[i] = Mat(Size(WIDTH, HEIGHT), CV_64FC1, PyArray_DATA((PyArrayObject*)PyList_GetItem(args, i)));
new (r_1+1) Mat(Size(WIDTH*3, HEIGHT*3), CV_64FC1, (unsigned char*)(x_1));
resize(images[i], r_1[i], newImageSize, 0, 0);
morphologyEx(r_1[i], r_1[i], MORPH_OPEN, MORPH_RECT_KERNEL, Point(-1,-1), 1);
morphologyEx(r_1[i], r_1[i], MORPH_OPEN, MORPH_RECT_KERNEL_H, Point(-1,-1), 1);
morphologyEx(r_1[i], r_1[i], MORPH_OPEN, MORPH_RECT_KERNEL_V, Point(-1,-1), 1);
dilate(r_1[i], r_1[i], MORPH_RECT_KERNEL_HOR);
tmp = (PyArrayObject*)PyList_GetItem(res_1, i);
tmp_v = PyArray_DATA(tmp);
resize(r_1[i], Mat(Size(WIDTH, HEIGHT), CV_64FC1, (unsigned char*)(tmp_v)), source_ImageSize, 0, 0);
}
}
}
| |