pythonusbcam.py 812 B

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