V4l2Capture.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* ---------------------------------------------------------------------------
  2. ** This software is in the public domain, furnished "as is", without technical
  3. ** support, and with no warranty, express or implied, as to its usefulness for
  4. ** any purpose.
  5. **
  6. ** V4l2Capture.h
  7. **
  8. ** V4L2 Capture wrapper
  9. **
  10. ** -------------------------------------------------------------------------*/
  11. #ifndef V4L2_CAPTURE
  12. #define V4L2_CAPTURE
  13. #include "V4l2Access.h"
  14. #include "opencv2/core/core.hpp"
  15. // ---------------------------------
  16. // V4L2 Capture
  17. // ---------------------------------
  18. class V4l2Capture : public V4l2Access
  19. {
  20. protected:
  21. V4l2Capture(V4l2Device* device);
  22. public:
  23. /**
  24. * @brief create 创建Capture
  25. * @param param
  26. *使用说明,我们读取UVC免驱的摄像头时,应该避免直接使用opencv的videocpature,
  27. * 因为简单的API使得我们并不知道我们到底获取的时摄像头的哪种图片格式。应该直接使用Qt v4l2 test benchmark软件去获取我们真正需要的
  28. * 图像帧格式。
  29. * V4L2_PIX_FMT_MJPEG (MJPEG)
  30. 使用范例 V4L2DeviceParameters param("/dev/video0", V4L2_PIX_FMT_MJPEG , 1920, 1080, 30, 0,verbose);
  31. * @param iotype
  32. * @return
  33. */
  34. static V4l2Capture* create(const V4L2DeviceParameters & param, IoType iotype = V4l2Access::IOTYPE_MMAP);
  35. virtual ~V4l2Capture();
  36. size_t read(char* buffer, size_t bufferSize);
  37. /**
  38. * @brief read 读取图像
  39. * @param readImage 获取的图像
  40. * @return
  41. */
  42. int read(cv::Mat &readImage);
  43. /**
  44. * @brief isReadable 判断是都可读取图像
  45. * @param tv 等待的时间
  46. * timeval tv;
  47. tv.tv_sec=1;
  48. tv.tv_usec=0;
  49. int ret = this->isReadable(&tv);
  50. *
  51. * @return -1 不可读 0 超时 1 成功
  52. */
  53. int isReadable(timeval* tv);
  54. /**
  55. * @brief getBusInfo 获取总线的地址,多个摄像头输入设备时便于判断我们现在采集的到底是哪个摄像头
  56. * @return
  57. */
  58. const char * getBusInfo();
  59. };
  60. #endif