Skip to content

Commit 42f328e

Browse files
committed
Removed the use of status variable, use the macros directly.
1 parent 51585c8 commit 42f328e

2 files changed

Lines changed: 38 additions & 59 deletions

File tree

tutorial_exercises/solution_exercise1/solution_exercise1.cpp

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@
5353
// Useful macros for OpenVX error checking:
5454
// ERROR_CHECK_STATUS - check status is VX_SUCCESS
5555
// ERROR_CHECK_OBJECT - check if the object creation is successful
56-
#define ERROR_CHECK_STATUS(status) { \
56+
#define ERROR_CHECK_STATUS( status ) { \
5757
vx_status status_ = (status); \
5858
if(status_ != VX_SUCCESS) { \
5959
printf("ERROR: failed with status = (%d) at " __FILE__ "#%d\n", status_, __LINE__); \
6060
exit(1); \
6161
} \
6262
}
6363

64-
#define ERROR_CHECK_OBJECT(obj) { \
64+
#define ERROR_CHECK_OBJECT( obj ) { \
6565
vx_status status_ = vxGetStatus((vx_reference)(obj)); \
6666
if(status_ != VX_SUCCESS) { \
6767
printf("ERROR: failed with status = (%d) at " __FILE__ "#%d\n", status_, __LINE__); \
@@ -205,10 +205,6 @@ int main( int argc, char * argv[] )
205205
// Process the video sequence frame by frame until the end of sequence or aborted.
206206
for( int frame_index = 0; !gui.AbortRequested(); frame_index++ )
207207
{
208-
////////
209-
// local variable for checking the status of OpenVX API calls
210-
vx_status status;
211-
212208
////////********
213209
// Copy the input RGB frame from OpenCV to OpenVX.
214210
// In order to do this, you need to use vxAccessImagePatch and vxCommitImagePatch APIs.
@@ -239,12 +235,11 @@ int main( int argc, char * argv[] )
239235
cv_rgb_image_layout.stride_x = 3;
240236
cv_rgb_image_layout.stride_y = gui.GetStride();
241237
vx_uint8 * cv_rgb_image_buffer = gui.GetBuffer();
242-
status = vxAccessImagePatch( input_rgb_image, &cv_rgb_image_region, 0,
243-
&cv_rgb_image_layout, ( void ** )&cv_rgb_image_buffer, VX_WRITE_ONLY );
244-
ERROR_CHECK_STATUS( status );
245-
status = vxCommitImagePatch( input_rgb_image, &cv_rgb_image_region, 0,
246-
&cv_rgb_image_layout, cv_rgb_image_buffer );
247-
ERROR_CHECK_STATUS( status );
238+
ERROR_CHECK_STATUS( vxAccessImagePatch( input_rgb_image, &cv_rgb_image_region, 0,
239+
&cv_rgb_image_layout, ( void ** )&cv_rgb_image_buffer,
240+
VX_WRITE_ONLY ) );
241+
ERROR_CHECK_STATUS( vxCommitImagePatch( input_rgb_image, &cv_rgb_image_region, 0,
242+
&cv_rgb_image_layout, cv_rgb_image_buffer ) );
248243

249244
////////********
250245
// In order to compute Harris corners from input RGB image, first you
@@ -260,14 +255,11 @@ int main( int argc, char * argv[] )
260255
// The num_corners parameter to vxuHarrisCorners is optional,
261256
// you need to set it to NULL in this exercise.
262257
// 4. Use ERROR_CHECK_STATUS for error checking.
263-
status = vxuColorConvert( context, input_rgb_image, yuv_image );
264-
ERROR_CHECK_STATUS( status );
265-
status = vxuChannelExtract( context, yuv_image, VX_CHANNEL_Y, gray_scale_image );
266-
ERROR_CHECK_STATUS( status );
267-
status = vxuHarrisCorners( context, gray_scale_image, strength_thresh,
268-
min_distance, sensitivity, harris_gradient_size, harris_block_size,
269-
output_keypoint_array, NULL );
270-
ERROR_CHECK_STATUS( status );
258+
ERROR_CHECK_STATUS( vxuColorConvert( context, input_rgb_image, yuv_image ) );
259+
ERROR_CHECK_STATUS( vxuChannelExtract( context, yuv_image, VX_CHANNEL_Y, gray_scale_image ) );
260+
ERROR_CHECK_STATUS( vxuHarrisCorners( context, gray_scale_image, strength_thresh,
261+
min_distance, sensitivity, harris_gradient_size,
262+
harris_block_size, output_keypoint_array, NULL ) );
271263

272264
////////********
273265
// To mark the keypoints in display, you need to access the output
@@ -298,23 +290,22 @@ int main( int argc, char * argv[] )
298290
// OpenVX framework by calling vxCommitArrayRange API.
299291
// 5. Use ERROR_CHECK_STATUS for error checking.
300292
vx_size num_corners = 0;
301-
status = vxQueryArray( output_keypoint_array,
302-
VX_ARRAY_ATTRIBUTE_NUMITEMS, &num_corners, sizeof( num_corners ) );
303-
ERROR_CHECK_STATUS( status );
293+
ERROR_CHECK_STATUS( vxQueryArray( output_keypoint_array,
294+
VX_ARRAY_ATTRIBUTE_NUMITEMS,
295+
&num_corners,
296+
sizeof( num_corners ) ) );
304297
if( num_corners > 0 )
305298
{
306299
vx_size kp_stride;
307300
vx_keypoint_t * kp_buf = NULL;
308-
status = vxAccessArrayRange( output_keypoint_array, 0, num_corners,
309-
&kp_stride, ( void ** ) &kp_buf, VX_READ_ONLY );
310-
ERROR_CHECK_STATUS( status );
301+
ERROR_CHECK_STATUS( vxAccessArrayRange( output_keypoint_array, 0, num_corners,
302+
&kp_stride, ( void ** ) &kp_buf, VX_READ_ONLY ) );
311303
for( vx_size i = 0; i < num_corners; i++ )
312304
{
313305
vx_keypoint_t * kp = &vxArrayItem( vx_keypoint_t, kp_buf, i, kp_stride );
314306
gui.DrawPoint( kp->x, kp->y );
315307
}
316-
status = vxCommitArrayRange( output_keypoint_array, 0, num_corners, kp_buf );
317-
ERROR_CHECK_STATUS( status );
308+
ERROR_CHECK_STATUS( vxCommitArrayRange( output_keypoint_array, 0, num_corners, kp_buf ) );
318309
}
319310

320311
////////

tutorial_exercises/solution_exercise4/solution_exercise4.cpp

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@
4949
// Useful macros for OpenVX error checking:
5050
// ERROR_CHECK_STATUS - check status is VX_SUCCESS
5151
// ERROR_CHECK_OBJECT - check if the object creation is successful
52-
#define ERROR_CHECK_STATUS(status) { \
52+
#define ERROR_CHECK_STATUS( status ) { \
5353
vx_status status_ = (status); \
5454
if(status_ != VX_SUCCESS) { \
5555
printf("ERROR: failed with status = (%d) at " __FILE__ "#%d\n", status_, __LINE__); \
5656
exit(1); \
5757
} \
5858
}
5959

60-
#define ERROR_CHECK_OBJECT(obj) { \
60+
#define ERROR_CHECK_OBJECT( obj ) { \
6161
vx_status status_ = vxGetStatus((vx_reference)(obj)); \
6262
if(status_ != VX_SUCCESS) { \
6363
printf("ERROR: failed with status = (%d) at " __FILE__ "#%d\n", status_, __LINE__); \
@@ -601,7 +601,7 @@ int main( int argc, char * argv[] )
601601
vxChannelExtractNode( graphHarris, harris_yuv_image, VX_CHANNEL_Y, harris_luma_image ),
602602
vxGaussianPyramidNode( graphHarris, harris_luma_image, currentPyramid ),
603603
vxHarrisCornersNode( graphHarris, harris_luma_image, strength_thresh, min_distance,
604-
sensitivity, harris_gradient_size, harris_block_size, currentKeypoints, NULL )
604+
sensitivity, harris_gradient_size, harris_block_size, currentKeypoints, NULL )
605605
};
606606
for( vx_size i = 0; i < sizeof( nodesHarris ) / sizeof( nodesHarris[0] ); i++ )
607607
{
@@ -629,9 +629,9 @@ int main( int argc, char * argv[] )
629629
vxChannelExtractNode( graphTrack, opticalflow_yuv_image, VX_CHANNEL_Y, opticalflow_luma_image ),
630630
vxGaussianPyramidNode( graphTrack, opticalflow_luma_image, currentPyramid ),
631631
userPickFeaturesNode( graphTrack, previousKeypoints, previousPyramidLevel0, strength_thresh,
632-
min_distance, sensitivity, harris_gradient_size, harris_block_size, featureKeypoints ),
632+
min_distance, sensitivity, harris_gradient_size, harris_block_size, featureKeypoints ),
633633
vxOpticalFlowPyrLKNode( graphTrack, previousPyramid, currentPyramid, featureKeypoints, featureKeypoints,
634-
currentKeypoints, lk_termination, epsilon, num_iterations, use_initial_estimate, lk_window_dimension )
634+
currentKeypoints, lk_termination, epsilon, num_iterations, use_initial_estimate, lk_window_dimension )
635635
};
636636
for( vx_size i = 0; i < sizeof( nodesTrack ) / sizeof( nodesTrack[0] ); i++ )
637637
{
@@ -647,10 +647,6 @@ int main( int argc, char * argv[] )
647647
// Process the video sequence frame by frame until the end of sequence or aborted.
648648
for( int frame_index = 0; !gui.AbortRequested(); frame_index++ )
649649
{
650-
////////
651-
// local variable for checking the status of OpenVX API calls
652-
vx_status status;
653-
654650
////////
655651
// Copy the input RGB frame from OpenCV to OpenVX.
656652
// In order to do this, you need to use vxAccessImagePatch and vxCommitImagePatch APIs.
@@ -664,38 +660,32 @@ int main( int argc, char * argv[] )
664660
cv_rgb_image_layout.stride_x = 3;
665661
cv_rgb_image_layout.stride_y = gui.GetStride();
666662
vx_uint8 * cv_rgb_image_buffer = gui.GetBuffer();
667-
status = vxAccessImagePatch( input_rgb_image, &cv_rgb_image_region, 0,
668-
&cv_rgb_image_layout, ( void ** )&cv_rgb_image_buffer, VX_WRITE_ONLY );
669-
ERROR_CHECK_STATUS( status );
670-
status = vxCommitImagePatch( input_rgb_image, &cv_rgb_image_region, 0,
671-
&cv_rgb_image_layout, cv_rgb_image_buffer );
672-
ERROR_CHECK_STATUS( status );
663+
ERROR_CHECK_STATUS( vxAccessImagePatch( input_rgb_image, &cv_rgb_image_region, 0,
664+
&cv_rgb_image_layout, ( void ** )&cv_rgb_image_buffer, VX_WRITE_ONLY ) );
665+
ERROR_CHECK_STATUS( vxCommitImagePatch( input_rgb_image, &cv_rgb_image_region, 0,
666+
&cv_rgb_image_layout, cv_rgb_image_buffer ) );
673667

674668
////////********
675669
// Now that input RGB image is ready, just run a graph.
676670
// Run Harris at the beginning to initialize the previous keypoints.
677-
status = vxProcessGraph( frame_index == 0 ? graphHarris : graphTrack );
678-
ERROR_CHECK_STATUS( status );
671+
ERROR_CHECK_STATUS( vxProcessGraph( frame_index == 0 ? graphHarris : graphTrack ) );
679672

680673
////////********
681674
// To mark the keypoints in display, you need to access the output
682675
// keypoint array and draw each item on the output window using gui.DrawArrow().
683676
vx_size num_corners = 0, num_tracking = 0;
684677
currentKeypoints = ( vx_array )vxGetReferenceFromDelay( keypointsDelay, 0 );
685678
ERROR_CHECK_OBJECT( currentKeypoints );
686-
status = vxQueryArray( featureKeypoints,
687-
VX_ARRAY_ATTRIBUTE_NUMITEMS, &num_corners, sizeof( num_corners ) );
688-
ERROR_CHECK_STATUS( status );
679+
ERROR_CHECK_STATUS( vxQueryArray( featureKeypoints,
680+
VX_ARRAY_ATTRIBUTE_NUMITEMS, &num_corners, sizeof( num_corners ) ) );
689681
if( num_corners > 0 )
690682
{
691683
vx_size kp_old_stride, kp_new_stride;
692684
vx_keypoint_t * kp_old_buf = NULL, * kp_new_buf = NULL;
693-
status = vxAccessArrayRange( featureKeypoints, 0, num_corners,
694-
&kp_old_stride, ( void ** ) &kp_old_buf, VX_READ_ONLY );
695-
ERROR_CHECK_STATUS( status );
696-
status = vxAccessArrayRange( currentKeypoints, 0, num_corners,
697-
&kp_new_stride, ( void ** ) &kp_new_buf, VX_READ_ONLY );
698-
ERROR_CHECK_STATUS( status );
685+
ERROR_CHECK_STATUS( vxAccessArrayRange( featureKeypoints, 0, num_corners,
686+
&kp_old_stride, ( void ** ) &kp_old_buf, VX_READ_ONLY ) );
687+
ERROR_CHECK_STATUS( vxAccessArrayRange( currentKeypoints, 0, num_corners,
688+
&kp_new_stride, ( void ** ) &kp_new_buf, VX_READ_ONLY ) );
699689
for( vx_size i = 0; i < num_corners; i++ )
700690
{
701691
vx_keypoint_t * kp_old = &vxArrayItem( vx_keypoint_t, kp_old_buf, i, kp_old_stride );
@@ -706,10 +696,8 @@ int main( int argc, char * argv[] )
706696
gui.DrawArrow( kp_old->x, kp_old->y, kp_new->x, kp_new->y );
707697
}
708698
}
709-
status = vxCommitArrayRange( featureKeypoints, 0, num_corners, kp_old_buf );
710-
ERROR_CHECK_STATUS( status );
711-
status = vxCommitArrayRange( currentKeypoints, 0, num_corners, kp_new_buf );
712-
ERROR_CHECK_STATUS( status );
699+
ERROR_CHECK_STATUS( vxCommitArrayRange( featureKeypoints, 0, num_corners, kp_old_buf ) );
700+
ERROR_CHECK_STATUS( vxCommitArrayRange( currentKeypoints, 0, num_corners, kp_new_buf ) );
713701
}
714702

715703
////////********
@@ -744,7 +732,7 @@ int main( int argc, char * argv[] )
744732
"Harris %9d %7.3f %7.3f\n"
745733
"Track %9d %7.3f %7.3f\n",
746734
( int )perfHarris.num, ( float )perfHarris.avg * 1e-6f, ( float )perfHarris.min * 1e-6f,
747-
( int )perfTrack.num, ( float )perfTrack.avg * 1e-6f, ( float )perfTrack.min * 1e-6f );
735+
( int )perfTrack.num, ( float )perfTrack.avg * 1e-6f, ( float )perfTrack.min * 1e-6f );
748736

749737
////////********
750738
// Release all the OpenVX objects created in this exercise, and make the context as the last one to release.

0 commit comments

Comments
 (0)