Skip to content

Instantly share code, notes, and snippets.

@wlei2018
Created April 24, 2018 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wlei2018/ff5cb5f9e070431d8c92c0b91d9d7811 to your computer and use it in GitHub Desktop.
Save wlei2018/ff5cb5f9e070431d8c92c0b91d9d7811 to your computer and use it in GitHub Desktop.
python update memory snippet
import myLib
import cv2
import numpy as np imgPtr = myLib.GetImgBuffer(img1, cols1, rows1)
numpy_array = np.frombuffer(imgPtr, dtype=np.uint8)
numpy_array.shape = (rows1, cols1)
//assume: rows1 = cols1 = 1024
//change the image in python
dst = np.ones((1024,1024), dtype=np.uint8)
//update data in the buffer
np.copyto(numpy_array, dst) //IS THIS CORRECT FOR UPDATING THE MEMORY IN THE BUFFER??
numpy_array.shape = dst.shape
//create another numpy array from the updated buffer
numpy_array2 = np.frombuffer(imgPtr, dtype=np.uint8)
numpy_array2.shape = numpy_array.shape // this array display the correct change but when we pick up
//the change in c++, only ~ quarter of the image is changed)
cv2.imshow('img - retrieve image from updated buffer & display in Python', numpy_array2)
cv2.waitKey(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment