Std::queue of Mat

Because I’am new to OpenCV, I have another, maybe silly, question: I added a queue of the standard template library to my program, which stores a number of into cv::Mat converted frames. Other methods which do the processing part (reading RGB values, drawing a histogram etc.) should read the frames from this queue for further processing. Is this an acceptable solution?

* Defines a Queue that stores a constant number of frames
std::queue<cv::Mat> ConvertVideoFormat::StoreFrame(cv::Mat frame) {

    std::queue<cv::Mat> frameQueue;

    //store only 1 sec into the queue
    for (int i = 1; i <= 25; ++i) {

    qDebug() << "FrameQueue: " << frameQueue.empty();
    return frameQueue;

cv::Mat ConvertVideoFormat::DeckLinkToCv(CComPtr<IDeckLinkVideoFrame> theFrame) {

    void* data; 
    theFrame->GetBytes(&data); //allows direct access to the data buffer of a video frame

    int frameHeight = theFrame->GetHeight();
    int frameWidth = theFrame->GetWidth();
    m_inputFrame = cv::Mat(frameHeight, frameWidth, CV_8UC2, data, theFrame->GetRowBytes()); //Ctor 11/25
    m_outputFrame = cv::Mat(frameHeight, frameWidth, CV_8UC4);
    cv::cvtColor(m_inputFrame, m_outputFrame, cv::COLOR_YUV2BGR_UYVY);
    m_copyConvFrame = m_outputFrame.clone();    

    return  m_copyConvFrame;

why do you need a queue ? why put 25 times the sme frame into it ?

please dont preallocate output Mat’s. it will be overwritten anyway, and the cvtColor() result will be CV_8UC3, because you said so in the flag

1 Like

Hi @berak,

Maybe a misunderstanding. I thought ConvertVideoFormat::DeckLinkToCv() creates a cv::Mat of every incoming single frame (for example: if the incoming stream has 25 fps, 25 cv::Mat’s are created).
Based on this understanding, my idea was to to create a “manual buffer” that caches the frames. This allows me stop the videostream and anaylize the video, because the video rendering and the conversion process requires lot of CPU power on my system.

1 Like

there is no reason to assume that one second of buffers is required or beneficial, assuming your code is effective in achieving that goal (it is not).

apart from that, your code just discards the function call’s return value (that queue), so it’s all a waste.

decklink doesn’t need these acrobatics nor could it make use of them. just remove the code.

if this code is intended to be read or used by anyone other than yourself (work? college?), get them to review your code thoroughly and ask for honest feedback.

Do you mean the queue is a waste or the format conversion from Decklink to cv::Mat with cvtColor?

I’m saying that function does nothing, so remove it.