rapp-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Rapp-users] RAPP Examples


From: Mikael Asker
Subject: Re: [Rapp-users] RAPP Examples
Date: Mon, 14 Oct 2013 20:36:43 +0200

Here is an incomplete but hopefully useful example, an 
edited part of working code that should get you started.  
This code splits an image into connected component 
segments.  I can not answer any questions about the 
details outside RAPP, they are part of our closed source 
higher level libraries.  We should probably make a complete 
documented example from this.

We use this sequence of RAPP calls to extract one segment :

  rapp_pad_align_bin                       Clear all alignment padding, 
required by rapp_crop_seek_bin()
  rapp_crop_seek_bin                       Check if there are any more set 
pixels
  rapp_pixop_set_u8                        Clear the object buffer
  rapp_fill_4conn_bin rapp_fill_8conn_bin  Perform seed fill
  rapp_crop_box_bin                        Compute the bounding box
  rapp_bitblt_andn_bin                     Remove the object from the map image

Mikael A.


{
    int ret = 0;
    
    int (*fill)(uint8_t *, int, const uint8_t *, 
                int, int, int, int, int);
    
    ...
    uint8_t    *map_buf;
    uint8_t    *obj_buf;
    unsigned    pos[2];
    int         dim;
    int         width;
    int         height;
    int         lod;
    int         row = 0;
    int         idx = 0;
    int         cnt = 0;
    int         write_index;

    ...

    SLIST_TYPE(list_elem_t) comp_list = SLIST_INITIALIZER;
    
    /* Validate the arguments */
    ...

    /* Set the seed fill function based on the connectivity mode */
    switch (conn) {
        case AV_CONN_4:
            fill = &rapp_fill_4conn_bin;
            break;

        case AV_CONN_8:
            fill = &rapp_fill_8conn_bin;
            break;

        default:
            goto Fail;
    }

    ...

    /* Create the map and object images */
    ...
     
    /* Get pixel buffer parameters */
    ...
    
    while (len == 0 || cnt < len) {
        ...
        unsigned     vec[4];       
        list_elem_t *list_elem;

        /* Clear all alignment padding, required by rapp_crop_seek_bin() */
        ret = rapp_pad_align_bin(&map_buf[idx], dim, 0,
                                 width, height - row, 0);
        if (ret < 0) {
            ERR("rapp_pad_align_bin failed");
            assert(false);
        }

        /* Check if there are any more set pixels */
        if (rapp_crop_seek_bin(&map_buf[idx], dim,
                               width, height - row, pos) == 0)
        {
            break;
        }
        
        /* Update the current row and buffer index */
        row += pos[1];
        idx += pos[1]*dim;

        /* Clear the object buffer */
        rapp_pixop_set_u8(&obj_buf[idx], 0, dim*(height - row), 1, 0);
        
        /* Perform seed fill */
        (*fill)(&obj_buf[idx], dim, &map_buf[idx], dim,
                width, height - row, pos[0], 0);
        
        /* Compute the bounding box */
        ret = rapp_crop_box_bin(&obj_buf[idx], dim,
                                width, height - row, vec);
        if (ret < 0) {
            ERR("rapp_crop_box_bin failed");
            assert(false);
        }
        
        /* Remove the object from the map image */
        rapp_bitblt_andn_bin(&map_buf[idx], dim, 0,
                             &obj_buf[idx], dim, 0,
                             width, vec[3]);

        /* Compute the object bounding box in the original image */
        box.xpos   = vec[0];
        box.ypos   = row;
        box.width  = vec[2];
        box.height = vec[3];
        assert((int)box.xpos  >= 0     && (int)box.ypos   >= 0 &&
               (int)box.width <= width && (int)box.height <= height);
        
        /* Save the object in a new image */
        ...
        
        /* Store the object destination image in the output buffer */
        ...
        cnt++;
    }

    /* Delete intermediate images */
    ...

    /* Create the output array */
    ...
    return cnt;

Fail:
    return -1;
}


________________________________________
From: address@hidden address@hidden On Behalf Of Hans-Peter Nilsson 
address@hidden
Sent: Monday, October 14, 2013 5:06 PM
To: address@hidden
Cc: address@hidden
Subject: Re: [Rapp-users] RAPP Examples

> From: Vincenzo Carletti <address@hidden>
> Date: Mon, 7 Oct 2013 10:33:22 +0200

> Good morning,
> I'm starting to use RAPPLib on AXIS camera, but i have some problems cause
> there are no examples or howtos.

I agree more examples would help.

> I need to perform a connected component search inside a frame extrated from
> the camera.
> How can i use RAPP to obtain this aim?

As I haven't used the functions myself (I'm just the janitor)
unfortunately I don't have any better answer than what I believe
you've found by yourself browsing sources and the documentation:
(Though arguable the code in the test-suite doesn't serve being
an example here.)

Starting with an image of unknown topology (or processed to
likely contain shapes want to further investigate), with N being
4 or 8 for the connectivity, iterate, use rapp_contour_Nconn_bin
to get each shape, then rapp_fill_Nconn_bin to fill it, to
prepare for the next call to rapp_contour_Nconn_bin.  Repeat
until an empty contour string is returned.

brgds, H-P



reply via email to

[Prev in Thread] Current Thread [Next in Thread]