29 #include <opencv2/core/version.hpp>
30 #if CV_MAJOR_VERSION >= 3
31 # include <opencv2/imgcodecs.hpp>
33 # include <opencv2/contrib/contrib.hpp>
34 # include <opencv2/highgui/highgui.hpp>
37 #include <opencv2/imgproc/imgproc.hpp>
52 #define CHECK_STATUS(STMT) \
55 VPIStatus status = (STMT); \
56 if (status != VPI_SUCCESS) \
58 char buffer[VPI_MAX_STATUS_MESSAGE_LENGTH]; \
59 vpiGetLastStatusMessage(buffer, sizeof(buffer)); \
60 std::ostringstream ss; \
61 ss << vpiStatusGetName(status) << ": " << buffer; \
62 throw std::runtime_error(ss.str()); \
66 static cv::Mat DrawKeypoints(cv::Mat img,
VPIKeypoint *kpts, uint32_t *scores,
int numKeypoints)
69 img.convertTo(out, CV_8UC1);
70 cvtColor(out, out, cv::COLOR_GRAY2BGR);
72 if (numKeypoints == 0)
78 cv::Mat cmap(1, 256, CV_8UC3);
80 cv::Mat gray(1, 256, CV_8UC1);
81 for (
int i = 0; i < 256; ++i)
83 gray.at<
unsigned char>(0, i) = i;
85 applyColorMap(gray, cmap, cv::COLORMAP_HOT);
88 float maxScore = *std::max_element(scores, scores + numKeypoints);
90 for (
int i = 0; i < numKeypoints; ++i)
92 cv::Vec3b color = cmap.at<cv::Vec3b>(scores[i] / maxScore * 255);
93 circle(out, cv::Point(kpts[i].x, kpts[i].y), 3, cv::Scalar(color[0], color[1], color[2]), -1);
99 int main(
int argc,
char *argv[])
122 throw std::runtime_error(std::string(
"Usage: ") + argv[0] +
" <cpu|pva|cuda> <input image>");
125 std::string strBackend = argv[1];
126 std::string strInputFileName = argv[2];
131 if (strBackend ==
"cpu")
135 else if (strBackend ==
"cuda")
139 else if (strBackend ==
"pva")
145 throw std::runtime_error(
"Backend '" + strBackend +
146 "' not recognized, it must be either cpu, cuda or pva.");
152 cvImage = cv::imread(strInputFileName);
155 throw std::runtime_error(
"Can't open '" + strInputFileName +
"'");
210 uint32_t *outScores = (uint32_t *)outScoresData.
data;
212 printf(
"\n%d keypoints found\n", *outKeypointsData.
sizePointer);
217 cv::Mat outImage = DrawKeypoints(img, outKeypoints, outScores, *outKeypointsData.
sizePointer);
219 imwrite(
"harris_corners_" + strBackend +
".png", outImage);
226 catch (std::exception &e)
228 std::cerr << e.what() << std::endl;
Functions and structures for dealing with VPI arrays.
Declares functions that implement the Harris Corner Detector algorithm.
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.
int32_t * sizePointer
Points to the number of elements in the array.
void * data
Points to the first element of the array.
VPIStatus vpiArrayUnlock(VPIArray array)
Releases the lock on array object.
VPIStatus vpiArrayLock(VPIArray array, VPILockMode mode, VPIArrayData *arrayData)
Acquires the lock on array object and returns a pointer to array data.
void vpiArrayDestroy(VPIArray array)
Destroy an array instance.
VPIStatus vpiArrayCreate(int32_t capacity, VPIArrayType type, uint32_t flags, VPIArray *array)
Create an empty array instance.
struct VPIArrayImpl * VPIArray
A handle to an array.
@ VPI_ARRAY_TYPE_U32
unsigned 32-bit.
@ VPI_ARRAY_TYPE_KEYPOINT
VPIKeypoint element.
Stores information about array characteristics and content.
float sensitivity
Specifies sensitivity threshold from the Harris-Stephens equation.
VPIStatus vpiInitHarrisCornerDetectorParams(VPIHarrisCornerDetectorParams *params)
Initializes VPIHarrisCornerDetectorParams with default values.
VPIStatus vpiCreateHarrisCornerDetector(uint32_t backends, int32_t inputWidth, int32_t inputHeight, VPIPayload *payload)
Creates a Harris Corner Detector payload.
VPIStatus vpiSubmitHarrisCornerDetector(VPIStream stream, uint32_t backend, VPIPayload payload, VPIImage input, VPIArray outFeatures, VPIArray outScores, const VPIHarrisCornerDetectorParams *params)
Submits Harris Corner Detector operation to the stream associated with the payload.
Structure that defines the parameters for vpiSubmitHarrisCornerDetector.
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 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_PVA
PVA backend.
@ VPI_BACKEND_CPU
CPU backend.
@ VPI_LOCK_READ
Lock memory only for reading.
Stores a keypoint coordinate.