CoreFlow 1.0.0
A modern orchestration and execution runtime
Loading...
Searching...
No Matches
orb.cpp

ORB Sample.

ORB Sample

Version
0.1
Date
2025-09-03
/*
* Copyright (c) 2022 - 2024 Advanced Micro Devices, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <VX/vx.h>
#include "vx_ext_opencv.h"
using namespace cv;
using namespace std;
#define ERROR_CHECK_STATUS( status ) { \
vx_status status_ = (status); \
if(status_ != VX_SUCCESS) { \
printf("ERROR: failed with status = (%d) at " __FILE__ "#%d\n", status_, __LINE__); \
exit(1); \
} \
}
#define ERROR_CHECK_OBJECT( obj ) { \
vx_status status_ = vxGetStatus((vx_reference)(obj)); \
if(status_ != VX_SUCCESS) { \
printf("ERROR: failed with status = (%d) at " __FILE__ "#%d\n", status_, __LINE__); \
exit(1); \
} \
}
static void VX_CALLBACK log_callback(vx_context context, vx_reference ref, vx_status status, const vx_char string[])
{
(void)context;
(void)ref;
(void)status;
size_t len = strlen(string);
if (len > 0) {
printf("%s", string);
if (string[len - 1] != '\n')
printf("\n");
fflush(stdout);
}
}
int main(int argc, char **argv)
{
(void)argv;
if (argc < 1) {
printf("Usage: ./orbDetect\n");
return 0;
}
vxRegisterLogCallback(context, log_callback, vx_false_e);
vxLoadKernels(context, "openvx-opencv");
vx_graph graph = vxCreateGraph(context);
int width = 1280, height = 720;
vx_image inter_luma = vxCreateImage(context, width, height, VX_DF_IMAGE_U8);
ERROR_CHECK_OBJECT(inter_luma);
VideoCapture cap(0);
Mat input, output;
cap >> input;
cap >> output;
cvtColor(input, input, COLOR_RGB2GRAY);
if (input.empty()) {
printf("Image not found\n");
}
cv::resize(input, input, Size(width, height));
cv::resize(output, output, Size(width, height));
vx_rectangle_t cv_image_region;
cv_image_region.start_x = 0;
cv_image_region.start_y = 0;
cv_image_region.end_x = width;
cv_image_region.end_y = height;
vx_imagepatch_addressing_t cv_image_layout;
cv_image_layout.stride_x = 1;
cv_image_layout.stride_y = input.step;
vx_uint8 * cv_image_buffer = input.data;
ERROR_CHECK_STATUS( vxCopyImagePatch( inter_luma, &cv_image_region, 0,
&cv_image_layout, cv_image_buffer,
vx_array keypoints = vxCreateArray( context, VX_TYPE_KEYPOINT, 10000 );
ERROR_CHECK_OBJECT( keypoints );
vx_int32 nFeatures = 1000;
vx_float32 scaleFactor = 1.2;
vx_int32 nlevels = 2;
vx_int32 edgeThreshold = 31;
vx_int32 firstLevel = 0;
vx_int32 WTA_K = 2;
vx_int32 scoreType = 0;
vx_int32 patchSize = 31;
vx_node nodes[] =
{
vxExtCvNode_orbDetect(graph, inter_luma, inter_luma, keypoints, nFeatures, scaleFactor, nlevels, edgeThreshold, firstLevel, WTA_K, scoreType, patchSize)
};
for( vx_size i = 0; i < sizeof( nodes ) / sizeof( nodes[0] ); i++ )
{
ERROR_CHECK_OBJECT( nodes[i] );
}
vx_size num_corners = 0;
ERROR_CHECK_STATUS(vxQueryArray (keypoints, VX_ARRAY_NUMITEMS, &num_corners, sizeof(num_corners)));
if (num_corners > 0) {
vx_size kp_stride;
vx_map_id kp_map;
vx_uint8 * kp_buf;
ERROR_CHECK_STATUS(vxMapArrayRange (keypoints, 0, num_corners, &kp_map, &kp_stride, (void **)&kp_buf, VX_READ_ONLY, VX_MEMORY_TYPE_HOST, 0));
for (vx_size i = 0; i < num_corners; i++) {
vx_keypoint_t * kp = (vx_keypoint_t *) (kp_buf + i*kp_stride);
cv::Point center (kp->x, kp->y);
cv::circle (output, center, 1, cv::Scalar(0,255, 0),2);
}
}
imshow( "OrbDetect", output );
waitKey(0);
return 0;
}
int main()
Definition blur_pipeline.cpp:15
#define ERROR_CHECK_OBJECT(obj)
Definition bubble_pop.cpp:28
#define ERROR_CHECK_STATUS(status)
Definition bubble_pop.cpp:20
VX_API_ENTRY vx_status VX_API_CALL vxMapArrayRange(vx_array array, vx_size range_start, vx_size range_end, vx_map_id *map_id, vx_size *stride, void **ptr, vx_enum usage, vx_enum mem_type, vx_uint32 flags)
Allows the application to get direct access to a range of an array object.
VX_API_ENTRY vx_status VX_API_CALL vxQueryArray(vx_array arr, vx_enum attribute, void *ptr, vx_size size)
Queries the Array for some specific information.
VX_API_ENTRY vx_status VX_API_CALL vxReleaseArray(vx_array *arr)
Releases a reference of an Array object. The object may not be garbage collected until its total refe...
struct Array * vx_array
The Array Object. Array is a strongly-typed container for other data structures.
Definition vx_types.h:367
VX_API_ENTRY vx_array VX_API_CALL vxCreateArray(vx_context context, vx_enum item_type, vx_size capacity)
Creates a reference to an Array object.
@ VX_ARRAY_NUMITEMS
The number of items in the Array. Read-only. Use a vx_size parameter.
Definition vx_types.h:1259
struct _vx_keypoint_t vx_keypoint_t
The keypoint data structure.
size_t vx_size
A wrapper of size_t to keep the naming convention uniform.
Definition vx_types.h:186
vx_enum vx_status
A formal status type with known fixed size.
Definition vx_types.h:550
int32_t vx_int32
A 32-bit signed value.
Definition vx_types.h:105
struct _vx_rectangle_t vx_rectangle_t
The rectangle data structure that is shared with the users. The area of the rectangle can be computed...
char vx_char
An 8 bit ASCII character.
Definition vx_types.h:70
uint8_t vx_uint8
An 8-bit unsigned value.
Definition vx_types.h:75
float vx_float32
A 32-bit float value.
Definition vx_types.h:131
#define VX_CALLBACK
Defines calling convention for user callbacks.
Definition vx_types.h:63
@ VX_DF_IMAGE_U8
A single plane of unsigned 8-bit data. The range of data is not specified, as it may be extracted fro...
Definition vx_types.h:855
@ vx_false_e
The "false" value.
Definition vx_types.h:404
@ VX_TYPE_KEYPOINT
A vx_keypoint_t.
Definition vx_types.h:453
struct Context * vx_context
An opaque reference to the implementation context.
Definition vx_types.h:274
VX_API_ENTRY vx_context VX_API_CALL vxCreateContext(void)
Creates a vx_context.
VX_API_ENTRY vx_status VX_API_CALL vxReleaseContext(vx_context *context)
Releases the OpenVX object context.
@ VX_READ_ONLY
The memory shall be treated by the system as if it were read-only. If the User writes to this memory,...
Definition vx_types.h:1515
@ VX_WRITE_ONLY
The memory shall be treated by the system as if it were write-only. If the User reads from this memor...
Definition vx_types.h:1519
@ VX_MEMORY_TYPE_HOST
The default memory type to import from the Host.
Definition vx_types.h:1338
VX_API_ENTRY vx_status VX_API_CALL vxVerifyGraph(vx_graph graph)
Verifies the state of the graph before it is executed. This is useful to catch programmer errors and ...
VX_API_ENTRY vx_status VX_API_CALL vxReleaseGraph(vx_graph *graph)
Releases a reference to a graph. The object may not be garbage collected until its total reference co...
VX_API_ENTRY vx_graph VX_API_CALL vxCreateGraph(vx_context context)
Creates an empty graph.
struct Graph * vx_graph
An opaque reference to a graph.
Definition vx_types.h:263
VX_API_ENTRY vx_status VX_API_CALL vxProcessGraph(vx_graph graph)
This function causes the synchronous processing of a graph. If the graph has not been verified,...
struct _vx_imagepatch_addressing_t vx_imagepatch_addressing_t
The addressing image patch structure is used by the Host only to address pixels in an image patch....
struct Image * vx_image
An opaque reference to an image.
Definition vx_types.h:219
VX_API_ENTRY vx_status VX_API_CALL vxReleaseImage(vx_image *image)
Releases a reference to an image object. The object may not be garbage collected until its total refe...
uintptr_t vx_map_id
Holds the address of a variable where the map/unmap functions return a map identifier.
Definition vx_types.h:196
VX_API_ENTRY vx_status VX_API_CALL vxCopyImagePatch(vx_image image, const vx_rectangle_t *image_rect, vx_uint32 image_plane_index, const vx_imagepatch_addressing_t *user_addr, void *user_ptr, vx_enum usage, vx_enum user_mem_type)
Allows the application to copy a rectangular patch from/into an image object plane.
VX_API_ENTRY vx_image VX_API_CALL vxCreateImage(vx_context context, vx_uint32 width, vx_uint32 height, vx_df_image color)
Creates an opaque reference to an image buffer.
VX_API_ENTRY void VX_API_CALL vxRegisterLogCallback(vx_context context, vx_log_callback_f callback, vx_bool reentrant)
Registers a callback facility to the OpenVX implementation to receive error logs.
struct Node * vx_node
An opaque reference to a kernel node.
Definition vx_types.h:253
VX_API_ENTRY vx_status VX_API_CALL vxReleaseNode(vx_node *node)
Releases a reference to a Node object. The object may not be garbage collected until its total refere...
VX_API_ENTRY vx_status VX_API_CALL vxLoadKernels(vx_context context, const vx_char *module)
Loads a library of kernels, called module, into a context.
vx_int32 stride_y
Stride in Y dimension in bytes.
Definition vx_types.h:1644
vx_int32 stride_x
Stride in X dimension in bytes.
Definition vx_types.h:1643
vx_int32 x
The x coordinate.
Definition vx_types.h:1758
vx_int32 y
The y coordinate.
Definition vx_types.h:1759
vx_uint32 start_x
The Start X coordinate.
Definition vx_types.h:1771
vx_uint32 start_y
The Start Y coordinate.
Definition vx_types.h:1772
vx_uint32 end_y
The End Y coordinate.
Definition vx_types.h:1774
vx_uint32 end_x
The End X coordinate.
Definition vx_types.h:1773
The top level OpenVX Header.
struct Reference * vx_reference
Definition vx_types.h:173