0

i'm starting integrating Opencv in a qt application, so i have a the follwing program structure:

QGraphicsView
    |
    |->QGraphicsPixmapItem (where the captured Image will be)
               |
               |
               |->QGraphicsRectItem (a rectangle that define the roi)

i have the follwing function to process an image:

void Inspection::Process()
{

   IplImage* m_CapureImage= Capture()->GetImage(); //cvLoadImage("e:\\Desert.jpg");


   IplImage* m_ProcessingImage= cvCreateImage(cvGetSize(m_CapureImage), IPL_DEPTH_8U, 1);

    cvCvtColor(m_CapureImage,m_ProcessingImage,CV_BGR2GRAY);


   // Process all ROI's in inspection    
    for (int var = 0; var < ROIs()->rowCount(QModelIndex()); ++var) {
        ROI* roi=ROIs()->data(ROIs()->index(var,0),Qt::UserRole).value<ROI*>();
        if(roi!=0)
            roi->Process(m_ProcessingImage);
    }
    QImage qImg = IplImage2QImage(m_ProcessingImage);
    m_BackgroundItem->setPixmap(QPixmap::fromImage(qImg));
}

/// 

    QImage IplImage2QImage(const IplImage *iplImage)
    {
        int height = iplImage->height;
        int width = iplImage->width;

        if  (iplImage->depth == IPL_DEPTH_8U && iplImage->nChannels == 3)
        {
            const uchar *qImageBuffer = (const uchar*)iplImage->imageData;
            QImage img(qImageBuffer, width, height, QImage::Format_RGB888);
            return img.rgbSwapped();
        } else if  (iplImage->depth == IPL_DEPTH_8U && iplImage->nChannels == 1){
            const uchar *qImageBuffer = (const uchar*)iplImage->imageData;
            QImage img(qImageBuffer, width, height, QImage::Format_Indexed8);

            QVector<QRgb> colorTable;
            for (int i = 0; i < 256; i++){
                colorTable.push_back(qRgb(i, i, i));
            }
            img.setColorTable(colorTable);
            return img;
        }else{
            qWarning() << "Image cannot be converted.";
            return QImage();
        }
    }

So, my question is: i change the position of the roi and do some changes in a region of iplImage, what i'm doing now is call again:

QImage qImg = IplImage2QImage(m_ProcessingImage);
m_BackgroundItem->setPixmap(QPixmap::fromImage(qImg));

so i will load again all the iplImage. Is there a way to only update the specific ROI of iplImage in the pixmap?

Thanks

EDIT 1:

I changed image display implementation, so now the QGraphicsPixmapItem will only display the original captured image, then i will create a custom QGraphicsRectItem and override the paint method to draw the processed ROI

Rui Sebastião
  • 855
  • 1
  • 18
  • 36
  • As far as I know you have to change the IplImage(in your case) and convert it each time. There are not functions for doing much image processing on a pixmap in Qt. By the way, what version of OpenCV do you use? Why do you use IplImages? – Øystein W. Aug 12 '14 at 14:32
  • My opencv version is 2.49, i'm using opencv for a long time. i know that iplimage is "deprecated" i will change to cv::mat – Rui Sebastião Aug 12 '14 at 15:45

0 Answers0