How to speed OpenCV createMergeMertens function?

asked 2019-12-04 21:57:51 -0500

I fusion multiexposure image from videostream in thread (pthread):

      vector<Mat> images;

        images.push_back(cv::Mat(displayContext->imageLowExposure->height(),displayContext->imageLowExposure->width(),
                                 CV_8UC1,displayContext->imageLowExposure->bits(),displayContext->imageLowExposure->bytesPerLine()));
        images.push_back(cv::Mat(displayContext->imageMediumExposure->height(),displayContext->imageMediumExposure->width(),
                                 CV_8UC1,displayContext->imageMediumExposure->bits(),displayContext->imageMediumExposure->bytesPerLine()));
        images.push_back(cv::Mat(displayContext->imageHighExposure->height(),displayContext->imageHighExposure->width(),
                                 CV_8UC1,displayContext->imageHighExposure->bits(),displayContext->imageHighExposure->bytesPerLine()));

        Mat exposureFusion;
        Ptr<MergeMertens> mergeMertens = createMergeMertens();
        mergeMertens->process(images, exposureFusion);

        Mat convert;
        exposureFusion.convertTo(convert,CV_8UC1,255);

        QImage temp (convert.data, convert.cols, convert.rows, convert.step, QImage::Format_Grayscale8);

        for (int i = 0; i < displayContext->height; ++i){
            memcpy(displayContext->resultImage->scanLine(i),temp.scanLine(i),size_t(displayContext->resultImage->width()));
        }

This code give good result, resultImage have a good quality. But in the end the video speed is reduced to 5 fps.If comment createMergeMertens() function, video speed is normal - 30 fps. How to speed OpenCV createMergeMertens function? At runtime in htop app only one core 100%, other core not above 30%. How to load all CPU cores? Maybe i can use GPU on my video card NVIDIA 1060? My system - UBUNTU 19.04, QT 5.12.6, Intel® Core™ i3-2120 CPU @ 3.30GHz × 4,OpenCV 4.

edit retag flag offensive close merge delete