Exemplo n.º 1
0
Plains::Plains(int x, int  y)
    : Tile(x, y, 2, 14, 1,  false, false, 0.0,
        Yield(1, 1, 0), "Plains") {
    this->features_on = new Feature[10];
    this->resources_on = new Resource[15];

    // Setting up available features
    this->features_on[0] = Feature(Feature::Jungle);
    this->features_on[1] = Feature(Feature::Forest);
    this->features_on[2] = Feature(Feature::BarringerCrater);
    this->features_on[3] = Feature(Feature::MtFuji);
    this->features_on[4] = Feature(Feature::GrandMesa);
    this->features_on[5] = Feature(Feature::RockGibraltar);
    this->features_on[6] = Feature(Feature::OldFaithful);
    this->features_on[7] = Feature(Feature::FountainOfYouth);
    this->features_on[8] = Feature(Feature::CorroDePotosi);
    this->features_on[9] = Feature(Feature::ElDorado);

    // Setting up available resources
    this->resources_on[0] = Resource(Resource::Iron);
    this->resources_on[1] = Resource(Resource::Horses);
    this->resources_on[2] = Resource(Resource::Aluminum);
    this->resources_on[3] = Resource(Resource::Uranium);
    this->resources_on[4] = Resource(Resource::Sheep);
    this->resources_on[5] = Resource(Resource::Gold);
    this->resources_on[6] = Resource(Resource::Coal);
    this->resources_on[7] = Resource(Resource::Gems);
    this->resources_on[8] = Resource(Resource::Marble);
    this->resources_on[9] = Resource(Resource::Cotton);
    this->resources_on[10] = Resource(Resource::Incense);
    this->resources_on[11] = Resource(Resource::Ivory);
    this->resources_on[12] = Resource(Resource::Wine);
    this->resources_on[13] = Resource(Resource::Wheat);
    this->resources_on[14] = Resource(Resource::Stone);
}
Exemplo n.º 2
0
/**
 * This function is called by the parsing functions to populate the feature sets
 */
void AddFeatureCallback(STPoint2 p, STPoint2 q, ImageChoice image)
{
    if (image == IMAGE_1 || image == BOTH_IMAGES)
        gSourceFeatures.push_back(Feature(p, q));
    if (image == IMAGE_2 || image == BOTH_IMAGES)
        gTargetFeatures.push_back(Feature(p, q));
}
void SparseFeatureVector::add(long index, double value)
{
  if (value == 0) {
    return;
  }
  for (featureIterator fiter = features.begin(); fiter != features.end(); ++fiter){
    if (index < (*fiter).index ) {
      features.insert(fiter, Feature(index, value));
      return;
    }
  }
  features.insert(features.end(), Feature(index, value));
}
Exemplo n.º 4
0
Hill::Hill(int x, int  y)
    : Tile(x, y, 0, 1, 2, false, false, 0.0,
        Yield(0, 0, 0), "Hill") {
    // TODO(tomgud): Check if forrest can be on top of a hill ?
    this->features_on = new Feature[8];
    this->features_on[0] = Feature(Feature::BarringerCrater);
    this->features_on[1] = Feature(Feature::MtFuji);
    this->features_on[2] = Feature(Feature::GrandMesa);
    this->features_on[3] = Feature(Feature::RockGibraltar);
    this->features_on[4] = Feature(Feature::OldFaithful);
    this->features_on[5] = Feature(Feature::FountainOfYouth);
    this->features_on[6] = Feature(Feature::CorroDePotosi);
    this->features_on[7] = Feature(Feature::ElDorado);

    this->resources_on = new Resource[11];
    this->resources_on[0] = Resource(Resource::Sheep);
    this->resources_on[1] = Resource(Resource::Iron);
    this->resources_on[2] = Resource(Resource::Coal);
    this->resources_on[3] = Resource(Resource::Aluminum);
    this->resources_on[4] = Resource(Resource::Uranium);
    this->resources_on[5] = Resource(Resource::Deer);
    this->resources_on[6] = Resource(Resource::Stone);
    this->resources_on[7] = Resource(Resource::Gold);
    this->resources_on[8] = Resource(Resource::Silver);
    this->resources_on[9] = Resource(Resource::Gems);
    this->resources_on[10] = Resource(Resource::Marble);
}
SparseFeatureVector::SparseFeatureVector(std::vector<long> featureID,
					 std::vector<double> featureValue)
{
  if (featureID.size() == 0) {
    for (unsigned int i = 0; i < featureValue.size(); i++) {
      features.push_back(Feature(i, featureValue[i]));
    }
  }
  else {
    for (unsigned int i = 0; i < featureValue.size(); i++) {
      features.push_back(Feature(featureID[i], featureValue[i]));
    }
  }
}
Exemplo n.º 6
0
Feature octogon(int side, int)
{
    // total number of rows is side * 3
    // top segment has side - 1 sections that increase by 2 each time
    // segment 2 has identitical sides offset 0 length side + 2*(side-1)
    // segment 3 has side -1 seconds, inverse of section 1

    EdgeList edges;
    side /= 3;
    if (side < 2) side = 2;

    for (auto i = 0; i < side - 1; i++)
    {
        edges.push_back({side-1-i,side+i*2});
    }

    for (auto i = 0; i < side; i++)
    {
        edges.push_back({0,side+2*(side-1)});
    }

    for (auto i = side - 2; i >= 0; i--)
    {
        edges.push_back({side-1-i,side+i*2});
    }
    return Feature(edges);
}
void SparseFeatureVector::initialize(std::vector<long> featureID,
				     std::vector<double> featureValue)
{
  for (unsigned int i = 0; i < featureID.size(); i++) {
    features.push_back(Feature(featureID[i], featureValue[i]));
  }
}
/**
 * Extract features from single image, save 'em to class container.
 * 1) Pass through all features to allocate space for sparse data matrices
 * 2) Fill sparce matrices, see Observation::Sparse class
 * 3) Fill an auxiliary matrix cv::mat Observation::Sparse::numFeats
 *
 * @param cv::Mat im
 * @return void
 */
void Observation::from(const cv::Mat& im)
{
     //initialize keypoint and descriptor extractors separately
    cv::Ptr<cv::FeatureDetector> detector = new cv::SurfFeatureDetector(config::HESSIAN_THRESHOLD);
//    cv::Ptr<cv::FeatureDetector> detector = new cv::FastFeatureDetector(config::FAST_THRESHOLD);

    cv::Ptr<cv::DescriptorExtractor> descriptorExtractor = new cv::SurfDescriptorExtractor(4, 2, true);

    // detect keypoints and extract features
    detector->detect(im, keyPoints);
    descriptorExtractor->compute(im, keyPoints, descriptors);

    // convert features to words
    Vocabulary::instance()->translateAll(descriptors, matches);

    // clear first
    this->features.clear();

#ifdef INSPECTION_MODE
    //timing
    clock_t t1 = clock();

    //timing
    //std::cout << "Features extracted in " << (double)(clock()-t1)/CLOCKS_PER_SEC;
    //std::cout << " seconds" << std::endl;
    //std::cout << "--------------------------------------" << std::endl;
#endif

    features.reserve(keyPoints.size());

    //! 1) gather allocation data for sparse representation
    for (size_t i=0; i<keyPoints.size(); ++i)
    {
        size_t curX = round(keyPoints[i].pt.x);
        size_t curY = round(keyPoints[i].pt.y);
        size_t wordId = matches[i].trainIdx;

        // insert word to multiset, compute their frequency later
        sparse->words.insert(wordId);

        // these will be used to allocate sparse matrix correctly
        this->sparse->insertX(curX);
        this->sparse->insertY(curY);

        features.push_back(Feature(wordId, curX, curY));
    }

#ifdef INSPECTION_MODE
    //timing
    //std::cout << "Features are converted to words in " << (double)(clock()-t1)/CLOCKS_PER_SEC;
    //std::cout << " seconds" << std::endl;
    //std::cout << "------------------------------------------------" << std::endl;
#endif

    this->sparse->fillWith(features);

    detector.release();
    descriptorExtractor.release();
}
bool StudentLocalization::stepFindChinContours(const IntensityImage &image, FeatureMap &features) const {

	//Get the position of the mouth
	Feature Mouth = features.getFeature(Feature::FEATURE_MOUTH_TOP);
	Point2D<double> MouthPosition;
	
	//Initialise the chin feature
	std::vector<Point2D<double>> ChinPositions;
	Feature Chin = Feature(Feature::FEATURE_CHIN);
	Feature ChinContour = Feature(Feature::FEATURE_CHIN_CONTOUR);
	int y = 0;
	int m = 0;
	
	//Draw a half circle starting from the center of the mouth
	for (int j = HALF_CIRCLE; j > 0; j -= DEGREE_STEP){
		
		//reset the position of the mouth
		MouthPosition.set(Mouth.getX(), Mouth.getY());
		MouthPosition.set(drawLine(j, START_POSITION, MouthPosition));
	
		m = m + 1;

		
		for (int i = 0; i < MEASURE_RANGE; i++){

			MouthPosition.set(drawLine(j, MEASURE_STEP, MouthPosition));
			Intensity pixel = image.getPixel(MouthPosition.getX(), MouthPosition.getY());

			// If the intensity of the current pixel is lower than 2 (which means it is black)
			if (pixel < 2){ 
				
				// If the current angle is within the bounds of the half circle
				if (j < RIGHT_HALF && j > LEFT_HALF){
					ChinContour.addPoint(drawLine(j, 2, MouthPosition));
				}
				else{
					//Draw a point on the mouth position, to indicate the detection failed.
					ChinContour.addPoint(MouthPosition);
				}
				break;
			}
		}	
	}	
	features.putFeature(ChinContour);
	return true;
}
Exemplo n.º 10
0
Feature rectangle(int width, int height)
{
    EdgeList edges;
    for (auto i = 0; i < height; i++)
    {
        edges.push_back({0,width});
    }
    return Feature(edges);
}
Exemplo n.º 11
0
Feature trapezium(int top, int height)
{
    EdgeList edges;
    for (auto i = 0; i < height; i++)
    {
        edges.push_back({top-1-i,top+i*2});
    }
    return Feature(edges);
}
Exemplo n.º 12
0
Feature triangle(int rows, int)
{
    EdgeList edges;
    for (auto i = 0; i < rows; i++)
    {
        edges.push_back({rows-i-1,(i+1)*2-1});
    }
    return Feature(edges);
}
Exemplo n.º 13
0
SystemTrayIcon::SystemTrayIcon() :
	m_systemTrayIconFeature( Feature( Feature::Session | Feature::Service | Feature::Worker | Feature::Builtin,
									  Feature::Uid( "8e997d84-ebb9-430f-8f72-d45d9821963d" ),
									  tr( "System tray icon"), QString(), QString() ) ),
	m_features(),
	m_systemTrayIcon( nullptr )
{
	m_features += m_systemTrayIconFeature;
}
Exemplo n.º 14
0
void CvLBPEvaluator::generateFeatures()
{
  int offset = winSize.width + 1;
  for ( int x = 0; x < winSize.width; x++ )
    for ( int y = 0; y < winSize.height; y++ )
      for ( int w = 1; w <= winSize.width / 3; w++ )
        for ( int h = 1; h <= winSize.height / 3; h++ )
          if( ( x + 3 * w <= winSize.width ) && ( y + 3 * h <= winSize.height ) )
            features.push_back( Feature( offset, x, y, w, h ) );
  numFeatures = (int) features.size();
}
Exemplo n.º 15
0
Mountain::Mountain(int x, int  y)
    : Tile(x, y, 0, 0, 1, true, false, 0.0,
        Yield(0, 0, 0),  "Mountain") {
    this->features_on = new Feature[8];
    this->features_on[0] = Feature(Feature::BarringerCrater);
    this->features_on[1] = Feature(Feature::MtFuji);
    this->features_on[2] = Feature(Feature::GrandMesa);
    this->features_on[3] = Feature(Feature::RockGibraltar);
    this->features_on[4] = Feature(Feature::OldFaithful);
    this->features_on[5] = Feature(Feature::FountainOfYouth);
    this->features_on[6] = Feature(Feature::CorroDePotosi);
    this->features_on[7] = Feature(Feature::ElDorado);
}
Exemplo n.º 16
0
void VisionRequestItem::addAllFeatures()
{
    std::vector<Feature> features;

    for (auto& feature: Feature::TYPE_STRINGS)
    {
        features.push_back(Feature(feature.first));
    }

    setFeatures(features);
}
Exemplo n.º 17
0
void CvHOGEvaluator::generateFeatures()
{
  int offset = winSize.width + 1;
  Size blockStep;
  int x, y, t, w, h;

  for ( t = 8; t <= winSize.width / 2; t += 8 )  //t = size of a cell. blocksize = 4*cellSize
  {
    blockStep = Size( 4, 4 );
    w = 2 * t;  //width of a block
    h = 2 * t;  //height of a block
    for ( x = 0; x <= winSize.width - w; x += blockStep.width )
    {
      for ( y = 0; y <= winSize.height - h; y += blockStep.height )
      {
        features.push_back( Feature( offset, x, y, t, t ) );
      }
    }
    w = 2 * t;
    h = 4 * t;
    for ( x = 0; x <= winSize.width - w; x += blockStep.width )
    {
      for ( y = 0; y <= winSize.height - h; y += blockStep.height )
      {
        features.push_back( Feature( offset, x, y, t, 2 * t ) );
      }
    }
    w = 4 * t;
    h = 2 * t;
    for ( x = 0; x <= winSize.width - w; x += blockStep.width )
    {
      for ( y = 0; y <= winSize.height - h; y += blockStep.height )
      {
        features.push_back( Feature( offset, x, y, 2 * t, t ) );
      }
    }
  }

  numFeatures = (int) features.size();
}
   Chip(const sensors_chip_name * c) : chip(c) {
      // populate name
      if(sensors_snprintf_chip_name(name, NAME_SZ, c) < 0) {
         // error: bad chip name
         snprintf(name, NAME_SZ, "Unknown chip");
      }

      // populate features
      int i = 0;
      const sensors_feature * feature;
      while( (feature = sensors_get_features(chip, &i)) ) {
         features.push_back(Feature(c, feature));
      }
   }
Exemplo n.º 19
0
UserSessionControl::UserSessionControl() :
	m_userSessionInfoFeature( Feature( Feature::Session | Feature::Service | Feature::Worker | Feature::Builtin,
									   Feature::Uid( "79a5e74d-50bd-4aab-8012-0e70dc08cc72" ),
									   tr( "User session control" ), QString(), QString() ) ),
	m_userLogoutFeature( Feature::Action | Feature::Master | Feature::Service,
						 Feature::Uid( "7311d43d-ab53-439e-a03a-8cb25f7ed526" ),
						 tr( "Logout user" ), QString(),
						 tr( "Click this button to logout users from all computers." ),
						 ":/resources/system-suspend-hibernate.png" ),
	m_features()
{
	m_features += m_userSessionInfoFeature;
	m_features += m_userLogoutFeature;
}
Exemplo n.º 20
0
States::States ( const cv::Mat& kx ) :
    X(cv::Vec3d( kx.at<double>(0,0), kx.at<double>(1,0), kx.at<double>(2,0)) ),
    V( cv::Vec3d( kx.at<double>(3,0), kx.at<double>(4,0), kx.at<double>(5,0)) ),
    b( cv::Vec3d( kx.at<double>(6,0), kx.at<double>(7,0), kx.at<double>(8,0) ) )
{
    int nf;
    nf = (kx.rows-9)/3;
    for( int i=0; i<nf; ++i )
    {
        addFeature(Feature( cv::Vec3d( kx.at<double>(9+3*i,0), 
            kx.at<double>(10+3*i,0), kx.at<double>(11+3*i,0) ), 0 )); 
    }
    return ;
}		/* -----  end of method States::States  ----- */
Exemplo n.º 21
0
        //find the position of an element in a query list of a person given the element id (good)
        int eid2pos(int eid)
        {
            int pos;
            map<int,int>::iterator it=m.find(eid);
            if(it==m.end())
            {
                pos=m.size();
                m.insert(make_pair(eid,pos));
                features.push_back(make_pair(eid,Feature()));

            }
            else
                pos=it->second;
            return pos;
        }
Exemplo n.º 22
0
std::vector<Feature> interpolateFeatures(const std::vector<Feature> &sourceFeatures,
                                         const std::vector<Feature> &targetFeatures,
                                         float t)
{
    std::vector<Feature> interpolatedFeatures;
    int numFeatures = sourceFeatures.size();
    for (int i = 0; i < numFeatures; i++) {
        float newPx = sourceFeatures[i].P.x*(1-t) + targetFeatures[i].P.x*t;
        float newPy = sourceFeatures[i].P.y*(1-t) + targetFeatures[i].P.y*t;
        float newQx = sourceFeatures[i].Q.x*(1-t) + targetFeatures[i].Q.x*t;
        float newQy = sourceFeatures[i].Q.y*(1-t) + targetFeatures[i].Q.y*t;
        interpolatedFeatures.push_back(Feature(STPoint2(newPx, newPy), STPoint2(newQx, newQy)));
    }
    return interpolatedFeatures;
}
Exemplo n.º 23
0
void Pages::user(Document *doc){

    std::string sub;
    int uid = route("user", path, sub);

    if(!uid || (sub != "" && sub != "json")) return;

    Account u(uid);
    if(!u) return;

    if(sub == "json"){
        doc->setJson("json/account.tpl");
        u.fill(doc->dict());
        doc->dict()->ShowSection("LONG");
        Tracks::byUser(u.id, 0).fillJson(doc->dict(), false);

        std::vector<Playlist> playlists = Playlist::forUser(u);
        for(std::vector<Playlist>::const_iterator i=playlists.begin(); i!=playlists.end(); i++){
            Dict *playlistDict = doc->dict()->AddSectionDictionary("PLAYLIST");
            Dict *item = playlistDict->AddIncludeDictionary("PLAYLIST");
            item->SetFilename("json/playlist.tpl");
            i->fill(item);
        }

    } else { // plain HTML
        doc->setHtml("html/user.tpl", u.name);
        u.fill(doc->dict());
        Tracks::byUser(u.id, u.self()).fill(doc->dict(), "TRACK_LIST");

#ifdef HAVE_LIBHIREDIS
        Stat::push("userView", uid);
#endif

        std::vector<Playlist> playlists = Playlist::forUser(u);
        doc->dict()->ShowSection(playlists.empty() ? "NO_PLAYLIST" : "HAS_PLAYLISTS");
        for(std::vector<Playlist>::const_iterator i=playlists.begin(); i!=playlists.end(); i++){
            Dict *playlistDict = doc->dict()->AddSectionDictionary("PLAYLIST");
            i->fill(playlistDict);
        }

        EventList::user(u, 12).fill(doc->dict(), "EVENTS");
        Follower(u.id).followed().fill(doc->dict(), "FOLLOWED_USERS");

        Feature(u.id).fill(doc->dict());

    }
}
Exemplo n.º 24
0
Feature diamond(int rows, int)
{
    // the offset starts at rows
    // the rows are (i+1)*2 -1 wide
    EdgeList edges;
    for (auto i = 0; i < rows / 2; i++)
    {
        edges.push_back({rows/2-i-1,(i+1)*2-1});
    }

    // bottom half of diamond
    for (auto i = rows / 2 - 1; i >= 0; i--)
    {
        edges.push_back({rows / 2 - i - 1,(i+1)*2-1});
    }
    return Feature(edges);
}
Exemplo n.º 25
0
void Ferns::generateFeatures(std::vector<cv::Size> const& scales)
{
    int totalFeatures = nstructs*structSize;
    features = std::vector< std::vector<Feature> >(scales.size(), std::vector<Feature> (totalFeatures) );
    
    cv::RNG& rng = cv::theRNG();
    for (int i=0; i<totalFeatures; i++) {
        float x1 = static_cast<float>(rng);
        float y1 = static_cast<float>(rng);
        float x2 = static_cast<float>(rng);
        float y2 = static_cast<float>(rng);
        for (int s=0; s<scales.size(); s++) {
            int scaled_x1 = scales[s].width * x1;
            int scaled_y1 = scales[s].height* y1;
            int scaled_x2 = scales[s].width * x2;
            int scaled_y2 = scales[s].height* y2;
            features[s][i] = Feature(static_cast<uchar>(scaled_x1), static_cast<uchar>(scaled_y1),
                                     static_cast<uchar>(scaled_x2), static_cast<uchar>(scaled_y2));
        }
    }
}
Exemplo n.º 26
0
void ClassifySvmSharedCommand::readSharedRAbundVectors(vector<SharedRAbundVector*>& lookup, GroupMap& designMap, LabeledObservationVector& labeledObservationVector, FeatureVector& featureVector) {
    for ( int j = 0; j < lookup.size(); j++ ) {
        //i++;
        vector<individual> data = lookup[j]->getData();
        Observation* observation = new Observation(data.size(), 0.0);
        string sharedGroupName = lookup[j]->getGroup();
        string treatmentName = designMap.getGroup(sharedGroupName);
        //std::cout << "shared group name: " << sharedGroupName << " treatment name: " << treatmentName << std::endl;
        //labeledObservationVector.push_back(std::make_pair(treatmentName, observation));
        labeledObservationVector.push_back(LabeledObservation(j, treatmentName, observation));
        //std::cout << " j=" << j << " label : " << lookup[j]->getLabel() << " group: " << lookup[j]->getGroup();
        for (int k = 0; k < data.size(); k++) {
            //std::cout << " abundance " << data[k].abundance;
            observation->at(k) = double(data[k].abundance);
            if ( j == 0) {
                featureVector.push_back(Feature(k, m->currentSharedBinLabels[k]));
            }
        }
        //std::cout << std::endl;
        // let this happen later?
        //delete lookup[j];
    }
}
Exemplo n.º 27
0
    void Sift::extract(Image &image, std::vector<Feature> *list) {
        float *fdata = new float[image.cv->width * image.cv->height];
        BOOST_VERIFY(fdata);
        {
            float *d = fdata;
            unsigned char *l = (unsigned char *)image.cv->imageData;
            for (int h = 0; h < image.cv->height; ++h) {
                for (int w = 0; w < image.cv->width; ++w) {
                    *d = float(l[w]);
                    d++;
                }
                l += image.cv->widthStep;
            }
        }

        VlSiftFilt *filt = vl_sift_new (image.cv->width, image.cv->height, O, S, omin) ;

        BOOST_VERIFY(filt);
        if (edge_thresh >= 0) vl_sift_set_edge_thresh (filt, edge_thresh) ;
        if (peak_thresh >= 0) vl_sift_set_peak_thresh (filt, peak_thresh) ;
        if (magnif      >= 0) vl_sift_set_magnif      (filt, magnif) ;

        magnif = vl_sift_get_magnif(filt);

        list->clear();

        int err = vl_sift_process_first_octave (filt, fdata);
        while (err == 0) {
          
            vl_sift_detect (filt) ;
            
            VlSiftKeypoint const *keys  = vl_sift_get_keypoints(filt) ;
            int nkeys = vl_sift_get_nkeypoints(filt) ;

            for (int i = 0; i < nkeys ; ++i) {
                VlSiftKeypoint const *key = keys + i;
                double                angles [4] ;

                int nangles = 0;
                if (do_angle) {
                    nangles = vl_sift_calc_keypoint_orientations(filt, angles, key) ;
                }
                else {
                    nangles = 1;
                    angles[0] = 0;
                }

                for (int q = 0 ; q < nangles ; ++q) {

                    list->push_back(Feature());
                    Feature &f = list->back();
                    f.desc.resize(DIM);
                  /* compute descriptor (if necessary) */
                    vl_sift_calc_keypoint_descriptor(filt, &f.desc[0], key, angles[q]) ;

                    BOOST_FOREACH(float &v, f.desc) {
                        /*
                        v = round(v * SIFT_RANGE);
                        if (v > SIFT_RANGE) v = SIFT_RANGE;
                        */
                        v *= 2;
                        if (v > 1.0) v = 1.0;
                    }

                    f.scale = image.getScale();
                    f.x = key->x;
                    f.y = key->y;
                    f.dir = angles[q] / M_PI / 2;
                    f.size = key->sigma * magnif;

                    if ((entropy(f.desc) < e_th) || !checkBlackList(f.desc)) {
                        list->pop_back();
                    }
                   
                }
            }
            err = vl_sift_process_next_octave  (filt) ;
        }
        vl_sift_delete (filt) ;
        delete [] fdata;
    }
Exemplo n.º 28
0
/**
 * @brief			Generating all possible feature rectangles
 * @param			size			Input	-- the concerned size
 * @param			mode			Input	-- mode, BASIC, CORE or ALL
 * @return			void
 */
 void VO_HaarFeatures::VO_GenerateAllFeatureInfo(const Size& size, unsigned int mode)
 {
	this->m_CVSize = size;
	
	int offset = this->m_CVSize.width + 1;			// integral image is (m_CVSize.height+1)*(m_CVSize.width+1)
    for( int x = 0; x < this->m_CVSize.width; x++ )
    {
        for( int y = 0; y < this->m_CVSize.height; y++ )
        {
            for( int dx = 1; dx <= this->m_CVSize.width; dx++ )
            {
                for( int dy = 1; dy <= this->m_CVSize.height; dy++ )
                {
                    // haar_x2
                    if ( (x+dx*2 <= this->m_CVSize.width) && (y+dy <= this->m_CVSize.height) )
                    {
						m_vAllFeatures.push_back( Feature( offset, false,
						x,    y, dx, dy, -1,
						x+dx, y, dx, dy, +1 ) );
                    }
                    // haar_y2
                    if ( (x+dx <= this->m_CVSize.width) && (y+dy*2 <= this->m_CVSize.height) ) 
                    {
						m_vAllFeatures.push_back( Feature( offset, false,
						x, y,    dx, dy, -1,
						x, y+dy, dx, dy, +1 ) );
                    }
                    // haar_x3
                    if ( (x+dx*3 <= this->m_CVSize.width) && (y+dy <= this->m_CVSize.height) )
                    {
						m_vAllFeatures.push_back( Feature( offset, false,
						x,    y, dx*3, dy, -1,
						x+dx, y, dx  , dy, +3 ) );
                    }
                    // haar_y3
                    if ( (x+dx <= this->m_CVSize.width) && (y+dy*3 <= this->m_CVSize.height) )
                    {
						m_vAllFeatures.push_back( Feature( offset, false,
						x, y,    dx, dy*3, -1,
						x, y+dy, dx, dy,   +3 ) );
                    }
                    if( mode != VO_HaarFeatures::BASIC )
                    {
                        // haar_x4
                        if ( (x+dx*4 <= this->m_CVSize.width) && (y+dy <= this->m_CVSize.height) ) 
                        {
							m_vAllFeatures.push_back( Feature( offset, false,
							x,    y, dx*4, dy, -1,
							x+dx, y, dx*2, dy, +2 ) );
                        }
                        // haar_y4
                        if ( (x+dx <= this->m_CVSize.width) && (y+dy*4 <= this->m_CVSize.height ) ) 
                        {
							m_vAllFeatures.push_back( Feature( offset, false,
							x, y,    dx, dy*4, -1,
							x, y+dy, dx, dy*2, +2 ) );
                        }
                    }
                    // x2_y2
                    if ( (x+dx*2 <= this->m_CVSize.width) && (y+dy*2 <= this->m_CVSize.height) ) 
                    {
						m_vAllFeatures.push_back( Feature( offset, false,
						x,    y,    dx*2, dy*2, -1,
						x,    y,    dx,   dy,   +2,
						x+dx, y+dy, dx,   dy,   +2 ) );
                    }
                    if (mode != VO_HaarFeatures::BASIC) 
                    {
						// x3_y3
                        if ( (x+dx*3 <= this->m_CVSize.width) && (y+dy*3 <= this->m_CVSize.height) ) 
                        {
							m_vAllFeatures.push_back( Feature( offset, false,
							x   , y   , dx*3, dy*3, -1,
							x+dx, y+dy, dx  , dy  , +9) );
                        }
                    }
                    if (mode == VO_HaarFeatures::ALL) 
                    {
                        // tilted haar_x2
                        if ( (x+2*dx <= this->m_CVSize.width) && (y+2*dx+dy <= this->m_CVSize.height) && (x-dy>= 0) ) 
                        {
							m_vAllFeatures.push_back( Feature( offset, true,
							x, 	  y, dx, dy, -1,
							x+dx, y, dx, dy, +1 ) );
                        }
                        // tilted haar_y2
                        if ( (x+dx <= this->m_CVSize.width) && (y+dx+2*dy <= this->m_CVSize.height) && (x-2*dy>= 0) ) 
                        {
							m_vAllFeatures.push_back( Feature( offset, true,
							x, y, 	 dx, dy, -1,
							x, y+dy, dx, dy, +1 ) );
                        }
                        // tilted haar_x3
                        if ( (x+3*dx <= this->m_CVSize.width) && (y+3*dx+dy <= this->m_CVSize.height) && (x-dy>= 0) ) 
                        {
							m_vAllFeatures.push_back( Feature( offset, true,
							x,    y, dx*3, dy, -1,
							x+dx, y, dx,   dy, +3 ) );
                        }
                        // tilted haar_y3
                        if ( (x+dx <= this->m_CVSize.width) && (y+dx+3*dy <= this->m_CVSize.height) && (x-3*dy>= 0) ) 
                        {
							m_vAllFeatures.push_back( Feature( offset, true,
							x, y,    dx, dy*3, -1,
							x, y+dy, dx, dy,   +3 ) );
                        }
                        // tilted haar_x4
                        if ( (x+4*dx <= this->m_CVSize.width) && (y+4*dx+dy <= this->m_CVSize.height) && (x-dy>= 0) ) 
                        {
							m_vAllFeatures.push_back( Feature( offset, true,
							x,    y, dx*4, dy, -1,
							x+dx, y, dx*2, dy, +2 ) );
                        }
                        // tilted haar_y4
                        if ( (x+dx <= this->m_CVSize.width) && (y+dx+4*dy <= this->m_CVSize.height) && (x-4*dy>= 0) ) 
                        {
							m_vAllFeatures.push_back( Feature( offset, true,
							x, y,    dx, dy*4, -1,
							x, y+dy, dx, dy*2, +2 ) );
                        }
                    }
                }
			}
        }
    }

	this->m_iMode 			= mode;
	this->m_iNbOfFeatures 	= this->m_vAllFeatures.size();
}
Exemplo n.º 29
0
namespace CloudPlatform {


const std::map<VisionRequestItem::Feature::Type, std::string> VisionRequestItem::Feature::TYPE_STRINGS =
{
    { Type::TYPE_UNSPECIFIED, "TYPE_UNSPECIFIED" },
    { Type::LABEL_DETECTION, "LABEL_DETECTION" },
    { Type::TEXT_DETECTION, "TEXT_DETECTION" },
    { Type::DOCUMENT_TEXT_DETECTION, "DOCUMENT_TEXT_DETECTION" },
    { Type::FACE_DETECTION, "FACE_DETECTION" },
    { Type::LANDMARK_DETECTION, "LANDMARK_DETECTION" },
    { Type::LOGO_DETECTION, "LOGO_DETECTION" },
    { Type::SAFE_SEARCH_DETECTION, "SAFE_SEARCH_DETECTION" },
    { Type::IMAGE_PROPERTIES, "IMAGE_PROPERTIES" },
    { Type::CROP_HINTS, "CROP_HINTS" },
    { Type::WEB_DETECTION, "WEB_DETECTION" }
};


VisionRequestItem::Feature::Feature(Type type, std::size_t maxResults)
{
    _json["type"] = TYPE_STRINGS.find(type)->second;
    _json["maxResults"] = maxResults;
}


const ofJson& VisionRequestItem::Feature::json() const
{
    return _json;
}


const std::vector<VisionRequestItem::Feature> VisionRequestItem::DEFAULT_FEATURES =
{
    Feature(Feature::Type::LABEL_DETECTION),
    Feature(Feature::Type::DOCUMENT_TEXT_DETECTION),
    Feature(Feature::Type::FACE_DETECTION),
    Feature(Feature::Type::LANDMARK_DETECTION),
    Feature(Feature::Type::LOGO_DETECTION),
    Feature(Feature::Type::SAFE_SEARCH_DETECTION),
    Feature(Feature::Type::IMAGE_PROPERTIES),
    Feature(Feature::Type::CROP_HINTS),
    Feature(Feature::Type::WEB_DETECTION)
};


VisionRequestItem::VisionRequestItem()
{
}
    

VisionRequestItem::VisionRequestItem(const ofPixels& pixels,
                                     const std::vector<Feature>& features):
    VisionRequestItem(pixels,
                      OF_IMAGE_FORMAT_JPEG,
                      OF_IMAGE_QUALITY_MEDIUM,
                      features)
{
}


VisionRequestItem::VisionRequestItem(const ofPixels& pixels,
                                     ofImageFormat format,
                                     ofImageQualityType quality,
                                     const std::vector<Feature>& features)
{
    setImage(pixels, format, quality);
    setFeatures(features);
}


VisionRequestItem::VisionRequestItem(const std::string& uri,
                                     const std::vector<Feature>& features)
{
    setImage(uri);
    setFeatures(features);
}


VisionRequestItem::VisionRequestItem(const ofBuffer& buffer,
                                     const std::vector<Feature>& features)
{
    setImage(buffer);
    setFeatures(features);
}


VisionRequestItem::~VisionRequestItem()
{
}


void VisionRequestItem::setImage(const ofPixels& pixels,
                                 ofImageFormat format,
                                 ofImageQualityType quality)
{
    ofBuffer buffer;
    ofSaveImage(pixels, buffer, format, quality);
    setImage(buffer);
}


void VisionRequestItem::setImage(const std::string& uri)
{
    if (uri.substr(0, 5).compare("gs://") == 0)
    {
        _json["image"].clear();
        _json["image"]["source"]["gcs_image_uri"] = uri;
    }
    else
    {
        setImage(ofBufferFromFile(uri));
    }
}


void VisionRequestItem::setImage(const ofBuffer& buffer)
{
    _json["image"].clear();
    _json["image"]["content"] = IO::Base64Encoding::encode(IO::ByteBuffer(buffer));
}


void VisionRequestItem::addFeature(const Feature& feature)
{
    _json["features"].push_back(feature.json());
}


void VisionRequestItem::setFeatures(const std::vector<Feature>& features)
{
    _json["features"].clear();

    for (auto& feature: features)
    {
        addFeature(feature);
    }
}


void VisionRequestItem::addAllFeatures()
{
    std::vector<Feature> features;

    for (auto& feature: Feature::TYPE_STRINGS)
    {
        features.push_back(Feature(feature.first));
    }

    setFeatures(features);
}


void VisionRequestItem::setLatitudeLongitudeBounds(double minLatitude,
                                                   double minLongitude,
                                                   double maxLatitude,
                                                   double maxLongitude)
{
    _json["imageContext"]["latLongRect"] = {
        "minLatLng", {
            { "latitude", minLatitude },
            { "longitude", minLongitude }
        },
        "maxLatLng", {
            { "latitude", maxLatitude },
            { "longitude", maxLongitude }
        }
    };
}

void VisionRequestItem::setLanguageHints(const std::vector<std::string>& languages)
{
    _json["imageContext"]["languageHints"].clear();

    for (auto& language: languages)
    {
        addLanguageHint(language);
    }
}


void VisionRequestItem::addLanguageHint(const std::string& language)
{
    _json["imageContext"]["languageHints"].push_back(language);
}


const ofJson& VisionRequestItem::json() const
{
    return _json;
}


} } // namespace ofx::CloudPlatform
Exemplo n.º 30
0
void SegmentationWindow::OnUpdateMenuSelectionSelectMarked(wxUpdateUIEvent& e)
{
	Feature feature = Feature(e.GetId() - (MENUID_SELECTION_SELECTMARKED_BASE+1));
	e.Enable(m_model->active_multi_feature_selection() && !m_model->active_multi_feature_selection()->selection(feature)->empty());
}