示例#1
0
void DynamicRawFeature::upgrade_feature_type(const char * value)
{
    // This ascertains that the value is a number
    parse_string<float>(value);
    
    // Find a suitable type for the feature
    int current_type_level = static_cast<int>(this->type);
    int potential_type = current_type_level + 1;
    while (potential_type <= static_cast<int>(MAX_RAW_FEATURE_TYPE) ) {
        try {
            std::unique_ptr<ColumnConsumer> test_type(this->create_raw_feature_for_type(static_cast<RawFeatureType>(potential_type)));
            test_type->consume_cell(value);
            test_type->consume_cell(this->feature->get_min_str().c_str());
            test_type->consume_cell(this->feature->get_max_str().c_str());
            break;
        } catch (number_format_error& e) {
            (void)e;
            potential_type++;
        } 
    }
    if (potential_type > static_cast<int>(MAX_RAW_FEATURE_TYPE)) {
        throw std::runtime_error(std::string("Cannot parse value in tsv file as number: ") + value);
    }
    RawFeatureType new_feature_type = static_cast<RawFeatureType>(potential_type);
    
    // Convert the feature
    std::unique_ptr<AbstractRawFeature> new_feature(this->create_raw_feature_for_type(new_feature_type));
    new_feature->import_data(this->feature->export_data().get());
    this->feature = std::move(new_feature);
}
示例#2
0
文件: sift.c 项目: vabc3/KarCv
/*
   Interpolates a scale-space extremum's location and scale to subpixel
   accuracy to form an image feature.  Rejects features with low contrast.
   Based on Section 4 of Lowe's paper.  

   @param dog_pyr DoG scale space pyramid
   @param octv feature's octave of scale space
   @param intvl feature's within-octave interval
   @param r feature's image row
   @param c feature's image column
   @param intvls total intervals per octave
   @param contr_thr threshold on feature contrast

   @return Returns the feature resulting from interpolation of the given
   parameters or NULL if the given location could not be interpolated or
   if contrast at the interpolated loation was too low.  If a feature is
   returned, its scale, orientation, and descriptor are yet to be determined.
   */
static struct feature* interp_extremum( IplImage*** dog_pyr, int octv,
		int intvl, int r, int c, int intvls,
		double contr_thr )
{
	struct feature* feat;
	struct detection_data* ddata;
	double xi, xr, xc, contr;
	int i = 0;

	while( i < SIFT_MAX_INTERP_STEPS )
	{
		interp_step( dog_pyr, octv, intvl, r, c, &xi, &xr, &xc );
		if( ABS( xi ) < 0.5  &&  ABS( xr ) < 0.5  &&  ABS( xc ) < 0.5 )
			break;

		c += cvRound( xc );
		r += cvRound( xr );
		intvl += cvRound( xi );

		if( intvl < 1  ||
				intvl > intvls  ||
				c < SIFT_IMG_BORDER  ||
				r < SIFT_IMG_BORDER  ||
				c >= dog_pyr[octv][0]->width - SIFT_IMG_BORDER  ||
				r >= dog_pyr[octv][0]->height - SIFT_IMG_BORDER )
		{
			return NULL;
		}

		i++;
	}

	/* ensure convergence of interpolation */
	if( i >= SIFT_MAX_INTERP_STEPS )
		return NULL;

	contr = interp_contr( dog_pyr, octv, intvl, r, c, xi, xr, xc );
	if( ABS( contr ) < contr_thr / intvls )
		return NULL;

	feat = new_feature();
	ddata = feat_detection_data( feat );
	feat->img_pt.x = feat->x = ( c + xc ) * pow( 2.0, octv );
	feat->img_pt.y = feat->y = ( r + xr ) * pow( 2.0, octv );
	ddata->r = r;
	ddata->c = c;
	ddata->octv = octv;
	ddata->intvl = intvl;
	ddata->subintvl = xi;

	return feat;
}
示例#3
0
/*
Makes a deep copy of a feature

@param feat feature to be cloned

@return Returns a deep copy of feat
*/
struct feature* clone_feature( struct feature* feat )
{
	struct feature* new_feat;
	struct detection_data* ddata;

	new_feat = new_feature();
	ddata = feat_detection_data( new_feat );
	memcpy( new_feat, feat, sizeof( struct feature ) );
	memcpy( ddata, feat_detection_data(feat), sizeof( struct detection_data ) );
	new_feat->feature_data = ddata;

	return new_feat;
}
示例#4
0
/*
Makes a deep copy of a feature
@param feat feature to be cloned
@return Returns a deep copy of feat
*/
static struct feature* clone_feature( struct feature* feat )
{
	struct feature* new_feat;
	struct detection_data* ddata;

    //为一个feature结构分配空间并初始化
    new_feat = new_feature();
    //调用宏feat_detection_data来提取参数feat中的feature_data成员并转换为detection_data类型的指针
	ddata = feat_detection_data( new_feat );
    //对内存空间进行赋值
	memcpy( new_feat, feat, sizeof( struct feature ) );
	memcpy( ddata, feat_detection_data(feat), sizeof( struct detection_data ) );
	new_feat->feature_data = ddata;

    return new_feat;//返回克隆生成的特征点的指针
}
示例#5
0
文件: mpm_tests.c 项目: tidatida/mpm
int main(int argc, char* argv[])
{
    int test;

    if (argc >= 2 && argv[1][0] == '-') {
        test = atoi(argv[1] + 1);
        if (test >= 1 && test <= MAX_TESTS) {
            tests[test - 1]();
            return test_failed;
        }

        printf("Test case id must be between 1 and %d\n", MAX_TESTS);
        return 1;
    }

    printf("Trying a new feature.\n\n");
    new_feature();

    return test_failed;
}
示例#6
0
/*
Interpolates a scale-space extremum's location and scale to subpixel
accuracy to form an image feature.  Rejects features with low contrast.
Based on Section 4 of Lowe's paper.  
@param dog_pyr DoG scale space pyramid
@param octv feature's octave of scale space
@param intvl feature's within-octave interval
@param r feature's image row
@param c feature's image column
@param intvls total intervals per octave
@param contr_thr threshold on feature contrast
@return Returns the feature resulting from interpolation of the given
	parameters or NULL if the given location could not be interpolated or
	if contrast at the interpolated loation was too low.  If a feature is
	returned, its scale, orientation, and descriptor are yet to be determined.
*/
static struct feature* interp_extremum( IplImage*** dog_pyr, int octv, int intvl,
										int r, int c, int intvls, double contr_thr )
{
    struct feature* feat;//修正后的特征点
    struct detection_data* ddata;//与特征检测有关的结构,存在feature结构的feature_data成员中
    double xi, xr, xc, contr;//xi,xr,xc分别为亚像素的intvl(层),row(y),col(x)方向上的增量(偏移量)
    int i = 0;//插值次数

    //SIFT_MAX_INTERP_STEPS指定了关键点的最大插值次数,即最多修正多少次,默认是5
	while( i < SIFT_MAX_INTERP_STEPS )
	{
        //进行一次极值点差值,计算σ(层方向,intvl方向),y,x方向上的子像素偏移量(增量)
		interp_step( dog_pyr, octv, intvl, r, c, &xi, &xr, &xc );
        //若在任意方向上的偏移量大于0.5时,意味着差值中心已经偏移到它的临近点上,所以必须改变当前关键点的位置坐标
        if( ABS( xi ) < 0.5  &&  ABS( xr ) < 0.5  &&  ABS( xc ) < 0.5 )//若三方向上偏移量都小于0.5,表示已经够精确,则不用继续插值
			break;

        //修正关键点的坐标,x,y,σ三方向上的原坐标加上偏移量取整(四舍五入)
        c += cvRound( xc );//x坐标修正
        r += cvRound( xr );//y坐标修正
        intvl += cvRound( xi );//σ方向,即层方向

        //若坐标修正后超出范围,则结束插值,返回NULL
        if( intvl < 1  ||           //层坐标插之后越界
			intvl > intvls  ||
            c < SIFT_IMG_BORDER  ||   //行列坐标插之后到边界线内
			r < SIFT_IMG_BORDER  ||
			c >= dog_pyr[octv][0]->width - SIFT_IMG_BORDER  ||
			r >= dog_pyr[octv][0]->height - SIFT_IMG_BORDER )
		{
			return NULL;
		}

		i++;
	}

    //若经过SIFT_MAX_INTERP_STEPS次插值后还没有修正到理想的精确位置,则返回NULL,即舍弃此极值点
	if( i >= SIFT_MAX_INTERP_STEPS )
		return NULL;

    //计算被插值点的对比度:D + 0.5 * dD^T * X
	contr = interp_contr( dog_pyr, octv, intvl, r, c, xi, xr, xc );
    if( ABS( contr ) < contr_thr / intvls )//若该点对比度过小,舍弃,返回NULL
		return NULL;

    //为一个特征点feature结构分配空间并初始化,返回特征点指针
	feat = new_feature();
    //调用宏feat_detection_data来提取参数feat中的feature_data成员并转换为detection_data类型的指针
	ddata = feat_detection_data( feat );

    //将修正后的坐标赋值给特征点feat
    //原图中特征点的x坐标,因为第octv组中的图的尺寸比原图小2^octv倍,所以坐标值要乘以2^octv
    feat->img_pt.x = feat->x = ( c + xc ) * pow( 2.0, octv );
    //原图中特征点的y坐标,因为第octv组中的图的尺寸比原图小2^octv倍,所以坐标值要乘以2^octv
	feat->img_pt.y = feat->y = ( r + xr ) * pow( 2.0, octv );

    ddata->r = r;//特征点所在的行
    ddata->c = c;//特征点所在的列
    ddata->octv = octv;//高斯差分金字塔中,特征点所在的组
    ddata->intvl = intvl;//高斯差分金字塔中,特征点所在的组中的层
    ddata->subintvl = xi;//特征点在层方向(σ方向,intvl方向)上的亚像素偏移量

    return feat;//返回特征点指针
}