#include "ImageProvider.h" #include ImageProvider::ImageProvider() : QQuickImageProvider(QQuickImageProvider::Image) {} QImage ImageProvider::requestImage(const QString &, QSize *, const QSize &) { return this->img; } QPixmap ImageProvider::requestPixmap(const QString &, QSize *, const QSize &) { return QPixmap::fromImage(this->img); } ShowImage::ShowImage(QObject *parent, RenderPosition _pos) : QObject(parent) { campos = _pos; m_pImgProvider = new ImageProvider(); detector = new YOLOv5Detector(L"C:\\Users\\admin\\Desktop\\Project1\\yolov5s.onnx"); } void ShowImage::sendFrontImage() { emit callQmlRefeshFrontImg(); } void ShowImage::sendBackImage() { emit callQmlRefeshBackImg(); } void ShowImage::sendLeftImage() { // m_pImgProvider->img = image;// .mirrored(true, false); emit callQmlRefeshLeftImg(); } void ShowImage::sendRightImage() { // m_pImgProvider->img = image;//.mirrored(true, false); emit callQmlRefeshRightImg(); } void ShowImage::sendLeftAnchor() { // m_pImgProvider->img = image; emit callQmlRefeshLeftAnchor(); } void ShowImage::sendRightAnchor() { // m_pImgProvider->img = image; emit callQmlRefeshRightAnchor(); } // void ShowImage::sendPanelImage(QImage sendimage) { // m_pImgProvider->img = sendimage; // emit callQmlRefeshPanelImg(); //} void ShowImage::OnRender(std::unique_ptr &pBuffer, int32_t , int32_t ) { if (pBuffer == nullptr) { // m_image.fill(Qt::GlobalColor::transparent); return; } std::lock_guard l(buffer_lock_); m_pImgProvider->img = QImage(pBuffer.get(), 1280, 720, QImage::Format_RGB32); //cv::Mat imgBGR; //cv::cvtColor(cv::Mat(720, 1280, CV_8UC4, pBuffer.get()), imgBGR, cv::COLOR_RGBA2BGR); //cv::Mat imgBGR = detector->QImageToMat(m_pImgProvider->img); //vector> detections = detector->detect(imgBGR); //detector->draw_boxes(imgBGR, detections); switch (campos) { case RenderPosition::FRONT: sendFrontImage(); break; case RenderPosition::LEFT: sendLeftImage(); break; case RenderPosition::RIGHT: sendRightImage(); break; case RenderPosition::BACK: sendBackImage(); break; case RenderPosition::LANCHOR: sendLeftAnchor(); break; /* case RenderPosition::RANCHOR: sendRightAnchor(); break;*/ } } void ShowImage::Empty() { if (m_pImgProvider != nullptr) { //QColor bmpBackA(0, 0, 0, 0); m_pImgProvider->img = QImage((uint8_t*)NULL, 1280, 720, QImage::Format_RGB32); switch (campos) { case RenderPosition::FRONT: sendFrontImage(); break; case RenderPosition::LEFT: sendLeftImage(); break; case RenderPosition::RIGHT: sendRightImage(); break; case RenderPosition::BACK: sendBackImage(); break; case RenderPosition::LANCHOR: sendLeftAnchor(); break; /* case RenderPosition::RANCHOR: sendRightAnchor(); break;*/ } } }