VPI samples installer includes a sample video with noise added artificially, found in /opt/nvidia/vpi-0.3/samples/assets/noisy.mp4.
For convenience, here's the code that is also installed in the samples directory.
#include <opencv2/core/version.hpp>
#if CV_MAJOR_VERSION >= 3
# include <opencv2/imgcodecs.hpp>
# include <opencv2/videoio.hpp>
#else
# include <opencv2/highgui/highgui.hpp>
#endif
#include <opencv2/imgproc/imgproc.hpp>
#include <algorithm>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <vector>
#define CHECK_STATUS(STMT) \
do \
{ \
VPIStatus status = (STMT); \
if (status != VPI_SUCCESS) \
{ \
throw std::runtime_error(vpiStatusGetName(status)); \
} \
} while (0);
static VPIImage ToVPIImage(
const cv::Mat &frame)
{
memset(&imgData, 0, sizeof(imgData));
switch (frame.type())
{
case CV_8U:
break;
case CV_8UC3:
break;
case CV_8UC4:
break;
default:
throw std::runtime_error("Frame type not supported");
}
return img;
};
{
cv::Mat out;
{
break;
break;
break;
default:
throw std::runtime_error("Frame type not supported");
}
return out;
}
int main(int argc, char *argv[])
{
int retval = 0;
try
{
if (argc != 4)
{
throw std::runtime_error(std::string("Usage: ") + argv[0] + " <cpu|pva|cuda> <input_video> <output>");
}
std::string strDevType = argv[1];
std::string strInputVideo = argv[2];
std::string strOutputVideo = argv[3];
cv::VideoCapture invid;
if (!invid.open(strInputVideo))
{
throw std::runtime_error("Can't open '" + strInputVideo + "'");
}
if (strDevType == "cpu")
{
}
else if (strDevType == "cuda")
{
}
else if (strDevType == "pva")
{
}
else
{
throw std::runtime_error("Backend '" + strDevType +
"' not recognized, it must be either cpu, cuda or pva.");
}
{
}
else
{
streamConv = streamTNR;
}
int w = invid.get(cv::CAP_PROP_FRAME_WIDTH);
int h = invid.get(cv::CAP_PROP_FRAME_HEIGHT);
cv::VideoWriter outVideo(strOutputVideo, invid.get(cv::CAP_PROP_FOURCC), invid.get(cv::CAP_PROP_FPS),
cv::Size(w, h));
VPIImage imgPrevious, imgCurrent, imgOutput;
int curFrame = 1;
cv::Mat cvFrame;
while (invid.read(cvFrame))
{
printf("Frame: %d\n", curFrame++);
VPIImage frameBGR = ToVPIImage(cvFrame);
if (streamConv != streamTNR)
{
}
CHECK_STATUS(
if (streamConv != streamTNR)
{
}
outVideo << ToCV(imgdata);
std::swap(imgPrevious, imgOutput);
};
}
catch (std::exception &e)
{
std::cerr << e.what() << std::endl;
retval = 1;
}
return retval;
}