コード例 #1
0
ファイル: hat.cpp プロジェクト: GianpaoloR/polyphemus
static inline void InitIndices(
    vec_int&    row_indices,    // out
    vec_double& row_fracs,      // out
    vec_int&    col_indices,    // out
    vec_double& col_fracs,      // out
    vec_double& pixelweights,   // out
    const int   patchwidth)     // in: in pixels
{
    CV_Assert(patchwidth % 2 == 1); // patchwidth must be odd in this implementation

    const int npix = SQ(patchwidth); // number of pixels in image patch

    row_indices.resize(npix);
    row_fracs.resize(npix);
    col_indices.resize(npix);
    col_fracs.resize(npix);
    pixelweights.resize(npix);

    const int halfpatchwidth = (patchwidth-1) / 2;

    const double grid_rows_per_img_row = GRIDHEIGHT / (patchwidth-1.);
    const double row_offset = GRIDHEIGHT / 2. - .5; // see header comment

    const double grid_cols_per_img_col = GRIDWIDTH / (patchwidth-1.);
    const double col_offset = GRIDWIDTH / 2. - .5;

    // downweight at border of patch is exp(-1 / (2 * WINDOW_SIGMA))
    const double weight = -1 / (WINDOW_SIGMA * GRIDHEIGHT * GRIDWIDTH );

    int ipix = 0;

    for (double patchrow = -halfpatchwidth; patchrow <= halfpatchwidth; patchrow++)
    {
        const double signed_row = patchrow * grid_rows_per_img_row;
        const double row        = signed_row + row_offset;
        const int irow          = int(floor(row));
        const double row_frac   = row - irow;

        CV_DbgAssert(row >= -.5 && row <= GRIDHEIGHT - .5); // same applies to col below

        for (double patchcol = -halfpatchwidth; patchcol <= halfpatchwidth; patchcol++)
        {
            row_indices[ipix] = irow;
            row_fracs[ipix]   = row_frac;

            const double signed_col = patchcol * grid_cols_per_img_col;
            const double col        = signed_col + col_offset;
            const int icol          = int(floor(col));

            col_indices[ipix] = icol;
            col_fracs[ipix]   = col - icol;

            pixelweights[ipix] = // TODO this weights col and row offsets equally
                exp(weight * (SQ(signed_row) + SQ(signed_col)));

            ipix++;
        }
    }
}
コード例 #2
0
static void NbrUsedPointsVec(   // nbr of used points in each shape
    vec_int&         nused_vec, // out: vec [nshapes] of int
    const vec_Shape& shapes)    // in
{
    nused_vec.resize(NSIZE(shapes));
    for (int ishape = 0; ishape < NSIZE(shapes); ishape++)
        nused_vec[ishape] = NbrUsedPoints(shapes[ishape]);
}
コード例 #3
0
ファイル: matvec.cpp プロジェクト: GuillaumeGibert/swooz
StasmMat FindMatInFile (const char sFile[],  // in
                   char *psImageDirs[], // out: directories in shape file if any, optional
                   const char sRegex[], // in: can be null
                   unsigned Mask0,      // in
                   unsigned Mask1)      // in
{
static char       sFile1[SLEN]; // the mat file name
static char       sImageDirs[SLEN];
static vec_Mat    MatV;         // the matrices read in from the file
static vec_string Tags;         // the tags (i.e. string before each mat in the file)
static vec_int    TagInts;      // hex number at start of each of above tags

// iMat is static so we start where we finished last time, which means that
// searches are fast if this function is invoked for matrices in order
// It also means with multiple matches to sRegex, succesive matching shapes
// are returned each time this function is called.

static unsigned iMat;

if (strcmp(sFile, sFile1))  // first time (for this file)?
    {
    // initialize the static variables

    strcpy(sFile1, sFile);
    iMat = 0;
    // read all shapes, we will filter the one we want later
    ReadShapeFile(MatV, Tags, sImageDirs, NULL, 0, 0, sFile);
    TagInts.resize(MatV.size());
    for (size_t i = 0; i < MatV.size(); i++)
        {
        char const *s = Tags[i].c_str();
        unsigned n;
        if (1 != sscanf(s, "%x", &n))
            Err("can't convert tag %s in %s to a hex number", s, sFile);
        TagInts[i] = n;
        }
    }
// regcomp flags: egrep style expression (supports |),
// ignore case, use simple failure reporting in regexec

// regex_t CompiledRegex;
// if (0 != regcomp(&CompiledRegex, sRegex, REG_EXTENDED|REG_ICASE|REG_NOSUB))
    // Err("invalid regular expression %s", sRegex);

size_t i;
for (i = 0; i < MatV.size(); i++)
    {
    if (fMatchAttr(TagInts[iMat], Mask0, Mask1))
	    // && // filter first on attributes
        // fRegexMatch(CompiledRegex, sGetBasenameFromTag(Tags[iMat])))
        {
        break;                  // found
        }
    iMat++;
    if (iMat >= MatV.size())
        iMat = 0;               // wrap
    }
// regfree(&CompiledRegex);

if (psImageDirs)
    *psImageDirs = sImageDirs;

StasmMat m;                          // returned matrix
if (i < MatV.size())            // found?
    m = MatV[iMat];

return m;
}