[英]c++ queue.front (); why not start from the first element?
我想創建一個緩沖區。 有4條流。 當每個填充 300 幀時,我想從所有隊列的第一個元素開始顯示它。 但這一切都從第 301 幀開始。 我無法訪問我在開始時填充的 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()));
結果:0
如果你能幫助我,我將不勝感激。
最好的祝福。
我在下面分享了一個 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");
}
不確定我是否正確理解了這個問題。 結合你的情況:
if(frameQueue9001.size() > quelen)
當您的隊列有 301 幀時,您執行操作。 如果您想要 300 幀的動作,則需要將其更正為等於或更大的等於條件。
通過該更正,可以訪問第 300 個元素
imshow("300", frameQueue9001.back());
您對第一個元素的查詢方法對我來說似乎是正確的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.