This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TDA4VM: Developing simple Use Case

Part Number: TDA4VM


Hello,

I would like to develop a simple Use Case for learning purposes.

The idea is:

 *                     *                                  |                                     |
 *                     *   image ->  fillPixelS ----->    multiply node   -----> checkPixels
 *                     *     ↓                 ↓         |               ↓                     |                 ↓
 * Pixel value:  *   none            2         |            2 x 2                   |               == 4 ??
 *     

I create two different Images and then following functions are being called by the main:

//overwrites one pixel with value
vx_status fillPixel(vx_image image,
                      const vx_imagepatch_addressing_t * addr,
                      vx_uint32 x,
                      vx_uint32 y,
                      vx_pixel_value_t fillValue
                    )
{
    vx_status status = VX_SUCCESS;
    vx_pixel_value_t *pixptr = (vx_pixel_value_t *) vxFormatImagePatchAddress2d((void*) image, x, y, addr);

    pixptr -> U8 = fillValue.U8;

    return status;
}
//overwrites u8 image with single value
vx_status fillPixelS(vx_image image,
                      vx_pixel_value_t fillValue,
                      vx_uint32 image_width,
                      vx_uint32 image_height)
{
  vx_status status = VX_SUCCESS;
  void *base_ptr = NULL;
  vx_rectangle_t rect;
  vx_uint32 plane =0;
  vx_imagepatch_addressing_t addr;
  vx_map_id map_id1;

  rect.start_x = rect.start_y = 0;
  rect.end_x = image_width;
  rect.end_y = image_height;

  status = vxMapImagePatch(image, &rect, plane, &map_id1, &addr, &base_ptr, VX_WRITE_ONLY,VX_MEMORY_TYPE_NONE,VX_NOGAP_X );

  if (status==VX_SUCCESS) {
    vx_uint32 x,y;
      for (y = 0; y < addr.dim_y; y+=addr.step_y) {
        for (x = 0; x < addr.dim_x; x+=addr.step_x) {

              if (status==VX_SUCCESS) {
                status=fillPixel(image,&addr,x,y,fillValue);
              }
              else
              {
                printf("Error fillPixelS%d \n", status);
                break;
              }
        }
      }
    }
    if (status==VX_SUCCESS){
      printf("FillPixels successful%d\n", status);
      status = vxUnmapImagePatch(image, map_id1);
    }
    else
    {
      printf("FillPixels not successful%d\n", status);

    }
    return status;
}
// checks single pixel value of a u8 image
vx_status checkPixel(vx_image image,
                  const vx_imagepatch_addressing_t * addr,
                  vx_uint32 x,
                  vx_uint32 y,
                  vx_pixel_value_t desiredValue
                )
{
  vx_status status = VX_SUCCESS;
  vx_pixel_value_t *pixptr = (vx_pixel_value_t *) vxFormatImagePatchAddress2d((void*) image, x, y, addr);

  printf("Debug real value %d\n", pixptr -> U8 );
  printf("Debug desired value %d\n", desiredValue.U8 );

  if (pixptr -> U8 == desiredValue.U8) {
    return status;
  }
  else
  {
    status = VX_FAILURE;
    return status;
  }
}
// check entire u8 image for a desired value
vx_status checkPixelS(vx_image image,
                      vx_pixel_value_t desiredValue,
                      vx_uint32 image_width,
                      vx_uint32 image_height)
{
  vx_status status = VX_SUCCESS;
  //void *base_ptr = NULL;
  vx_rectangle_t rect;
//  vx_uint32 plane =0;
  vx_imagepatch_addressing_t addr;
  //vx_map_id map_id1;

  rect.start_x = rect.start_y = 0;
  rect.end_x = image_width;
  rect.end_y = image_height;

  printf("Debug=1 %d\n",status);
  //status = vxMapImagePatch(image, &rect, plane, &map_id1, &addr, &base_ptr, VX_READ_AND_WRITE,VX_MEMORY_TYPE_NONE,VX_NOGAP_X );
  printf("Debug=2 %d\n",status);


  if (status==VX_SUCCESS) {
    vx_uint32 x,y;
      for (y = 0; y < addr.dim_y; y+=addr.step_y) {

        if (status!=VX_SUCCESS) {
          break;
        }
        for (x = 0; x < addr.dim_x; x+=addr.step_x) {

              if (status==VX_SUCCESS) {
                status=checkPixel(image,&addr,x,y,desiredValue);
              }
              else
              {
                printf("Error checkPixelS0x%x \n", status);
                break;
              }
        }
      }
    }
    return status;
}


// node which mulitplies single pixel values with themselves
vx_status app_create_multiply(AppObj *obj){

  vx_status status = VX_SUCCESS;

  vx_float32 scalarValue = 2.0;

  obj->scale = vxCreateScalar(obj->context,VX_TYPE_FLOAT32,&scalarValue);
  status = vxGetStatus((vx_reference) obj->scale);

  // elementwise multiplication
  if (status==VX_SUCCESS) {
    printf("scale created\n" );
  }
  else
  {
    printf("scale not created\n" );
  }

  // elementwise multiplication
  obj->node_multiply = vxMultiplyNode(
                                  obj->graph,
                                  obj->image,
                                  obj->image,
                                  obj->scale,
                                  VX_CONVERT_POLICY_WRAP,
                                  VX_ROUND_POLICY_TO_ZERO,
                                  obj->multiplied_image
                );
  status = vxGetStatus((vx_reference) obj->node_multiply);
  if (status==VX_SUCCESS) {
    printf("node_multiply created\n" );
  }
  else
  {
    printf("node_multiply not created\n" );
  }


  return status;
}

When I run my app I get this error message:

78.794255 s:  VX_ZONE_ERROR:[vxUnmapImagePatch:2038] invalid image reference

I don't know why. Where are the bugs?

Best regards,

Daniel