29 #include <opencv2/core.hpp>
30 #include <opencv2/features2d.hpp>
31 #include <opencv2/imgcodecs.hpp>
32 #include <opencv2/imgproc.hpp>
51 #define CHECK_STATUS(STMT) \
54 VPIStatus status = (STMT); \
55 if (status != VPI_SUCCESS) \
57 char buffer[VPI_MAX_STATUS_MESSAGE_LENGTH]; \
58 vpiGetLastStatusMessage(buffer, sizeof(buffer)); \
59 std::ostringstream ss; \
60 ss << vpiStatusGetName(status) << ": " << buffer; \
61 throw std::runtime_error(ss.str()); \
68 img.convertTo(out, CV_8UC1);
69 cvtColor(out, out, cv::COLOR_GRAY2BGR);
71 if (numKeypoints == 0)
76 for (
int i = 0; i < numKeypoints; ++i)
78 auto de=outDescriptors[i];
79 cv::Scalar col(255,0,0);
80 for(
int j=0; j<32;j++){
81 if(de.data[j]>0) { col=cv::Scalar(0,255, 0);
break;}
83 circle(out, cv::Point(kpts[i].x, kpts[i].y), 3, col, -1);
88 int main(
int argc,
char *argv[])
113 throw std::runtime_error(std::string(
"Usage: ") + argv[0] +
" <cpu|cuda> <input image>");
116 std::string strBackend = argv[1];
117 std::string strInputFileName = argv[2];
122 if (strBackend ==
"cpu")
126 else if (strBackend ==
"cuda")
132 throw std::runtime_error(
"Backend '" + strBackend +
"' not recognized, it must be either cpu or cuda.");
138 cvImage = cv::imread(strInputFileName);
141 throw std::runtime_error(
"Can't open first image: '" + strInputFileName +
"'");
164 orbParams.
scoreType=VPI_CORNER_SCORE_HARRIS;
218 printf(
"%d keypoints found\n", nkp);
219 for(
int i=0; i<nkp;i++)
221 printf(
"%d %f %f\n",i, (outKeypoints[i]).x,(outKeypoints[i]).y);
224 printf(
"%d descriptors found\n", nde);
225 for(
int i=0; i<nde;i++)
230 printf(
"%hhu ", (outDescriptors[i]).data[j]);
238 cv::Mat outImage = DrawKeypoints(img, outKeypoints, outDescriptors, *outKeypointsData.
buffer.
aos.
sizePointer);
240 imwrite(
"orb_feature_detector_" + strBackend +
".png", outImage);
249 catch (std::exception &e)
251 std::cerr << e.what() << std::endl;
Functions and structures for dealing with VPI arrays.
Declares functions that handle gaussian pyramids.
Declares functions that implement Image flip algorithms.
Functions and structures for dealing with VPI images.
Declares functions that implement support for ORB.
Functions for handling OpenCV interoperability with VPI.
Functions and structures for dealing with VPI pyramids.
Declaration of VPI status codes handling functions.
Declares functions dealing with VPI streams.
#define VPI_BRIEF_DESCRIPTOR_ARRAY_LENGTH
Length of Brief Descriptor Array.
Stores a BRIEF Descriptor.
void * data
Points to the first element of the array.
VPIArrayBuffer buffer
Stores the array contents.
int32_t * sizePointer
Points to the number of elements in the array.
VPIArrayBufferAOS aos
Array stored in array-of-structures layout.
VPIStatus vpiArrayUnlock(VPIArray array)
Releases the lock on array object.
VPIStatus vpiArrayLockData(VPIArray array, VPILockMode mode, VPIArrayBufferType bufType, VPIArrayData *data)
Acquires the lock on an array object and returns the array contents.
void vpiArrayDestroy(VPIArray array)
Destroy an array instance.
VPIStatus vpiArrayCreate(int32_t capacity, VPIArrayType type, uint64_t flags, VPIArray *array)
Create an empty array instance.
struct VPIArrayImpl * VPIArray
A handle to an array.
@ VPI_ARRAY_TYPE_KEYPOINT_F32
VPIKeypointF32 element.
@ VPI_ARRAY_BUFFER_HOST_AOS
Host-accessible array-of-structures.
Stores information about array characteristics and contents.
VPIStatus vpiSubmitGaussianPyramidGenerator(VPIStream stream, uint64_t backend, VPIImage input, VPIPyramid output, VPIBorderExtension border)
Computes the Gaussian pyramid from the input image.
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.
VPICornerScore scoreType
The scoring criteria for ordering the top N FAST corners.
int32_t maxFeatures
The maximum number of features alloted per level of the scale pyramid.
int32_t pyramidLevels
The number of levels in the scale pyramid to utilize.
VPIStatus vpiInitORBParams(VPIORBParams *params)
Initializes VPIORBParams with default values.
VPIStatus vpiCreateORBFeatureDetector(uint64_t backends, size_t capacity, VPIPayload *payload)
Creates a ORB payload.
VPIStatus vpiSubmitORBFeatureDetector(VPIStream stream, uint64_t backend, VPIPayload payload, VPIPyramid input, VPIArray outCorners, VPIArray outDescriptors, const VPIORBParams *params, VPIBorderExtension border)
Submits a ORB operation to the stream.
Structure that defines the parameters for both vpiCreateORBFeatureDetector and vpiSubmitORBFeatureDet...
struct VPIPayloadImpl * VPIPayload
A handle to an algorithm payload.
void vpiPayloadDestroy(VPIPayload payload)
Deallocates the payload object and all associated resources.
VPIStatus vpiPyramidCreate(int32_t width, int32_t height, VPIImageFormat fmt, int32_t numLevels, float scale, uint64_t flags, VPIPyramid *pyr)
Create an empty image pyramid instance with the specified flags.
struct VPIPyramidImpl * VPIPyramid
A handle to an image pyramid.
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_CPU
CPU backend.
VPIBorderExtension
Image border extension specify how pixel values outside of the image domain should be constructed.
@ VPI_BORDER_CLAMP
Border pixels are repeated indefinitely.
@ VPI_LOCK_READ
Lock memory only for reading.
Stores a float32 keypoint coordinate The coordinate is relative to the top-left corner of an image.