pythonreadpic.py 665 B

12345678910111213141516171819202122232425262728293031323334
  1. import ctypes
  2. import time
  3. import cv2 as cv
  4. import numpy as np
  5. mylib = ctypes.cdll.LoadLibrary("./libtestpythoncpp.so")
  6. char_arr100 = ctypes.c_char*10000000
  7. y = char_arr100()
  8. def showpic():
  9. str="hello"
  10. i = 0;
  11. mylib.registelisten("usbpic");
  12. nlenx = ctypes.c_int*2
  13. nlen = nlenx()
  14. while i< 10000:
  15. nRtn = mylib.GetData(y,nlen);
  16. if(nRtn>0):
  17. xdata = np.frombuffer(y,count = nlen[0])
  18. matx = cv.imdecode(xdata, cv.IMREAD_COLOR );
  19. cv.imshow("showing",matx)
  20. cv.waitKey(1)
  21. print(nRtn)
  22. time.sleep(0.001);
  23. str="exit"
  24. print(str);
  25. if __name__ == "__main__":
  26. print ('This is main ,for show pic from c++')
  27. showpic()