Qt

Threads with Qt : QThread

good + short intro by Maya Posch how to use threads with Qt

converting a cv::Mat to QImage

static QImage Mat2QImage(cv::Mat& img)
{    
    //QImage qimg = QImage((const unsigned char*)(img.data),img.cols, img.rows, QImage::Format_RGB888);   // wrong!
    QImage qimg = QImage((const unsigned char*)(img.data),img.cols, img.rows, img.step, QImage::Format_RGB888); // correct!
 
    return qimg;
}

see here

How to prepare the Qt SDK to be used in Visual Studio 2010

When you download the Qt SDK (e.g. 4.7.4) and you want to use it with Visual Studio 2010, you will get the following error message when you try to add this new Qt version to the list of Qt versions in Visual Studio 2010:

The problem is, that the Qt SDK version is build only for Visual Studio 2008.

The solution is therefore to download the Qt sources and build it by your own for Visual Studio 2010:

  1. download the qt-everywhere-opensource-src-4.7.4.zip (Qt SDK 4.7.4 source code)
  2. extract the qt-everywhere-opensource-src-4.7.4.zip file in your download folder <DownloadFolder>
  3. start Visual Studio 2010 command prompt (for 64bit compiling, call the 64bit Visual Studio command line shell). Another hint for 64bit compiling.
  4. change to <DownloadFolder> and type configure -platform win32-msvc2010 (note: the configure.exe is already there if you extract the .zip file). See also this list of possible configure options.
  5. drink a coffee … (~ 15 min)
  6. type nmake
  7. drink a pot of coffee … (~ 2-3 hours)
  8. after compilation has finished, start VS 2010 and add the new Qt version ('4.7.4', <DownloadFolder>) via Qt → Qt Options → Add
  9. if you do not have a Qt menu in VS 2010, you probably do not have installed the Qt Visual Studio Add-in

The whole procedure is also described here.

Fast conversion: OpenCV IplImage <-> Qt QImage

This is a standard question of programmer that use OpenCV and Qt. I found two code snippets to do the conversion in both directions in this 2 page pdf document.

Here is what I use for the conversion IplImage → QImage:

static QImage* IplImage2QImage(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;   // get pointer to the data buffer of the IplImage
        QImage img(qImageBuffer, width, height, QImage::Format_RGB888);  // create a QImage using the data buffer from the IplImage ...
        QImage* converted = new QImage( img.rgbSwapped() );              // get a rgb channel swapped copy of the original image
        return converted;
    }
    else
        Logger::Access()->Log( "IplImage2QImage conversion error" );
 
 
    return NULL;
}

Here is what I use for the conversion: QImage → IplImage (gray-scale):

static IplImage* QImage2IplImage(QImage* qImage)
{
    int width = qImage->width();
    int height = qImage->height();
    CvSize Size;
    Size.height = height;
    Size.width = width;
    IplImage *charIplImageBuffer = cvCreateImage(Size, IPL_DEPTH_8U, 1);
    char *charTemp = (char *) charIplImageBuffer->imageData;
    for (int y = 0; y < height; y++)
    {
        for (int x = 0; x < width; x++)
        {
            int index = y * width + x;
            charTemp[index] = (char) qGray(qImage->pixel(x, y));
        }
    }
 
    return charIplImageBuffer;
}

How to change colors of a QWidget?

How to call an external tool from Qt C++ code?

example that converts img.jpg to img.png:

#include <qprocess.h>
 
...
 
QString program = "C:\\Program Files\\ImageMagick\\convert.exe";
QStringList arguments;
arguments << "img.jpg" << "img.png"; 
QProcess *myProcess = new QProcess();
myProcess->start(program, arguments);
 
public/qt.txt · Last modified: 2012/12/05 16:13 (external edit) · []
Recent changes RSS feed Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki