Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Plotting received image at QGraphicsView

Plotting received image at QGraphicsView

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 2.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    thomas11live.com.sg
    wrote on last edited by
    #1

    Dear All,
    I am trying to plot the image received from a camera.
    The camera image is in Opencv format and converted to Qimage format and I display in QGraphicsView. But I don't know why the image is not displayed at the window.

    @MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {

    ui->setupUi(this);
    
    cameraisConnected = false;
    imageCaptureThreadStarted = false;
    //UI implementation
    
    //View initialization
    ui_Implementation(ui);
    scene = new QGraphicsScene(view);
    scene2 = new QGraphicsScene(view2);
    pixmaItem = new QGraphicsPixmapItem();
    pixmaItem2 = new QGraphicsPixmapItem();
    
    scene->addItem(pixmaItem);
    view->setScene(scene);
    scene->setSceneRect(0,0,300,200);
    view->setRenderHints(QPainter::Antialiasing);
    imageshown = false;
    

    // plot();
    }@

    @void MainWindow::newImageReceivedInformed(imageData receiveImage)
    {
    opencvimageData_t opcvImage;
    QPixmap pixma;
    int col = receiveImage.imageframe.GetCols();// captured image's column
    int row = receiveImage.imageframe.GetRows();// captured image's row
    int data_size = receiveImage.imageframe.GetDataSize();//captured image's data size
    QImage qImg = QImage(col, row, QImage::Format_RGB32);
    opcvImage.opencvimageframe = cvCreateImage(cvSize(col, row), IPL_DEPTH_8U, 1);//3 channels for RGB
    memcpy(opcvImage.opencvimageframe->imageData, receiveImage.imageframe.GetData(), data_size);
    opcvImage.imgnumber = receiveImage.snr;
    capturedImageQueue.setQueue(opcvImage);
    IplImage2QImage(opcvImage.opencvimageframe, qImg);
    pixma = QPixmap::fromImage(qImg);
    pixmaItem->setPixmap(pixma);
    view->show();
    }@

    @void MainWindow::IplImage2QImage(IplImage *iplImg, QImage &qimg)
    {
    int h = iplImg->height;
    int w = iplImg->width;
    int channels = iplImg->nChannels;
    char *data = iplImg->imageData;
    for (int y = 0; y < h; y++, data += iplImg->widthStep)
    {
    for (int x = 0; x < w; x++)
    {
    char r, g, b, a = 0;
    if (channels == 1)
    {
    r = data[x * channels];
    g = data[x * channels];
    b = data[x * channels];
    }
    else if (channels == 3 || channels == 4)
    {
    r = data[x * channels + 2];
    g = data[x * channels + 1];
    b = data[x * channels];
    }

       if (channels == 4)
       {
          a = data[x * channels + 3];
          qimg.setPixel(x, y, qRgba(r, g, b, a));
       }
       else
       {
           qimg.setPixel(x, y, qRgb(r, g, b));
       }
      }
    

    }
    return;

    }@

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved