OpenVx immediate code and Graphs not giving similar results

橙三吉。 提交于 2019-12-23 04:39:09

问题


I have converted the following OpenVx Sobel immediate code to Graph based . But the results done match.

Immediate code works fine, it gives proper result. Whereas Graph code takes "longer" than the immediate code for a single image and produces wrong results too.

So is my conversion correct ?

Immediate Code :

/* Intermediate images. */
  vx_image dx = vxCreateImage(context, width, height, VX_DF_IMAGE_S16);
  vx_image dy = vxCreateImage(context, width, height, VX_DF_IMAGE_S16);
  vx_image mag = vxCreateImage(context, width, height, VX_DF_IMAGE_S16);


      /* Perform Sobel convolution. */
      if (vxuSobel3x3(context,image,dx, dy)!=VX_SUCCESS)
      {
        printf("ERROR: failed to do sobel!\n");
      }

      /* Calculate magnitude from gradients. */
      if (vxuMagnitude(context,dx,dy,mag)!=VX_SUCCESS)
      {
        printf("ERROR: failed to do magnitude!\n");
      }

       //Convert result back to U8 image. 
      if (vxuConvertDepth(context,mag,image,VX_CONVERT_POLICY_WRAP,0)!=VX_SUCCESS)
      {
        printf("ERROR: failed to do color convert!\n");
      }

Graph based code of the above immediate code

vx_graph graph = vxCreateGraph( context );
  vx_image intermediate1 = vxCreateVirtualImage( graph, width, height, VX_DF_IMAGE_S16 );
  vx_image intermediate2 = vxCreateVirtualImage( graph, width, height, VX_DF_IMAGE_S16 );
  vx_image intermediate3 = vxCreateVirtualImage( graph, width, height, VX_DF_IMAGE_S16 );

  if(vxSobel3x3Node(graph,image,intermediate1,intermediate2) == 0)
  {
    printf("FAILED TO Create 1 graph node");
  }

  if(vxMagnitudeNode(graph,intermediate1,intermediate2,intermediate3) == 0)
  {
      printf("ERROR: failed to do magnitude!\n");
  }

  if(vxConvertDepthNode(graph,intermediate3,image,VX_CONVERT_POLICY_WRAP,0) == 0)
  {
    printf("ERROR failed to do color convert");
  }

  vxVerifyGraph( graph );

  vxProcessGraph( graph ); // run in a loop

回答1:


At first, you should inspect the result of the vxVerifyGraph. Like this:

vx_status stat = vxVerifyGraph(graph);
if (stat != VX_SUCCESS)
    printf("Graph failed (%d)\n", stat);
else
    vxProcessGraph(graph);

For your example it returns "-4" for the vxConvertDepthNode function.

vx_types.h says:

VX_ERROR_NOT_SUFFICIENT = -4, /*!< \brief Indicates that the given graph has failed verification due to an insufficient number of required parameters, which cannot be automatically created. Typically this indicates required atomic parameters. \see vxVerifyGraph. */

The proper use is (I don't remember where we got it):

vx_int32 shift = 0;
vx_scalar sshift = vxCreateScalar(context, VX_TYPE_INT32, &shift);
if(vxConvertDepthNode(graph,intermediate3,image,VX_CONVERT_POLICY_WRAP,sshift) == 0)  {
   printf("ERROR failed to do color convert");
}

Now vxVerifyGraph returns "-18".

VX_ERROR_INVALID_GRAPH = -18, /*!< \brief Indicates that the supplied graph has invalid connections (cycles). */

That's what about @jet47 says. You should use another image for output:

if(vxConvertDepthNode(graph,intermediate3,imageOut,VX_CONVERT_POLICY_WRAP,sshift ) == 0)  {
   printf("ERROR failed to do color convert");
}

Now it works fine.




回答2:


Please check return code of vxVerifyGraph. You graph contains a loop (image object), which is forbidden, so it should fail on verification stage. To fix this use another image for vxConvertDepthNode output.



来源:https://stackoverflow.com/questions/36544717/openvx-immediate-code-and-graphs-not-giving-similar-results

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!