//////////////////////////////////////////////////////////////////////////////// /** * \file layercomposer.cpp * \version v1.0 * \author Ing. Dominik Malcik */ //////////////////////////////////////////////////////////////////////////////// #include "layercomposer.h" #include LayerComposer::LayerComposer(QWidget *parent) : QMainWindow(parent) { } QImage LayerComposer::composeLayers (std::vector importedLayers, std::vector analysingLayers, std::vector importedIndexes, std::vector analysingIndexes, QString &bgRootDir, QString &overLayRootDir) { QString bgImgFileName; for (unsigned int i = 0; i < importedIndexes.size(); i++) { bgImgFileName = importedLayers[importedIndexes[i]]; } bgImgFileName = bgRootDir + bgImgFileName; // final image // size is taken from the background bitmap QImage bgImage(bgImgFileName); QImage resultImage = QImage(bgImage.width(), bgImage.height(), QImage::Format_ARGB32_Premultiplied); QPainter painter(&resultImage); // draw background painter.setCompositionMode(QPainter::CompositionMode_Source); painter.fillRect(resultImage.rect(), Qt::transparent); painter.setCompositionMode(QPainter::CompositionMode_SourceOver); painter.drawImage(0, 0, bgImage); // ---------------------- QString overlayFileName; QString srcAddr = overLayRootDir; for (unsigned int i = 0; i < analysingIndexes.size(); i++) { overlayFileName = srcAddr + analysingLayers[analysingIndexes[i]]; // mask black colour QPixmap mypixmap(overlayFileName); mypixmap.setMask(mypixmap.createMaskFromColor(Qt::black)); // draw given image painter.setCompositionMode(QPainter::CompositionMode_SourceOver); painter.drawPixmap(0, 0, mypixmap); } painter.end(); return resultImage; } QImage LayerComposer::maskSelectedLayer(QString &bgImageFileName, QString &bgRootDir, QRgb maskColor, int rThrsh, int gThrsh, int bThrsh ) { QImage image(bgRootDir + bgImageFileName); OpenCVprocessor * cvProcessor = new OpenCVprocessor(); image = cvProcessor->normalizeImage(&image, qRed(maskColor), qGreen(maskColor), qBlue(maskColor), rThrsh, gThrsh, bThrsh); QPixmap maskPixmap = QPixmap::fromImage(image); QPixmap myPixmap(bgRootDir + bgImageFileName); QImage resultImage = QImage(myPixmap.width(), myPixmap.height(), QImage::Format_ARGB32_Premultiplied); QPainter painter(&resultImage); // draw background - black painter.setCompositionMode(QPainter::CompositionMode_Source); painter.fillRect(resultImage.rect(), Qt::black); // draw background masked from OpenCV myPixmap.setMask(maskPixmap.createMaskFromColor(Qt::black)); painter.setCompositionMode(QPainter::CompositionMode_SourceOver); painter.drawPixmap(0, 0, myPixmap); painter.end(); return resultImage; }