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>
53 #define CHECK_STATUS(STMT) \
56 VPIStatus status = (STMT); \
57 if (status != VPI_SUCCESS) \
59 char buffer[VPI_MAX_STATUS_MESSAGE_LENGTH]; \
60 vpiGetLastStatusMessage(buffer, sizeof(buffer)); \
61 std::ostringstream ss; \
62 ss << vpiStatusGetName(status) << ": " << buffer; \
63 throw std::runtime_error(ss.str()); \
70 for (
int i = 0; i < 3; ++i)
72 for (
int j = 0; j < 3; ++j)
74 r[i][j] = a[i][0] * b[0][j];
75 for (
int k = 1; k < 3; ++k)
77 r[i][j] += a[i][k] * b[k][j];
83 int main(
int argc,
char *argv[])
91 VPIImage imgInput = NULL, imgOutput = NULL;
104 throw std::runtime_error(std::string(
"Usage: ") + argv[0] +
" <cpu|vic|cuda> <input_video>");
107 std::string strBackend = argv[1];
108 std::string strInputVideo = argv[2];
113 if (strBackend ==
"cpu")
117 else if (strBackend ==
"cuda")
121 else if (strBackend ==
"vic")
127 throw std::runtime_error(
"Backend '" + strBackend +
128 "' not recognized, it must be either cpu, cuda or vic.");
135 cv::VideoCapture invid;
136 if (!invid.open(strInputVideo))
138 throw std::runtime_error(
"Can't open '" + strInputVideo +
"'");
142 #if CV_MAJOR_VERSION >= 3
143 int w = invid.get(cv::CAP_PROP_FRAME_WIDTH);
144 int h = invid.get(cv::CAP_PROP_FRAME_HEIGHT);
145 int fourcc = cv::VideoWriter::fourcc(
'a',
'v',
'c',
'1');
146 double fps = invid.get(cv::CAP_PROP_FPS);
147 std::string extOutputVideo =
".mp4";
151 int w = invid.get(CV_CAP_PROP_FRAME_WIDTH);
152 int h = invid.get(CV_CAP_PROP_FRAME_HEIGHT);
153 int fourcc = CV_FOURCC(
'M',
'P',
'E',
'G');
154 double fps = invid.get(CV_CAP_PROP_FPS);
155 std::string extOutputVideo =
".avi";
158 cv::VideoWriter outVideo(
"perspwarp_" + strBackend + extOutputVideo, fourcc, fps, cv::Size(w, h));
159 if (!outVideo.isOpened())
161 throw std::runtime_error(
"Can't create output video");
177 memset(&xform, 0,
sizeof(xform));
183 while (invid.read(cvFrame))
185 printf(
"Frame: %d\n", curFrame++);
187 if (frameBGR == NULL)
205 float v1 = sin(curFrame / 30.0 * 2 * M_PI / 2) * 0.0005f;
206 float v2 = cos(curFrame / 30.0 * 2 * M_PI / 3) * 0.0005f;
214 MatrixMultiply(tmp, P, t1);
215 MatrixMultiply(xform, t2, tmp);
231 outVideo << outFrame;
236 catch (std::exception &e)
238 std::cerr << e.what() << std::endl;
Functions and structures for dealing with VPI images.
Functions for handling OpenCV interoperability with VPI.
Declares functions that implement the Perspective Warp algorithm.
Declaration of VPI status codes handling functions.
Declares functions dealing with VPI streams.
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.
float VPIPerspectiveTransform[3][3]
Represents a 2D perspective transform.
VPIStatus vpiSubmitPerspectiveWarp(VPIStream stream, uint32_t backend, VPIPayload payload, VPIImage input, const VPIPerspectiveTransform xform, VPIImage output, VPIInterpolationType interp, VPIBorderExtension border, uint32_t flags)
Submits the Perspective Warp operation to the stream associated with the payload.
VPIStatus vpiCreatePerspectiveWarp(uint32_t backends, VPIPayload *payload)
Creates a payload for Perspective Warp algorithm.
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.
@ VPI_BACKEND_CPU
CPU backend.
@ VPI_BORDER_ZERO
All pixels outside the image are considered to be zero.
@ VPI_INTERP_LINEAR
Linear interpolation.
@ VPI_LOCK_READ
Lock memory only for reading.