29 #include <opencv2/core.hpp>
30 #include <opencv2/features2d.hpp>
31 #include <opencv2/imgcodecs.hpp>
32 #include <opencv2/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()); \
71 img.convertTo(out, CV_8UC1);
72 cvtColor(out, out, cv::COLOR_GRAY2BGR);
74 if (numKeypoints == 0)
79 std::vector<int> distances(numKeypoints, 0);
82 for (
int i = 0; i < numKeypoints; i++)
86 distances[i] += std::bitset<8 * sizeof(uint8_t)>(descs[i].data[j] ^ descs[0].data[j]).count();
88 if (distances[i] > maxDist)
90 maxDist = distances[i];
95 std::iota(&ids[0], &ids[0] + 256, 0);
96 cv::Mat idsMat(256, 1, CV_8UC1, ids);
99 applyColorMap(idsMat, cmap, cv::COLORMAP_JET);
101 for (
int i = 0; i < numKeypoints; i++)
103 int cmapIdx =
static_cast<int>(std::round((distances[i] / maxDist) * 255));
105 circle(out, cv::Point(kpts[i].x, kpts[i].y), 3, cmap.at<cv::Vec3b>(cmapIdx, 0), -1);
111 int main(
int argc,
char *argv[])
136 throw std::runtime_error(std::string(
"Usage: ") + argv[0] +
" <cpu|cuda> <input image>");
139 std::string strBackend = argv[1];
140 std::string strInputFileName = argv[2];
145 if (strBackend ==
"cpu")
149 else if (strBackend ==
"cuda")
155 throw std::runtime_error(
"Backend '" + strBackend +
"' not recognized, it must be either cpu or cuda.");
164 cvImage = cv::imread(strInputFileName);
167 throw std::runtime_error(
"Can't open first image: '" + strInputFileName +
"'");
215 backend, &pyrInput));
242 cv::Mat outImage = DrawKeypoints(img, outKeypoints, outDescriptors, *outKeypointsData.
buffer.
aos.
sizePointer);
245 imwrite(
"orb_feature_detector_" + strBackend +
".png", outImage);
252 catch (std::exception &e)
254 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_TYPE_BRIEF_DESCRIPTOR
VPIBriefDescriptor element.
@ VPI_ARRAY_BUFFER_HOST_AOS
Host-accessible array-of-structures.
Stores information about array characteristics and contents.
float intensityThreshold
Threshold to select a pixel as being part of the arc in circle around a keypoint candidate.
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.
int32_t maxFeaturesPerLevel
The maximum number N of features per level of the input pyramid to be used by ORB.
VPIFASTCornerDetectorParams fastParams
Parameters for the FAST corner detector, see FAST Corners Detector for more details.
int32_t maxPyramidLevels
Maximum number of levels in the input pyramid to utilize.
VPIStatus vpiInitORBParams(VPIORBParams *params)
Initializes VPIORBParams with default values.
VPIStatus vpiSubmitORBFeatureDetector(VPIStream stream, uint64_t backend, VPIPayload payload, VPIPyramid input, VPIArray outCorners, VPIArray outDescriptors, const VPIORBParams *params, VPIBorderExtension border)
Submits an ORB feature detector operation to the stream.
VPIStatus vpiCreateORBFeatureDetector(uint64_t backends, int32_t capacity, VPIPayload *payload)
Creates an ORB feature detector payload.
Structure that defines the parameters for vpiSubmitORBFeatureDetector.
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.
@ VPI_BORDER_LIMITED
Consider image as limited to not access outside pixels.
@ 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.