简体   繁体   English

c++ queue.front(); 为什么不从第一个元素开始呢?

[英]c++ queue.front (); why not start from the first element?

I want to create a buffer.我想创建一个缓冲区。 There are 4 streams.有4条流。 When each one fills 300 frames, I want to show it starting from the first element of all queues.当每个填充 300 帧时,我想从所有队列的第一个元素开始显示它。 But it all starts from the 301st frame.但这一切都从第 301 帧开始。 I cannot access the 300 Frame that I filled at the beginning.Another problem although i upload the queue with different data, .front() and back() operations on the queue returns the same data我无法访问我在开始时填充的 300 帧。另一个问题虽然我上传了不同数据的队列,队列上的 .front() 和 back() 操作返回相同的数据

Mat checkdata;
cv::subtract(frameQueue9001.back(), frameQueue9001.front(), checkdata, noArray(), -1);
printf("sthg  goes on: %f\n",cv::norm(checkdata, NORM_L2, noArray()));

Resault: 0结果:0

I will be grateful if you could help me.如果你能帮助我,我将不胜感激。

Best regards.最好的祝福。

I shared the code below for a single stream example我在下面分享了一个 stream 示例的代码

#include "highgui.hpp"
#include "videoio.hpp"
#include "imgproc.hpp"
#include <opencv2/core/cuda.hpp>
#include <iostream>
#include <string.h>
#include <queue>
#include <opencv2/core.hpp>

#define quelen 300

using namespace cv;
using namespace std;

queue<Mat> frameQueue9001;


int main(int argc, char** argv)
{

    namedWindow("1", WINDOW_OPENGL);
    namedWindow("1");
    resizeWindow("1", 960, 510);
    moveWindow("1", 0, 0);


    string gst_pipe1 = "udpsrc port=9001 caps = application/x-rtp ! rtph264depay ! h264parse ! nvh264dec ! videoconvert ! appsink sync=false";

    VideoCapture cap1(gst_pipe1, CAP_GSTREAMER);

    Mat frame1;

    while (true) {

        cap1 >> frame1;
        frameQueue9001.push(frame1);   

        if(frameQueue9001.size() > quelen){ 

            imshow("1", frameQueue9001.front()); 

            frameQueue9001.pop();

        }
        //if (frame.empty())
        //    break;

        if (waitKey(1) == 'r')
            break;
    }
    destroyWindow("1");
}

Not sure if I understood the question correctly.不确定我是否正确理解了这个问题。 With your condition:结合你的情况:

if(frameQueue9001.size() > quelen)

You perform actions when your queue has 301 frames.当您的队列有 301 帧时,您执行操作。 If you want the action with 300 frames, you need to correct that to an equals or greater equals condition.如果您想要 300 帧的动作,则需要将其更正为等于或更大的等于条件。

With that correction, the 300th element can be accessed with通过该更正,可以访问第 300 个元素

imshow("300", frameQueue9001.back()); 

Your query method of the first element seems correct to me.您对第一个元素的查询方法对我来说似乎是正确的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM