29 #include <opencv2/core/version.hpp>
30 #if CV_MAJOR_VERSION >= 3
31 # include <opencv2/imgcodecs.hpp>
32 # include <opencv2/videoio.hpp>
34 # include <opencv2/highgui/highgui.hpp>
37 #include <opencv2/imgproc/imgproc.hpp>
54 #define CHECK_STATUS(STMT) \
57 VPIStatus status = (STMT); \
58 if (status != VPI_SUCCESS) \
60 char buffer[VPI_MAX_STATUS_MESSAGE_LENGTH]; \
61 vpiGetLastStatusMessage(buffer, sizeof(buffer)); \
62 std::ostringstream ss; \
63 ss << vpiStatusGetName(status) << ": " << buffer; \
64 throw std::runtime_error(ss.str()); \
68 int main(
int argc,
char *argv[])
77 VPIImage imgPrevious = NULL, imgCurrent = NULL, imgOutput = NULL;
91 throw std::runtime_error(std::string(
"Usage: ") + argv[0] +
" <vic|cuda> <input_video>");
94 std::string strBackend = argv[1];
95 std::string strInputVideo = argv[2];
100 if (strBackend ==
"cuda")
104 else if (strBackend ==
"vic")
110 throw std::runtime_error(
"Backend '" + strBackend +
"' not recognized, it must be either cuda or vic.");
117 cv::VideoCapture invid;
118 if (!invid.open(strInputVideo))
120 throw std::runtime_error(
"Can't open '" + strInputVideo +
"'");
124 #if CV_MAJOR_VERSION >= 3
125 int w = invid.get(cv::CAP_PROP_FRAME_WIDTH);
126 int h = invid.get(cv::CAP_PROP_FRAME_HEIGHT);
127 int fourcc = cv::VideoWriter::fourcc(
'a',
'v',
'c',
'1');
128 double fps = invid.get(cv::CAP_PROP_FPS);
129 std::string extOutputVideo =
".mp4";
133 int w = invid.get(CV_CAP_PROP_FRAME_WIDTH);
134 int h = invid.get(CV_CAP_PROP_FRAME_HEIGHT);
135 int fourcc = CV_FOURCC(
'M',
'P',
'E',
'G');
136 double fps = invid.get(CV_CAP_PROP_FPS);
137 std::string extOutputVideo =
".avi";
141 cv::VideoWriter outVideo(
"denoised_" + strBackend + extOutputVideo, fourcc, fps, cv::Size(w, h));
142 if (!outVideo.isOpened())
144 throw std::runtime_error(
"Can't create output video");
167 while (invid.read(cvFrame))
169 printf(
"Frame: %d\n", ++curFrame);
172 if (frameBGR == NULL)
196 imgOutput, ¶ms));
208 outVideo << outFrame;
214 std::swap(imgPrevious, imgOutput);
217 catch (std::exception &e)
219 std::cerr << e.what() << std::endl;
Functions and structures for dealing with VPI images.
Functions for handling OpenCV interoperability with VPI.
Declaration of VPI status codes handling functions.
Declares functions dealing with VPI streams.
Declares functions that implement the Temporal Noise Reduction algorithm.
VPIStatus vpiImageLock(VPIImage img, VPILockMode mode, VPIImageData *hostData)
Acquires the lock on an image object and returns a pointer to the image planes.
void vpiImageDestroy(VPIImage img)
Destroy an image instance.
struct VPIImageImpl * VPIImage
A handle to an image.
VPIStatus vpiImageCreate(int32_t width, int32_t height, VPIImageFormat fmt, uint32_t flags, VPIImage *img)
Create an empty image instance with the specified flags.
VPIStatus vpiImageUnlock(VPIImage img)
Releases the lock on an image object.
Stores information about image characteristics and content.
VPIStatus vpiImageDataExportOpenCVMat(const VPIImageData &imgData, cv::Mat *mat)
Fills an existing cv::Mat with data from VPIImageData coming from a locked VPIImage.
VPIStatus vpiImageSetWrappedOpenCVMat(VPIImage img, const cv::Mat &mat)
Redefines the wrapped cv::Mat of an existing VPIImage wrapper.
VPIStatus vpiImageCreateOpenCVMatWrapper(const cv::Mat &mat, VPIImageFormat fmt, uint32_t flags, VPIImage *img)
Wraps a cv::Mat in an VPIImage with the given image format.
struct VPIPayloadImpl * VPIPayload
A handle to an algorithm payload.
void vpiPayloadDestroy(VPIPayload payload)
Deallocates the payload object and all associated resources.
struct VPIStreamImpl * VPIStream
A handle to a stream.
VPIStatus vpiStreamSync(VPIStream stream)
Blocks the calling thread until all submitted commands in this stream queue are done (queue is empty)...
VPIBackend
VPI Backend types.
void vpiStreamDestroy(VPIStream stream)
Destroy a stream instance and deallocate all HW resources.
VPIStatus vpiStreamCreate(uint32_t flags, VPIStream *stream)
Create a stream instance.
@ VPI_BACKEND_CUDA
CUDA backend.
@ VPI_BACKEND_VIC
VIC backend.
float strength
Noise reduction strength.
VPITNRPreset preset
Scene preset to be used.
VPIStatus vpiInitTemporalNoiseReductionParams(VPITNRParams *params)
Initializes vpiSubmitTemporalNoiseReduction with default values.
VPIStatus vpiCreateTemporalNoiseReduction(uint32_t backends, int32_t width, int32_t height, VPIImageFormat imgFormat, VPITNRVersion version, VPIPayload *payload)
Creates a payload for Temporal Noise Reduction algorithm.
VPIStatus vpiSubmitTemporalNoiseReduction(VPIStream stream, uint32_t backend, VPIPayload payload, VPIImage prevFrame, VPIImage curFrame, VPIImage outFrame, const VPITNRParams *params)
Submits a Temporal Noise Reduction operation to the stream associated with the given payload.
@ VPI_TNR_PRESET_INDOOR_MEDIUM_LIGHT
Medium light indoor scene.
@ VPI_TNR_DEFAULT
Chooses the version with best quality available in the current device and given backend.
Structure that defines the parameters for vpiSubmitTemporalNoiseReduction.
@ VPI_LOCK_READ
Lock memory only for reading.