29 #include <opencv2/core/version.hpp>
30 #include <opencv2/imgcodecs.hpp>
31 #include <opencv2/imgproc/imgproc.hpp>
32 #include <opencv2/videoio.hpp>
49 #define CHECK_STATUS(STMT) \
52 VPIStatus status = (STMT); \
53 if (status != VPI_SUCCESS) \
55 char buffer[VPI_MAX_STATUS_MESSAGE_LENGTH]; \
56 vpiGetLastStatusMessage(buffer, sizeof(buffer)); \
57 std::ostringstream ss; \
58 ss << vpiStatusGetName(status) << ": " << buffer; \
59 throw std::runtime_error(ss.str()); \
63 int main(
int argc,
char *argv[])
72 VPIImage imgPrevious = NULL, imgCurrent = NULL, imgOutput = NULL;
86 throw std::runtime_error(std::string(
"Usage: ") + argv[0] +
" <vic|cuda> <input_video>");
89 std::string strBackend = argv[1];
90 std::string strInputVideo = argv[2];
95 if (strBackend ==
"cuda")
99 else if (strBackend ==
"vic")
105 throw std::runtime_error(
"Backend '" + strBackend +
"' not recognized, it must be either cuda or vic.");
112 cv::VideoCapture invid;
113 if (!invid.open(strInputVideo))
115 throw std::runtime_error(
"Can't open '" + strInputVideo +
"'");
119 int w = invid.get(cv::CAP_PROP_FRAME_WIDTH);
120 int h = invid.get(cv::CAP_PROP_FRAME_HEIGHT);
121 int fourcc = cv::VideoWriter::fourcc(
'M',
'P',
'E',
'G');
122 double fps = invid.get(cv::CAP_PROP_FPS);
125 cv::VideoWriter outVideo(
"denoised_" + strBackend +
".mp4", fourcc, fps, cv::Size(w, h));
126 if (!outVideo.isOpened())
128 throw std::runtime_error(
"Can't create output video");
151 while (invid.read(cvFrame))
153 printf(
"Frame: %d\n", ++curFrame);
156 if (frameBGR == NULL)
180 imgOutput, ¶ms));
192 outVideo << outFrame;
198 std::swap(imgPrevious, imgOutput);
201 catch (std::exception &e)
203 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.
void vpiImageDestroy(VPIImage img)
Destroy an image instance.
struct VPIImageImpl * VPIImage
A handle to an image.
VPIStatus vpiImageLockData(VPIImage img, VPILockMode mode, VPIImageBufferType bufType, VPIImageData *data)
Acquires the lock on an image object and returns the image contents.
VPIStatus vpiImageCreate(int32_t width, int32_t height, VPIImageFormat fmt, uint64_t flags, VPIImage *img)
Create an empty image instance with the specified flags.
VPIStatus vpiImageUnlock(VPIImage img)
Releases the lock on an image object.
@ VPI_IMAGE_BUFFER_HOST_PITCH_LINEAR
Host-accessible with planes in pitch-linear memory layout.
Stores information about image characteristics and content.
VPIStatus vpiImageCreateWrapperOpenCVMat(const cv::Mat &mat, VPIImageFormat fmt, uint64_t flags, VPIImage *img)
Wraps a cv::Mat in an VPIImage with the given image format.
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.
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(uint64_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 vpiSubmitTemporalNoiseReduction(VPIStream stream, uint64_t backend, VPIPayload payload, VPIImage prevFrame, VPIImage curFrame, VPIImage outFrame, const VPITNRParams *params)
Submits a Temporal Noise Reduction operation to the stream.
VPIStatus vpiInitTemporalNoiseReductionParams(VPITNRParams *params)
Initializes vpiSubmitTemporalNoiseReduction with default values.
VPIStatus vpiCreateTemporalNoiseReduction(uint64_t backends, int32_t width, int32_t height, VPIImageFormat imgFormat, VPITNRVersion version, VPIPayload *payload)
Creates a payload for Temporal Noise Reduction algorithm.
@ 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.