bool Bootstrap::automaticallyLabelBoard(const RProp& model, const char* boardFile) const { char buffer[100]; sprintf(buffer, "%s/%s", sourceDirectory, boardFile); Board board; std::map<Block*, BlockFinalFeatures> featureMap; if(!board.readFromFile(buffer, featureMap)) { printf("Couldn't read board from file %s\n", buffer); return false; } std::map<Block*, bool> lifeMap; std::map<Block*, BlockFinalFeatures>::iterator itt = featureMap.begin(); std::map<Block*, BlockFinalFeatures>::iterator end = featureMap.end(); for( ; itt != end; ++itt) { float* features = getFeatureVector(itt->second); bool alive = model.calculateR(features) >= 0.0; delete[] features; std::pair<Block*, bool> mapping(itt->first, alive); lifeMap.insert(mapping); } sprintf(buffer, "%s/%sl", labelDirectory, boardFile); if(!writeLifeFile(lifeMap, buffer)) { printf("Could not write the life map to %s\n", buffer); return false; } float score = board.calculateFinalScore(lifeMap); if(score != board.getFinalScore()) { return false; } return true; }
// ###################################################################### void GistEstimatorGen:: onSimEventVisualCortexOutput(SimEventQueue& q, rutz::shared_ptr<SimEventVisualCortexOutput>& e) { //Grab the channel maps from the visual cortex rutz::shared_ptr<SimReqVCXmaps> vcxm(new SimReqVCXmaps(this)); q.request(vcxm); // VisualCortex is now filling-in the maps... rutz::shared_ptr<ChannelMaps> chm = vcxm->channelmaps(); //Compute the full size gist feature vector getFeatureVector(chm); // post an event so that anyone interested in gist can grab it: rutz::shared_ptr<SimEventGistOutput> ew(new SimEventGistOutput(this, itsGistVector)); q.post(ew); }
vector<int> FRID::getFeaturePoints() { int i,j; vector<int> r; uint _order = getOrder(); int sz=w4*h4; Mat sobelx, gradx, sobely,grady,sobel; Mat sobelgray_,sobelgray__,sobelgray; int totalPoints; Sobel(orderMap[_order],sobelx,CV_16S,1,0,3,1, 0, BORDER_DEFAULT ); convertScaleAbs( sobelx, gradx ); Sobel(orderMap[_order],sobely,CV_16S,0,1,3,1, 0, BORDER_DEFAULT ); convertScaleAbs( sobely, grady ); addWeighted( gradx, 0.5, grady, 0.5, 0, sobel ); cvtColor(sobel,sobelgray_,CV_RGB2GRAY); sobelgray_.convertTo(sobelgray__,CV_8UC1); double min,max; int maxid[2]; minMaxIdx(sobelgray__,&min,&max,0,maxid); threshold(sobelgray__,sobelgray__,(int)(((float)max)/255*100),1,THRESH_BINARY); totalPoints = sum(sobelgray__)[0]; cout<<"max: "<<max<<endl; cout<<"totalPoints: "<<totalPoints<<endl; double br; double bg; double bb; double bsr; double bsg; double bsb; int xmin,xmax,ymin,ymax; //Mat bufABSmat; //Mat bufABS2mat; Mat result1; Mat cdmat; orderMap[_order].copyTo(cdmat); for (i=0; i<sz; i++){ if (sobelgray__.at<uchar>(i/w4,i%w4) == 0) continue; float* bufABS = getFeatureVector(i%w4,i/w4,br,bg,bb,bsr,bsg,bsb); Mat bufABSmat ((_order/2-1)*3+3,1,CV_32FC1,bufABS); //bufABSmat; Mat corImg = Mat::zeros(Size(w4,h4),CV_8UC1); xmin=w4-1,xmax=0,ymin=h4-1,ymax=0; for (j=0; j<sz; j++){ if (sobelgray__.at<uchar>(j/w4,j%w4) == 0) continue; float* bufABS2 = getFeatureVector(j%w4,j/w4,br,bg,bb,bsr,bsg,bsb); Mat bufABS2mat ((_order/2-1)*3+3,1,CV_32FC1,bufABS2); matchTemplate(bufABSmat, bufABS2mat, result1, CV_TM_CCOEFF_NORMED); if (bsr>255 && bsg>255 && bsb>255 && pow(result1.at<float>(0),3)>0.5) { if (xmin > j%w4) xmin = j%w4; if (xmax < j%w4) xmax = j%w4; if (ymin > j/w4) ymin = j/w4; if (ymax < j/w4) ymax = j/w4; corImg.at<uchar>(j) = 1;//(result1.at<float>(0) > 0)? pow(result1.at<float>(0),10):0; if ((xmax-xmin)>6 && (ymax-ymin)>6)break; } } // namedWindow( "c", CV_WINDOW_AUTOSIZE ); // imshow( "c", corImg*255);//thrCrCb[0] ); // // waitKey(0); if ((xmax-xmin)<=6 && (ymax-ymin)<=6) { cout<<"xy: "<<i%w4<<", "<<i/w4<<endl; cout<<"totalPoints: "<<sum(sobelgray__)[0]<<endl; circle( cdmat, Point(i%w4,i/w4), 1, Scalar( 0, 0, 255 ), -1, 8 ); r.push_back(i%w4); r.push_back(i/w4); } //sobelgray__=sobelgray__-corImg; } //circle( cdmat, Point(maxid[1],maxid[0]), 1, Scalar( 0, 0, 255 ), -1, 8 ); return r; }
individual individual::copy(){ std::vector<float> cop = getFeatureVector(); individual ind(cop); return ind; }