void loadFeaturesRGB(BoWFeatures &features) { features.clear(); features.reserve(files_list_rgb.size()); cv::SURF surf(500, 4, 2, true); double acc_media = 0,media=0,scarti=0,varianza=0; DUtilsCV::GUI::tWinHandler win = "SURF"; for (int i = 0; i < files_list_rgb.size(); ++i) { cout << "Estrazione SURF: " << files_list_rgb[i]; clock_t begin = clock(); cv::Mat image = cv::imread(files_list_rgb[i]); cv::Mat mask,outImg; vector<cv::KeyPoint> keypoints; vector<float> descriptors; surf(image, mask, keypoints, descriptors); drawKeypoints(image, keypoints, outImg ); DUtilsCV::GUI::showImage(outImg, true, &win, 10); features.push_back(vector<vector<float> >()); changeStructure(descriptors, features.back(), surf.descriptorSize()); clock_t end = clock(); double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC; media = media + elapsed_secs; acc_media = media / (i+1); cout << "media: " << acc_media<<endl; scarti += pow(elapsed_secs-acc_media,2); varianza = sqrt(scarti/(i+1)); cout << "varianza: " << varianza<<endl; cout << ". Estratti " << features[i].size() << " descrittori." << endl; descriptors.clear(); keypoints.clear(); mask.release(); image.release(); } cout << "Estrazione terminata." << endl; }
void ObjectRecognition::loadFeatures(Mat& inImage, vector< KeyPoint >& keypoints, vector< std::vector< float > >& features, Mat& descriptors) { features.clear(); keypoints.clear(); if(input_type==0) //input_type = 0 camera cvtColor(inImage, inImage, CV_RGB2GRAY); #if FEATURE_EXTRATION //---------------using SIFT to get features descriptors------------------------- //cout<< "...Extracting SIFT features..." << endl; initModule_nonfree(); SIFT sift(1, 3, 0.04, 10, 1.0); sift(inImage, noArray(), keypoints, descriptors); // vector<vector<float> > vdesc; // vdesc.reserve(descriptors.rows); for (int i=0; i<descriptors.rows; i++) { features.push_back(descriptors.row(i)); } // cout<< "descriptors: " << vdesc.size() << " " << vdesc[0].size() << endl; #else //-----------using SURF to get features descriptors------------------------ vector<float> descriptors; cv::Mat mask; cv::SURF surf(400, 4, 2, EXTENDED_SURF); surf(inimage, mask, keypoints, descriptors); features.push_back(vector<vector<float> >()); changeStructure(descriptors, features.back(), surf.descriptorSize()); #endif //----------------------------display keypoints-------------------------- // drawKeypoints(image, keypoints, image, Scalar(255,0,0)); // imshow("clusters", image); // waitKey(); }
int game_host::performUpdate(string upd) { int updateType = 0; UpdMess update(upd); updateType = update.getType(); if(updateType == TOWER) { int subType = update.getVal(0); //Tower Placement: UpdMess(Player[1], TOWER, TOWERPLACE[2], TowerX[2], Tower[Y]); if(subType == TOWERPLACE) { // placeTower(int playerNumber, int towerType, int x, int y); if(isEmptyLocation(update.getVal(1), update.getVal(2))) { placeTower(update.getPlayer(), STRUCTURE, update.getVal(1), update.getVal(2)); } } else if(subType == MINEPLACE) { if(isEmptyLocation(update.getVal(1), update.getVal(2))) { placeTower(update.getPlayer(), MINETOWER, update.getVal(1), update.getVal(2)); } } //Tower Upgrade: UpdMess(Player[1], TOWER, TOWERUPGRADE[2], TowerID[4]); else if(subType == TOWERUPGRADE) { if(towerList.checkForObjectWithID(update.getId1()) == true) { if(towerList.getNodeWithID(update.getId1())->getData()->getType() != STRUCTURE) { if(towerList.getNodeWithID(update.getId1())->getData()->upgrade()) { sendMessageToQueue(UpdMess(update.getPlayer(), TOWER, TOWERUPGRADE, update.getId1()).getMT()); } } } } //Tower ChangeType: UpdMess(Player[1], TOWER, TOWERCHANGE[2], TowerID[4], newType[2]); else if(subType == TOWERCHANGE) { if(towerList.checkForObjectWithID(update.getId1()) == true) { if(towerList.getNodeWithID(update.getId1())->getData()->getType() == STRUCTURE) { return changeStructure(update.getId1(), update.getVal(1)); } else if(towerList.getNodeWithID(update.getId1())->getData()->getType() == NORMCREEPTOWER) { if(towerList.getNodeWithID(update.getId1())->getData()->changeType(update.getVal(1))) { sendMessageToQueue(UpdMess(update.getPlayer(), TOWER, TOWERCHANGE, update.getId1(),update.getVal(1)).getMT()); } } } } //Tower Toggle Pause: UpdMess(Player[1], TOWER, TOWERTOGGLE[2], TowerID[4], newValue); else if(subType == TOWERTOGGLE) { if(towerList.checkForObjectWithID(update.getId1())) { int towerTypeRec = towerList.getNodeWithID(update.getId1())->getData()->getType(); if(towerList.getNodeWithID(update.getId1())->getData()->getType() >= NORMCREEPTOWER && towerList.getNodeWithID(update.getId1())->getData()->getType() <= FATTYCREEPTOWER) { if(update.getVal(1) == 1) towerList.getNodeWithID(update.getId1())->getData()->pause(); else if(update.getVal(1) == 0) towerList.getNodeWithID(update.getId1())->getData()->unpause(); sendMessageToQueue(UpdMess(towerList.getNodeWithID(update.getId1())->getData()->getPlayer(), TOWER, TOWERTOGGLE, update.getId1(), towerList.getNodeWithID(update.getId1())->getData()->isPaused()).getMT()); } } } else if(subType == TOWERDELETE) { if(towerList.checkForObjectWithID(update.getId1())) { removeTower(update.getId1(), update.getPlayer()); } } } else if(updateType == BASE) { int subType = update.getVal(0); if(subType == UPGRADE) { if(this->getPlayer(update.getPlayer())->getMoney() >= BASEUPGRADECOST) { if(update.getPlayer() == 1) { if(this->p1Spawner->getLevel() < 5 && players[0].getMoney() >= (p1Spawner->getLevel() + 1) * BASEUPGRADECOST) { players[0].spendMoney((p1Spawner->getLevel() + 1) * BASEUPGRADECOST); this->p1Spawner->setLevel(this->p1Spawner->getLevel() + 1); sendMessageToQueue(UpdMess(1, BASE, UPGRADE).getMT()); } } else if(update.getPlayer() == 2) { if(this->p2Spawner->getLevel() < 5 && players[1].getMoney() >= (p2Spawner->getLevel() + 1) * BASEUPGRADECOST) { players[1].spendMoney((p2Spawner->getLevel() + 1) * BASEUPGRADECOST); this->p2Spawner->setLevel(this->p2Spawner->getLevel() + 1); sendMessageToQueue(UpdMess(2, BASE, UPGRADE).getMT()); } } } } else if(subType == ADDTYPE) { int addType = update.getVal(1); if(!(addType >= FAST && addType <= FATTY)) return -1; if(update.getPlayer() == 1) { if(this->p1Spawner->isInSpawner(addType)) return -1; // Already in the spawner } else if(update.getPlayer() == 2) { if(this->p2Spawner->isInSpawner(addType)) return -1; // Already in the spawner } else return -1; if(this->getPlayer(update.getPlayer())->getMoney() >= addSpawnArr[addType]) { this->getPlayer(update.getPlayer())->spendMoney(addSpawnArr[addType]); if(update.getPlayer() == 1) { this->p1Spawner->addCreepType(addType); sendMessageToQueue(UpdMess(1, BASE, ADDTYPE, addType).getMT()); } else { this->p2Spawner->addCreepType(addType); sendMessageToQueue(UpdMess(2, BASE, ADDTYPE, addType).getMT()); } } } else return -1; } else return -1; sendMessageToQueue(UpdMess(1, PLAYERUPDATE, getPlayer(1)->getHealth(), getPlayer(1)->getMoney()).getMT()); sendMessageToQueue(UpdMess(2, PLAYERUPDATE, getPlayer(2)->getHealth(), getPlayer(2)->getMoney()).getMT()); return 0; }