如何解决在 GPU 空间中获取 gstreamer VideoCapture 输出
下面是我的代码示例。我要返回 64 个资源。 videoCap [i] .read (frameCurrent [i]);当我说的时候,我将它输出为 Mat 输出并上传到 GpuMat。当有 64 个资源时,性能会下降。在gpu中解码后。我想将输出保留在 gpu 中,而无需在 cpu 和 gpu 之间切换。是否有可能 ?平台:Ubuntu 20.04
pipeline = filesrc location=/home/nmi/Desktop/gag/videos/480x270.mp4 ! qtdemux name=demux demux.video_0 ! h265parse ! nvh265dec ! appsink
void Widget::func_all() {
for(int i=0; i<NUCAMS; i++){
videoCap[i] = VideoCapture(gst_pipe[0],CAP_GSTREAMER);
}
std::time_t timeBegin = std::time(0);
int tick = 0;
long frameCounter = 0;
namedWindow( "Output",cv::WINDOW_OPENGL );
setWindowProperty( "Output",WND_PROP_FULLSCREEN,WINDOW_FULLSCREEN );
while (true)
{
for(int i=0; i<NUCAMS; i++){
videoCap[i].read(frameCurrent[i]);
videoFrames[i].upload(frameCurrent[i]);
videoFrames[i] = videoFrames[i](Rect(0,480,270));
//cuda::resize(videoFrames[i],videoFrames[i],Size(Width,Height),INTER_AREA);
}
Size sizevals = videoFrames[0].size();
int height = sizevals.height;
int width = sizevals.width;
sizevals.height = height * sqrt(NUCAMS);
sizevals.width = width * sqrt(NUCAMS);
GpuMat outval(sizevals,CV_8UC1,Scalar(0));
//printf("types: %d %d\n",videoFrames[0].type(),outval.type());
//cout << in1.size() << endl;
//cout << outval.size() << endl;
int sayac = 0;
for(int n=0; n<sqrt(NUCAMS); n++){
for(int m=0; m<sqrt(NUCAMS); m++)
videoFrames[sayac++].copyTo(outval(Rect((width*m),(height*n),(width),(height))));
}
frameCounter++;
std::time_t timeNow = std::time(0) - timeBegin;
if (timeNow - tick >= 1)
{
tick++;
cout << "Frames per second: " << frameCounter << endl;
frameCounter = 0;
}
imshow( "Output",outval );
if (waitKey(1) == 'q') {
break;
}
}
destroyWindow("Output");
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。