OpenVX scale does not work


#1

Hello,
I’m trying to scale a grayscale image on my NVIDIA Jetson TX2 GPU, however if I use the pyramid function I always get a blank gray image (a value of 204 at all pixels) and if I use the scale function my program crashes.
What am I doing wrong? Here is my code (I need to write it in C but if you have an answer only in C++ it is also welcomed):

void resize_frame(char *input_file, char *output_file, float scaleRatio)
{
IplImage *img = cvLoadImage(input_file,1);
IplImage *img2 = cvCreateImage(cvSize(img->width,img->height), IPL_DEPTH_8U, 1);
cvCvtColor(img,img2,7);

 vx_context vxContext = vxCreateContext();
 void *ptr = &(img2->imageData[0]);
 vx_imagepatch_addressing_t addr;
 addr.dim_x = img2->width;
 addr.dim_y = img2->height;
 addr.stride_x = sizeof(vx_uint8);
 addr.stride_y = addr.stride_x * addr.dim_x;
 addr.step_x = 1;
 addr.step_y = 1;
 vx_image vxImg = vxCreateImageFromHandle(vxContext,VX_DF_IMAGE_U8,&addr,ptr,VX_IMPORT_TYPE_HOST);

 int outW = (int)(img2->width * scaleRatio);
 int outH = (int)(img2->height * scaleRatio);

 if(1) 
 {
	vx_pyramid pyr = vxCreatePyramid(vxContext, 2, scaleRatio, img2->width, img2->height, VX_DF_IMAGE_U8);
	vx_image vxOutImg = vxGetPyramidLevel(pyr,1);
 }
 else 
 {
	vx_image vxOutImg = vxCreateImage(vxContext,outW,outH,VX_DF_IMAGE_U8);
	vxuScaleImage(vxContext,vxImg,vxOutImg,VX_INTERPOLATION_TYPE_BILINEAR);	
 }

 IplImage *outImg = cvCreateImage(cvSize(outW,outH), IPL_DEPTH_8U, 1);
 void *ptr1= NULL;
 vx_imagepatch_addressing_t addr1;
 vx_rectangle_t rect1 = {0u,0u,outW,outH};
 vxAccessImagePatch(vxOutImg, &rect1, 0, &addr1, &ptr1 ,VX_READ_ONLY);

 outImg->imageData = ptr1;
 cvSaveImage(output_file,outImg,0);
 vxReleaseImage(vxImg);
 vxReleaseImage(vxOutImg);
 cvReleaseImage(&img);
 cvReleaseImage(&img2);
 cvReleaseImage(&outImg);

}

Thank you,
Haggai


#2

Looks like the pyramid was created without any operation to compute into the pyramid object.


#3

Thanks for the answer and sorry if I make such simple mistakes, I’m totally new to openVX. But why does it crash if I use the vxuScaleImage function?


#4

I see one more problem with this code. The ptrs argument for vxCreateImageFromHandle is incorrect.
See https://www.khronos.org/registry/OpenVX/specs/1.1/html/df/d09/group__group__image.html#ga5abb694617a79024621e3ba95237a109
You need to pass &ptr instead of ptr.