JPery / MJPEGWriter

Lightweight HTTP server to stream your OpenCV processing in C++
MIT License
98 stars 40 forks source link

Screen Tearing Problem #19

Open AdiLakshmy opened 4 years ago

AdiLakshmy commented 4 years ago

First I converted my output QImage to Mat and then I write that converted Mat in MJPEGWriter. I observed screen tearing problem. How can I solve this problem?

AdiLakshmy commented 4 years ago

This is the below code I used for Qimage to Mat conversion

Mat QImageToMat(QImage image)
{
    cv::Mat mat;
    switch (image.format())
    {
    case QImage::Format_ARGB32:
    case QImage::Format_RGB32:
    case QImage::Format_ARGB32_Premultiplied:
        mat = cv::Mat(image.height(), image.width(), CV_8UC4, (void*)image.constBits(), image.bytesPerLine());
        break;
    case QImage::Format_RGB888:
        mat = cv::Mat(image.height(), image.width(), CV_8UC3, (void*)image.constBits(), image.bytesPerLine());
        cv::cvtColor(mat, mat, CV_BGR2RGB);
        break;
    case QImage::Format_Grayscale8:
        mat = cv::Mat(image.height(), image.width(), CV_8UC1, (void*)image.constBits(), image.bytesPerLine());
        break;
    }
    return mat;
}