/*---------------------------------------------------------------------------*/ FEATURE_SET ReadFeatureSet(FILE *File, const FEATURE_DESC_STRUCT* FeatureDesc) { /* ** Parameters: ** File open text file to read new feature set from ** FeatureDesc specifies type of feature to read from File ** Globals: none ** Operation: Create a new feature set of the specified type and read in ** the features from File. The correct text representation ** for a feature set is an integer which specifies the number (N) ** of features in a set followed by a list of N feature ** descriptions. ** Return: New feature set read from File. ** Exceptions: none ** History: Wed May 23 09:17:31 1990, DSJ, Created. */ FEATURE_SET FeatureSet; int NumFeatures; int i; if (fscanf (File, "%d", &NumFeatures) != 1 || NumFeatures < 0) DoError (ILLEGAL_NUM_FEATURES, "Illegal number of features in set"); FeatureSet = NewFeatureSet (NumFeatures); for (i = 0; i < NumFeatures; i++) AddFeature (FeatureSet, ReadFeature (File, FeatureDesc)); return (FeatureSet); } /* ReadFeatureSet */
/** * Create a new feature set of the specified type and read in * the features from File. The correct text representation * for a feature set is an integer which specifies the number (N) * of features in a set followed by a list of N feature * descriptions. * @param File open text file to read new feature set from * @param FeatureDesc specifies type of feature to read from File * @return New feature set read from File. */ FEATURE_SET ReadFeatureSet(FILE* File, const FEATURE_DESC_STRUCT* FeatureDesc) { int NumFeatures; ASSERT_HOST(tfscanf(File, "%d", &NumFeatures) == 1); ASSERT_HOST(NumFeatures >= 0); FEATURE_SET FeatureSet = NewFeatureSet(NumFeatures); for (int i = 0; i < NumFeatures; i++) AddFeature(FeatureSet, ReadFeature (File, FeatureDesc)); return FeatureSet; }
void CompareImage(char* db_image, FEATURE* feature, CvSeq* scores){ char srcpath[FLEN], srcfile[FLEN]; int length = strlen(db_image)-4; strncpy(srcpath, db_image, length); srcpath[length]='\0'; //check feature file strcpy(srcfile, srcpath); strcat(srcfile, FTR_EXT); FileWithScore score; if (Exists(srcfile)==0){ fprintf(stderr, "feature file does not exists!\n"); score.score = -1.0f; }else{ FEATURE DBFeature; ReadFeature(srcfile, &DBFeature); float queryScore = CalcSimilarity(feature->num_faces, DBFeature.num_faces, feature->histogram, DBFeature.histogram); float DBScore = CalcSimilarity( DBFeature.num_faces, feature->num_faces, DBFeature.histogram, feature->histogram); float totalScore = (feature->num_faces==0? 0 : queryScore/feature->num_faces) + (DBFeature.num_faces==0? 0:DBScore/DBFeature.num_faces); //printf("lbp score: %f\n", totalScore); if (HUELBP_ON){ float hue_queryScore = CalcSimilarity(feature->num_faces, DBFeature.num_faces, feature->histogram, DBFeature.histogram); float hue_DBScore = CalcSimilarity(DBFeature.num_faces, feature->num_faces, DBFeature.hue_histogram, feature->hue_histogram); float hue_totalScore = (feature->num_faces==0? 0 : hue_queryScore/feature->num_faces) + (DBFeature.num_faces==0? 0:hue_DBScore/DBFeature.num_faces); totalScore = 0.8*totalScore + 0.2*hue_totalScore; //printf("hue-lbp score: %f\n", hue_totalScore); } score.score = totalScore; } strcpy(srcfile, srcpath); strcat(srcfile, IMG_EXT); score.img_file = (char*)malloc(strlen(srcfile)); strcpy(score.img_file, srcfile); cvSeqPush(scores, &score); }
OGRGeoJSONLayer* OGRGeoJSONReader::ReadLayer( const char* pszName, OGRGeoJSONDataSource* poDS ) { CPLAssert( NULL == poLayer_ ); if( NULL == poGJObject_ ) { CPLDebug( "GeoJSON", "Missing parset GeoJSON data. Forgot to call Parse()?" ); return NULL; } poLayer_ = new OGRGeoJSONLayer( pszName, NULL, OGRGeoJSONLayer::DefaultGeometryType, NULL, poDS ); if( !GenerateLayerDefn() ) { CPLError( CE_Failure, CPLE_AppDefined, "Layer schema generation failed." ); delete poLayer_; return NULL; } /* -------------------------------------------------------------------- */ /* Translate single geometry-only Feature object. */ /* -------------------------------------------------------------------- */ GeoJSONObject::Type objType = OGRGeoJSONGetType( poGJObject_ ); if( GeoJSONObject::ePoint == objType || GeoJSONObject::eMultiPoint == objType || GeoJSONObject::eLineString == objType || GeoJSONObject::eMultiLineString == objType || GeoJSONObject::ePolygon == objType || GeoJSONObject::eMultiPolygon == objType || GeoJSONObject::eGeometryCollection == objType ) { OGRGeometry* poGeometry = NULL; poGeometry = ReadGeometry( poGJObject_ ); if( !AddFeature( poGeometry ) ) { CPLDebug( "GeoJSON", "Translation of single geometry failed." ); delete poLayer_; return NULL; } } /* -------------------------------------------------------------------- */ /* Translate single but complete Feature object. */ /* -------------------------------------------------------------------- */ else if( GeoJSONObject::eFeature == objType ) { OGRFeature* poFeature = NULL; poFeature = ReadFeature( poGJObject_ ); if( !AddFeature( poFeature ) ) { CPLDebug( "GeoJSON", "Translation of single feature failed." ); delete poLayer_; return NULL; } } /* -------------------------------------------------------------------- */ /* Translate multi-feature FeatureCollection object. */ /* -------------------------------------------------------------------- */ else if( GeoJSONObject::eFeatureCollection == objType ) { OGRGeoJSONLayer* poThisLayer = NULL; poThisLayer = ReadFeatureCollection( poGJObject_ ); CPLAssert( poLayer_ == poThisLayer ); } else { CPLError( CE_Failure, CPLE_AppDefined, "Unrecognized GeoJSON structure." ); delete poLayer_; return NULL; } OGRSpatialReference* poSRS = NULL; poSRS = OGRGeoJSONReadSpatialReference( poGJObject_ ); if (poSRS == NULL ) { // If there is none defined, we use 4326 poSRS = new OGRSpatialReference(); if( OGRERR_NONE != poSRS->importFromEPSG( 4326 ) ) { delete poSRS; poSRS = NULL; } poLayer_->SetSpatialRef( poSRS ); delete poSRS; } else { poLayer_->SetSpatialRef( poSRS ); delete poSRS; } // TODO: FeatureCollection return poLayer_; }