daily pastebin goal
52%
SHARE
TWEET

Untitled

a guest Feb 20th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. image = cv.imread("someimage.jpg", 1)
  2. dims = image.shape
  3. image = image.ravel()
  4. cppextenionmodule.np_to_mat(dims, image)
  5.      
  6. static PyObject *np_to_mat(PyObject *self, PyObject *args){
  7.     PyObject *size;
  8.     PyArrayObject *image;
  9.  
  10.     if (!PyArg_ParseTuple(args, "O!O!", &PyTuple_Type, &size, &PyArray_Type, &image)) {
  11.         return NULL;
  12.     }
  13.     int rows = PyLong_AsLong(PyTuple_GetItem(size ,0));
  14.     int cols = PyLong_AsLong(PyTuple_GetItem(size ,1));
  15.     int nchannels = PyLong_AsLong(PyTuple_GetItem(size ,2));
  16.     char my_arr[rows * nchannels * cols];
  17.  
  18.     for(size_t length = 0; length<(rows * nchannels * cols); length++){
  19.         my_arr[length] = (*(char *)PyArray_GETPTR1(image, length));
  20.     }
  21.  
  22.     cv::Mat my_img = cv::Mat(cv::Size(cols, rows), CV_8UC3, &my_arr);
  23.  
  24.     ...
  25. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top