I can use VideoReader class of OpenCV to decode an IP camera stream or any video file by using its path. This decoding process is using GPU as expected, no problem up to now. Here is simple code which is working fine and using GPU for decoding:
int main()
{
const std::string fname("rtsp://user:pwd@192.168.1.108");
// const std::string fname("/path/to/video/file.mp4"); // this also works
cv::cuda::GpuMat d_frame;
cv::Ptr<cv::cudacodec::VideoReader> d_reader = cv::cudacodec::createVideoReader(fname);
Mat frame;
for (;;)
{
if (!d_reader->nextFrame(d_frame))
break;
Mat myMat(d_frame);
cv::imshow("GPU", myMat);
if (cv::waitKey(3) > 0)
break;
}
return 0;
}
I want to use GPU to capture streams from my webcam as like VideoCapture(0). I know as @berak mentioned here : There is no way to do that with VideoCapture
My questions are:
1 - Is it possible to stream by using GPU with VideoReader class? Because VideoReader class only accepts strings not indexes.
2- What are the other ways to be able to stream by using GPU?