ImageProvider.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #include "ImageProvider.h"
  2. #include <QDebug>
  3. ImageProvider::ImageProvider()
  4. : QQuickImageProvider(QQuickImageProvider::Image) {}
  5. QImage ImageProvider::requestImage(const QString &, QSize *,
  6. const QSize &) {
  7. return this->img;
  8. }
  9. QPixmap ImageProvider::requestPixmap(const QString &, QSize *,
  10. const QSize &) {
  11. return QPixmap::fromImage(this->img);
  12. }
  13. ShowImage::ShowImage(QObject *parent, RenderPosition _pos) : QObject(parent) {
  14. campos = _pos;
  15. m_pImgProvider = new ImageProvider();
  16. detector = new YOLOv5Detector(L"C:\\Users\\admin\\Desktop\\Project1\\yolov5s.onnx");
  17. }
  18. void ShowImage::sendFrontImage() {
  19. emit callQmlRefeshFrontImg();
  20. }
  21. void ShowImage::sendBackImage() {
  22. emit callQmlRefeshBackImg();
  23. }
  24. void ShowImage::sendLeftImage() {
  25. // m_pImgProvider->img = image;// .mirrored(true, false);
  26. emit callQmlRefeshLeftImg();
  27. }
  28. void ShowImage::sendRightImage() {
  29. // m_pImgProvider->img = image;//.mirrored(true, false);
  30. emit callQmlRefeshRightImg();
  31. }
  32. void ShowImage::sendLeftAnchor() {
  33. // m_pImgProvider->img = image;
  34. emit callQmlRefeshLeftAnchor();
  35. }
  36. void ShowImage::sendRightAnchor()
  37. {
  38. // m_pImgProvider->img = image;
  39. emit callQmlRefeshRightAnchor();
  40. }
  41. // void ShowImage::sendPanelImage(QImage sendimage) {
  42. // m_pImgProvider->img = sendimage;
  43. // emit callQmlRefeshPanelImg();
  44. //}
  45. void ShowImage::OnRender(std::unique_ptr<uint8_t> &pBuffer, int32_t ,
  46. int32_t ) {
  47. if (pBuffer == nullptr)
  48. {
  49. // m_image.fill(Qt::GlobalColor::transparent);
  50. return;
  51. }
  52. std::lock_guard<std::mutex> l(buffer_lock_);
  53. m_pImgProvider->img = QImage(pBuffer.get(), 1280, 720, QImage::Format_RGB32);
  54. //cv::Mat imgBGR;
  55. //cv::cvtColor(cv::Mat(720, 1280, CV_8UC4, pBuffer.get()), imgBGR, cv::COLOR_RGBA2BGR);
  56. //cv::Mat imgBGR = detector->QImageToMat(m_pImgProvider->img);
  57. //vector<vector<float>> detections = detector->detect(imgBGR);
  58. //detector->draw_boxes(imgBGR, detections);
  59. switch (campos)
  60. {
  61. case RenderPosition::FRONT:
  62. sendFrontImage();
  63. break;
  64. case RenderPosition::LEFT:
  65. sendLeftImage();
  66. break;
  67. case RenderPosition::RIGHT:
  68. sendRightImage();
  69. break;
  70. case RenderPosition::BACK:
  71. sendBackImage();
  72. break;
  73. case RenderPosition::LANCHOR:
  74. sendLeftAnchor();
  75. break;
  76. /* case RenderPosition::RANCHOR:
  77. sendRightAnchor();
  78. break;*/
  79. }
  80. }
  81. void ShowImage::Empty()
  82. {
  83. if (m_pImgProvider != nullptr)
  84. {
  85. //QColor bmpBackA(0, 0, 0, 0);
  86. m_pImgProvider->img = QImage((uint8_t*)NULL, 1280, 720, QImage::Format_RGB32);
  87. switch (campos)
  88. {
  89. case RenderPosition::FRONT:
  90. sendFrontImage();
  91. break;
  92. case RenderPosition::LEFT:
  93. sendLeftImage();
  94. break;
  95. case RenderPosition::RIGHT:
  96. sendRightImage();
  97. break;
  98. case RenderPosition::BACK:
  99. sendBackImage();
  100. break;
  101. case RenderPosition::LANCHOR:
  102. sendLeftAnchor();
  103. break;
  104. /* case RenderPosition::RANCHOR:
  105. sendRightAnchor();
  106. break;*/
  107. }
  108. }
  109. }