我已经将以下OpenVx Sobel即时代码转换为基于图形的代码。但结果是一致的。
即时代码工作正常,它给出了适当的结果。然而,图形代码比单个图像的即时代码“花费更长”,并且也会产生错误的结果。
所以我的转换是正确的吗?
即时代码:
/* 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");
}基于图的上述直接代码代码
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发布于 2016-06-07 14:26:51
首先,您应该检查vxVerifyGraph的结果。如下所示:
vx_status stat = vxVerifyGraph(graph);
if (stat != VX_SUCCESS)
printf("Graph failed (%d)\n", stat);
else
vxProcessGraph(graph);对于您的示例,它返回vxConvertDepthNode函数的"-4“。
vx_types.h说:
VX_ERROR_NOT_SUFFICIENT = -4,/*!< \/*表示,由于所需参数数量不足,无法自动创建所需参数,因此给定图的验证失败。这通常表示所需的原子参数。见vxVerifyGraph。*/
正确的用法是(我不记得我们是从哪里得到的):
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");
}现在vxVerifyGraph返回"-18“。
VX_ERROR_INVALID_GRAPH = -18,/*!< \/*表示提供的图具有无效的连接(循环)。*/
@jet47 47说的就是这样。您应该使用另一个图像进行输出:
if(vxConvertDepthNode(graph,intermediate3,imageOut,VX_CONVERT_POLICY_WRAP,sshift ) == 0) {
printf("ERROR failed to do color convert");
}现在它很好用。
发布于 2016-04-11 16:59:30
请检查vxVerifyGraph的返回代码。您的图形包含一个循环(image对象),这是禁止的,所以它应该在验证阶段失败。若要修复此问题,请为vxConvertDepthNode输出使用另一个图像。
https://stackoverflow.com/questions/36544717
复制相似问题