Plotting received image at QGraphicsView



  • 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;

    }@


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.