0

I'm doing a little physics experiment where I send numpy arrays to a manufacturer library that is written in C++.

Currently, the code looks as follows:

import ctypes
import numpy as np

is_rgba = ctypes.c_uint(1)

# Load DLL
ctypes.cdll.LoadLibrary("\path_to_dll")
slm_lib = ctypes.CDLL("Blink_C_wrapper")


# Phase is the input array with data type np.uint8 and shape (1920, 1200)
# Here I only print parts of it

phase = [[137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137
  137 137 137 137 137 137 137 137 137 137 137 137]
 [118 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118
  118 118 118 118 118 118 118 118 118 118 118 118]
 [100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100
  100 100 100 100 100 100 100 100 100 100 100 100]
 [ 82  82  82  82  82  82  82  82  82  82  82  82  82  82  82  82  82  82
   82  82  82  82  82  82  82  82  82  82  82  82]
 [ 63  63  63  63  63  63  63  63  63  63  63  63  63  63  63  63  63  63
   63  63  63  63  63  63  63  63  63  63  63  63]
 [ 45  45  45  45  45  45  45  45  45  45  45  45  45  45  45  45  45  45
   45  45  45  45  45  45  45  45  45  45  45  45]
 [ 27  27  27  27  27  27  27  27  27  27  27  27  27  27  27  27  27  27
   27  27  27  27  27  27  27  27  27  27  27  27]
 [  9   9   9   9   9   9   9   9   9   9   9   9   9   9   9   9   9   9
    9   9   9   9   9   9   9   9   9   9   9   9]
 [246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246
  246 246 246 246 246 246 246 246 246 246 246 246]
 [228 228 228 228 228 228 228 228 228 228 228 228 228 228 228 228 228 228
  228 228 228 228 228 228 228 228 228 228 228 228]
 [210 210 210 210 210 210 210 210 210 210 210 210 210 210 210 210 210 210
  210 210 210 210 210 210 210 210 210 210 210 210]
 [191 191 191 191 191 191 191 191 191 191 191 191 191 191 191 191 191 191
  191 191 191 191 191 191 191 191 191 191 191 191]
 [173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173
  173 173 173 173 173 173 173 173 173 173 173 173]
 [155 155 155 155 155 155 155 155 155 155 155 155 155 155 155 155 155 155
  155 155 155 155 155 155 155 155 155 155 155 155]
 [137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137
  137 137 137 137 137 137 137 137 137 137 137 137]
 [118 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118
  118 118 118 118 118 118 118 118 118 118 118 118]
 [100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100
  100 100 100 100 100 100 100 100 100 100 100 100]
 [ 82  82  82  82  82  82  82  82  82  82  82  82  82  82  82  82  82  82
   82  82  82  82  82  82  82  82  82  82  82  82]
 [ 63  63  63  63  63  63  63  63  63  63  63  63  63  63  63  63  63  63
   63  63  63  63  63  63  63  63  63  63  63  63]
 [ 45  45  45  45  45  45  45  45  45  45  45  45  45  45  45  45  45  45
   45  45  45  45  45  45  45  45  45  45  45  45]
 [ 27  27  27  27  27  27  27  27  27  27  27  27  27  27  27  27  27  27
   27  27  27  27  27  27  27  27  27  27  27  27]
 [  9   9   9   9   9   9   9   9   9   9   9   9   9   9   9   9   9   9
    9   9   9   9   9   9   9   9   9   9   9   9]
 [246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246
  246 246 246 246 246 246 246 246 246 246 246 246]
 [228 228 228 228 228 228 228 228 228 228 228 228 228 228 228 228 228 228
  228 228 228 228 228 228 228 228 228 228 228 228]
 [210 210 210 210 210 210 210 210 210 210 210 210 210 210 210 210 210 210
  210 210 210 210 210 210 210 210 210 210 210 210]
 [191 191 191 191 191 191 191 191 191 191 191 191 191 191 191 191 191 191
  191 191 191 191 191 191 191 191 191 191 191 191]
 [173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173
  173 173 173 173 173 173 173 173 173 173 173 173]
 [155 155 155 155 155 155 155 155 155 155 155 155 155 155 155 155 155 155
  155 155 155 155 155 155 155 155 155 155 155 155]
 [137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137
  137 137 137 137 137 137 137 137 137 137 137 137]
 [118 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118
  118 118 118 118 118 118 118 118 118 118 118 118]
 [100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100
  100 100 100 100 100 100 100 100 100 100 100 100]
 [ 82  82  82  82  82  82  82  82  82  82  82  82  82  82  82  82  82  82
   82  82  82  82  82  82  82  82  82  82  82  82]
 [ 63  63  63  63  63  63  63  63  63  63  63  63  63  63  63  63  63  63
   63  63  63  63  63  63  63  63  63  63  63  63]
 [ 45  45  45  45  45  45  45  45  45  45  45  45  45  45  45  45  45  45
   45  45  45  45  45  45  45  45  45  45  45  45]
 [ 27  27  27  27  27  27  27  27  27  27  27  27  27  27  27  27  27  27
   27  27  27  27  27  27  27  27  27  27  27  27]
 [  9   9   9   9   9   9   9   9   9   9   9   9   9   9   9   9   9   9
    9   9   9   9   9   9   9   9   9   9   9   9]
 [246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246 246
  246 246 246 246 246 246 246 246 246 246 246 246]
 [228 228 228 228 228 228 228 228 228 228 228 228 228 228 228 228 228 228
  228 228 228 228 228 228 228 228 228 228 228 228]
 [210 210 210 210 210 210 210 210 210 210 210 210 210 210 210 210 210 210
  210 210 210 210 210 210 210 210 210 210 210 210]
 [191 191 191 191 191 191 191 191 191 191 191 191 191 191 191 191 191 191
  191 191 191 191 191 191 191 191 191 191 191 191]
 [173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173 173
  173 173 173 173 173 173 173 173 173 173 173 173]
 [155 155 155 155 155 155 155 155 155 155 155 155 155 155 155 155 155 155
  155 155 155 155 155 155 155 155 155 155 155 155]
 [137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137
  137 137 137 137 137 137 137 137 137 137 137 137]
 [118 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118 118
  118 118 118 118 118 118 118 118 118 118 118 118]
 [100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100
  100 100 100 100 100 100 100 100 100 100 100 100]
 [ 82  82  82  82  82  82  82  82  82  82  82  82  82  82  82  82  82  82
   82  82  82  82  82  82  82  82  82  82  82  82]
 [ 63  63  63  63  63  63  63  63  63  63  63  63  63  63  63  63  63  63
   63  63  63  63  63  63  63  63  63  63  63  63]
 [ 45  45  45  45  45  45  45  45  45  45  45  45  45  45  45  45  45  45
   45  45  45  45  45  45  45  45  45  45  45  45]
 [ 27  27  27  27  27  27  27  27  27  27  27  27  27  27  27  27  27  27
   27  27  27  27  27  27  27  27  27  27  27  27]
 [  9   9   9   9   9   9   9   9   9   9   9   9   9   9   9   9   9   9
    9   9   9   9   9   9   9   9   9   9   9   9]]

# Write to SLM
matrix = phase.ravel()
c = matrix.ctypes.data_as(ctypes.POINTER(ctypes.c_uint8))


success = slm_lib.Write_image(c, is_rgba)

I do not have access to Write_image. The header is

BLINK_C_WRAPPER_API int Write_image(unsigned char* image_data, int is_8_bit);

From what I record in the experiment, it seems as if there is a flip along the horizontal axis, i.e. what actually gets written to my machine is np.flip(phase, axis=0). I know that Python is row-major and so is C++, so it shouldn't be the case.

My question is:

  • Is my use of ctpyes correct?
  • Is it possible that somewhere in this code snippet a flip happens?
3

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.