Custom Concolution (vxConvolveNode)

Hello everyone ,

I do not understand why i can’t do a simpel covolution (i newby in this framework) please i have some help

i did a simple function called like that :

vx_image vxSrc1 ; //init with a loaded image 3channel
vx_image vxOutBlur;
convol1(context,vxContext , vxSrc1 , vxOutBlur)

void colorBlur(vx_context m_vxCtx, vx_image& vxiSrc, vx_image& vxiOut)
{
vx_uint32 width = 0, height = 0;
vx_uint32 colorFormat=0;

NVXIO_SAFE_CALL( vxQueryImage(vxiSrc, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width)) );
NVXIO_SAFE_CALL( vxQueryImage(vxiSrc, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height)) );
NVXIO_SAFE_CALL( vxQueryImage(vxiSrc, VX_IMAGE_ATTRIBUTE_FORMAT, &colorFormat, sizeof(colorFormat)) );

vxiOut = vxCreateImage(m_vxCtx, width, height, VX_DF_IMAGE_RGB);
vx_image vxr = vxCreateImage(m_vxCtx, width, height, VX_DF_IMAGE_U8);
vx_image vxg = vxCreateImage(m_vxCtx, width, height, VX_DF_IMAGE_U8);
vx_image vxb = vxCreateImage(m_vxCtx, width, height, VX_DF_IMAGE_U8);

vx_status status1 = vxuChannelExtract(m_vxCtx, vxiSrc, VX_CHANNEL_R, vxr);
vx_status status2 = vxuChannelExtract(m_vxCtx, vxiSrc, VX_CHANNEL_G, vxg);
vx_status status3 = vxuChannelExtract(m_vxCtx, vxiSrc, VX_CHANNEL_B, vxb);

std::cout<<" Status color1: "<<status1;
std::cout<<" Status color2: "<<status2;
std::cout<<" Status color3: "<<status3<<"\n";

vx_graph graph = vxCreateGraph(m_vxCtx);

vx_image virt_U8R        = vxCreateVirtualImage(graph, width,height , VX_DF_IMAGE_U8);
vx_image virt_U8G        = vxCreateVirtualImage(graph, 0, 0, VX_DF_IMAGE_U8);
vx_image virt_U8B        = vxCreateVirtualImage(graph, 0, 0, VX_DF_IMAGE_U8);

/// Gaussian Blur

vx_int16 kernel[3][3]={{1,2,1},{2,4,2},{1,2,1}};
vx_uint32 scale=16; // sum of kernel

vx_convolution conv_k= vxCreateConvolution(m_vxCtx,3,3);
vxCopyConvolutionCoefficients(conv_k,&kernel,VX_WRITE_ONLY,VX_MEMORY_TYPE_HOST);
vxSetConvolutionAttribute(conv_k,VX_CONVOLUTION_SCALE,&scale,sizeof(scale));

vx_node nodeConv1=vxConvolveNode(graph,vxr, conv_k,virt_U8R);
vx_status statusConv1=vxGetStatus((vx_reference)nodeConv1);
std::cout<<" Status convR: "<<statusConv1<<"\n";

vx_node nodeConv2=vxConvolveNode(graph,vxg, conv_k,virt_U8G);
vx_status statusConv2=vxGetStatus((vx_reference)nodeConv1);
std::cout<<" Status convG: "<<statusConv2<<"\n";

vx_node nodeConv3=vxConvolveNode(graph,vxb, conv_k,virt_U8B);
vx_status statusGraf= vxSetGraphAttribute(graph, NVX_GRAPH_VERIFY_OPTIONS, "-O3", strlen("-O3")) ;
std::cout<<" Status convG: "<<statusConv2<<"\n";


vx_status statusConv = vxVerifyGraph(graph);
std::cout<<" Status convB: "<<statusConv<<"\n";

///////////////testSplit cannal split ////////////
 cv::Mat cvr = cv::Mat(height,width, CV_8UC1);
VX2MatC1(m_vxCtx, virt_U8R, cvr); // based on https://forums.developer.nvidia.com/t/convert-vx-image-to-cv-mat/58737
cv::imwrite("cvR2Bis.jpg",cvr);

vx_status status = vxuChannelCombine(m_vxCtx, virt_U8B, virt_U8G, virt_U8R, NULL, vxiOut);

}

I also test with nxuConvolve() but despit the status 0 the image convolve is not applied

thanks for your help

Hi,

Thanks for your question.

Have you checked our VisionWorks document for usage first?

Thanks.

1 Like

Thanks @AastaLLL for this code i based on the documentation ( http://gis.gha-engineers.com/pub/visionworks/nvvwx_docs/group__group__vision__function__custom__convolution.html )

Someone have clue why my convolution does’nt work?

Hi,

Sorry for the late update.

Could you share the return vx_status value with us?
If the vx_state value is 0, it indicates the convolution is applied without error.
http://gis.gha-engineers.com/pub/visionworks/nvvwx_docs/vx__types_8h_source.html

  387 enum vx_status_e {
  388     VX_STATUS_MIN                       = -25,
  389     /* add new codes here */
  390     VX_ERROR_REFERENCE_NONZERO          = -24,
  391     VX_ERROR_MULTIPLE_WRITERS           = -23,
  392     VX_ERROR_GRAPH_ABANDONED            = -22,
  393     VX_ERROR_GRAPH_SCHEDULED            = -21,
  394     VX_ERROR_INVALID_SCOPE              = -20,
  395     VX_ERROR_INVALID_NODE               = -19,
  396     VX_ERROR_INVALID_GRAPH              = -18,
  397     VX_ERROR_INVALID_TYPE               = -17,
  398     VX_ERROR_INVALID_VALUE              = -16,
  399     VX_ERROR_INVALID_DIMENSION          = -15,
  400     VX_ERROR_INVALID_FORMAT             = -14,
  401     VX_ERROR_INVALID_LINK               = -13,
  402     VX_ERROR_INVALID_REFERENCE          = -12,
  403     VX_ERROR_INVALID_MODULE             = -11,
  404     VX_ERROR_INVALID_PARAMETERS         = -10,
  405     VX_ERROR_OPTIMIZED_AWAY             = -9,
  406     VX_ERROR_NO_MEMORY                  = -8,
  407     VX_ERROR_NO_RESOURCES               = -7,
  408     VX_ERROR_NOT_COMPATIBLE             = -6,
  409     VX_ERROR_NOT_ALLOCATED              = -5,
  410     VX_ERROR_NOT_SUFFICIENT             = -4,
  411     VX_ERROR_NOT_SUPPORTED              = -3,
  412     VX_ERROR_NOT_IMPLEMENTED            = -2,
  413     VX_FAILURE                          = -1,
  414     VX_SUCCESS                          =  0,
  415 };

Thanks.