int main() { std::pair<std::string, std::string> temp_files = get_temp_file_names(); std::string& temp1 = temp_files.first; std::string& temp2 = temp_files.second; assert(temp1 != temp2); { std::fstream fs1(temp1.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::trunc); std::fstream fs2(temp2.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::trunc); fs1 << 1 << ' ' << 2; fs2 << 2 << ' ' << 1; fs1.seekg(0); fs1.swap(fs2); fs1.seekg(0); int i; fs1 >> i; assert(i == 2); fs1 >> i; assert(i == 1); i = 0; fs2 >> i; assert(i == 1); fs2 >> i; assert(i == 2); } std::remove(temp1.c_str()); std::remove(temp2.c_str()); { std::wfstream fs1(temp1.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::trunc); std::wfstream fs2(temp2.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::trunc); fs1 << 1 << ' ' << 2; fs2 << 2 << ' ' << 1; fs1.seekg(0); fs1.swap(fs2); fs1.seekg(0); int i; fs1 >> i; assert(i == 2); fs1 >> i; assert(i == 1); i = 0; fs2 >> i; assert(i == 1); fs2 >> i; assert(i == 2); } std::remove(temp1.c_str()); std::remove(temp2.c_str()); }
// void MainEngine::ReadConfigurationFile(int argc, wxChar* argv[]) // void MainEngine::ReadConfigurationFile(int argc, char** argv) void MainEngine::ReadConfigurationFile(int argc, char* argv[]) { // settings test // cv::FileStorage fs(wxString(argv[1]).ToStdString(), cv::FileStorage::READ); cv::FileStorage fs; if(argc < 2) { cv::FileStorage fs1("/home/cvfish/Work/code/github/PangaeaTracking/config/Levi_cluster/cluster_levi_real_images_blur_ncc_coarse/PangaeaTracking_001_test.yml", cv::FileStorage::READ); fs = fs1; } else { cv::FileStorage fs1(argv[1], cv::FileStorage::READ); fs = fs1; } // read settings std::string imageSource; std::string tracker; if(!fs["ImageSourceType"].empty()) fs["ImageSourceType"] >> imageSource; imageSourceType = mapImageSourceType( imageSource ); if(!fs["TrackingType"].empty()) fs["TrackingType"] >> tracker; trackingType = mapTrackingType(tracker); if(!fs["ImageSourceSettings"].empty()) fs["ImageSourceSettings"] >> imageSourceSettings; if(!fs["ShapeLoadingSettings"].empty()) fs["ShapeLoadingSettings"] >> shapeLoadingSettings; if(!fs["MeshLoadingSettings"].empty()) fs["MeshLoadingSettings"] >> meshLoadingSettings; if(!fs["TrackerSettings"].empty()) fs["TrackerSettings"] >> trackerSettings; if(!fs["FeatureSettings"].empty()) fs["FeatureSettings"] >> featureSettings; fs.release(); }
int main() { { std::fstream fs1("test1.dat", std::ios_base::in | std::ios_base::out | std::ios_base::trunc); std::fstream fs2("test2.dat", std::ios_base::in | std::ios_base::out | std::ios_base::trunc); fs1 << 1 << ' ' << 2; fs2 << 2 << ' ' << 1; fs1.seekg(0); fs1.swap(fs2); fs1.seekg(0); int i; fs1 >> i; assert(i == 2); fs1 >> i; assert(i == 1); i = 0; fs2 >> i; assert(i == 1); fs2 >> i; assert(i == 2); } std::remove("test1.dat"); std::remove("test2.dat"); { std::wfstream fs1("test1.dat", std::ios_base::in | std::ios_base::out | std::ios_base::trunc); std::wfstream fs2("test2.dat", std::ios_base::in | std::ios_base::out | std::ios_base::trunc); fs1 << 1 << ' ' << 2; fs2 << 2 << ' ' << 1; fs1.seekg(0); fs1.swap(fs2); fs1.seekg(0); int i; fs1 >> i; assert(i == 2); fs1 >> i; assert(i == 1); i = 0; fs2 >> i; assert(i == 1); fs2 >> i; assert(i == 2); } std::remove("test1.dat"); std::remove("test2.dat"); }
void MasterTimer_Test::stopAllFunctions() { MasterTimer* mt = m_doc->masterTimer(); mt->start(); Function_Stub fs1(m_doc); fs1.start(mt, FunctionParent::master()); DMXSource_Stub s1; mt->registerDMXSource(&s1, "s1"); Function_Stub fs2(m_doc); fs2.start(mt, FunctionParent::master()); DMXSource_Stub s2; mt->registerDMXSource(&s2, "s2"); Function_Stub fs3(m_doc); fs3.start(mt, FunctionParent::master()); QTest::qWait(60); QVERIFY(mt->runningFunctions() == 3); QVERIFY(mt->m_dmxSourceList.size() == 2); mt->stopAllFunctions(); QVERIFY(mt->runningFunctions() == 0); QVERIFY(mt->m_dmxSourceList.size() == 2); // Shouldn't stop mt->unregisterDMXSource(&s1); mt->unregisterDMXSource(&s2); }
void MasterTimer_Test::runMultipleFunctions() { MasterTimer* mt = m_doc->masterTimer(); mt->start(); Function_Stub fs1(m_doc); fs1.start(mt, FunctionParent::master()); mt->timerTick(); QVERIFY(mt->runningFunctions() == 1); Function_Stub fs2(m_doc); fs2.start(mt, FunctionParent::master()); mt->timerTick(); QVERIFY(mt->runningFunctions() == 2); Function_Stub fs3(m_doc); fs3.start(mt, FunctionParent::master()); mt->timerTick(); QVERIFY(mt->runningFunctions() == 3); /* Wait a while so that the functions start running */ QTest::qWait(100); /* Stop the functions after they have been running for a while */ fs1.stop(FunctionParent::master()); fs2.stop(FunctionParent::master()); fs3.stop(FunctionParent::master()); /* Wait a while so that the functions stop */ QTest::qWait(100); QVERIFY(mt->runningFunctions() == 0); }
void ReplaceInFile(std::string fn,std::string nfn,StringPairs& repl) { char buf[10000]; std::ifstream fs(fn.c_str(),std::ios::in | std::ios::binary); std::ofstream fs1(nfn.c_str(),std::ios::out | std::ios::binary); while(!fs.eof()) { fs.getline(buf,1000); std::string ss(buf); std::string res = ReplaceInString(ss,repl); if(res.size()>1) { fs1.write(res.c_str(),res.size()-1); fs1 << std::endl; } } fs.close(); fs1.close(); }
void Build_Vocabulary::drawKmeans(String vocabularyfile, String descriptorsfile){// can only draw 2D points. cout << "Loading Files..." << endl; FileStorage fs(descriptorsfile, FileStorage::READ); Mat training_descriptors; fs["training_descriptors"] >> training_descriptors; fs.release(); FileStorage fs1(vocabularyfile, FileStorage::READ); Mat vocabulary; fs1["vocabulary"] >> vocabulary; fs1.release(); IplImage* img = cvCreateImage( cvSize( 500, 500 ), 8, 3 ); cvZero( img ); for( int i = 0; i < training_descriptors.rows; i++ ) { CvPoint2D32f pt = ((CvPoint2D32f*)training_descriptors.data)[i]; int cluster_idx = vocabulary.data[i]; cvCircle( img, cvPointFrom32f(pt), 2, CV_RGB(cluster_idx%255 , cluster_idx%255 , cluster_idx%255), CV_FILLED ); } training_descriptors.release(); vocabulary.release(); cvShowImage( "clusters", img ); waitKey(0); }
bool DSAValidate() { cout << "\nDSA validation suite running...\n\n"; bool pass = true, fail; { FileSource fs("dsa512.dat", true, new HexDecoder()); DSAPrivateKey priv(fs); priv.Precompute(16); DSAPublicKey pub(priv); byte seed[]={0xd5, 0x01, 0x4e, 0x4b, 0x60, 0xef, 0x2b, 0xa8, 0xb6, 0x21, 0x1b, 0x40, 0x62, 0xba, 0x32, 0x24, 0xe0, 0x42, 0x7d, 0xd3}; Integer k("358dad57 1462710f 50e254cf 1a376b2b deaadfbfh"); Integer h("a9993e36 4706816a ba3e2571 7850c26c 9cd0d89dh"); byte sig[]={0x8b, 0xac, 0x1a, 0xb6, 0x64, 0x10, 0x43, 0x5c, 0xb7, 0x18, 0x1f, 0x95, 0xb1, 0x6a, 0xb9, 0x7c, 0x92, 0xb3, 0x41, 0xc0, 0x41, 0xe2, 0x34, 0x5f, 0x1f, 0x56, 0xdf, 0x24, 0x58, 0xf4, 0x26, 0xd1, 0x55, 0xb4, 0xba, 0x2d, 0xb6, 0xdc, 0xd8, 0xc8}; Integer r(sig, 20); Integer s(sig+20, 20); Integer pGen, qGen, rOut, sOut; int c; fail = !GenerateDSAPrimes(seed, 160, c, pGen, 512, qGen); fail = fail || (pGen != pub.GetModulus()) || (qGen != pub.GetSubgroupSize()); pass = pass && !fail; cout << (fail ? "FAILED " : "passed "); cout << "prime generation test\n"; priv.RawSign(k, h, rOut, sOut); fail = (rOut != r) || (sOut != s); pass = pass && !fail; cout << (fail ? "FAILED " : "passed "); cout << "signature check against test vector\n"; fail = !pub.VerifyMessage((byte *)"abc", 3, sig); pass = pass && !fail; cout << (fail ? "FAILED " : "passed "); cout << "verification check against test vector\n"; fail = pub.VerifyMessage((byte *)"xyz", 3, sig); pass = pass && !fail; } FileSource fs1("dsa1024.dat", true, new HexDecoder()); DSAPrivateKey priv(fs1); FileSource fs2("dsa1024b.dat", true, new HexDecoder()); DSAPublicKey pub(fs2); pass = SignatureValidate(priv, pub) && pass; return pass; }
void Build_Vocabulary::doKmeansAll(String postFix){ clock_t start, finish; double elapsed_time; start = time(NULL); cout << "Loading Descriptor Files..." << endl; FileStorage fs("training_descriptors_bike_" +postFix+ ".txt", FileStorage::READ); Mat training_descriptors_bike; fs["training_descriptors"] >> training_descriptors_bike; fs.release(); FileStorage fs1("training_descriptors_cars_" +postFix+ ".txt", FileStorage::READ); Mat training_descriptors_cars; fs1["training_descriptors"] >> training_descriptors_cars; fs1.release(); FileStorage fs2("training_descriptors_person_" +postFix+ ".txt", FileStorage::READ); Mat training_descriptors_person; fs2["training_descriptors"] >> training_descriptors_person; fs2.release(); FileStorage fs3("training_descriptors_none_" +postFix+ ".txt", FileStorage::READ); Mat training_descriptors_none; fs3["training_descriptors"] >> training_descriptors_none; fs3.release(); /* */ BOWKMeansTrainer bowtrainer(1000); //num clusters bowtrainer.add(training_descriptors_bike); bowtrainer.add(training_descriptors_person); bowtrainer.add(training_descriptors_cars); bowtrainer.add(training_descriptors_none); cout << "Clustering Bag-of-Words features..." << endl; Mat vocabulary = bowtrainer.cluster(); FileStorage fs4("vocabulary_1000_" +postFix+ ".txt", FileStorage::WRITE); fs4 << "vocabulary" << vocabulary; fs4.release(); /* */ finish=time(NULL); elapsed_time = finish-start; int hours = (int) elapsed_time / 3600; int minutes = (int) (elapsed_time - hours * 3600) / 60; int seconds = (int) elapsed_time - hours * 3600 - minutes * 60; cout << "Elapsed Time for Clustering: " << hours << ":" << minutes << ":" << seconds << endl << endl; cout << "------- Finished Build Vocabulary ---------\n" << endl; }
int main(int argv, char** argc) { std::fstream fs1(argc[1], std::ios::in | std::ios::binary); CryptoPP::SHA256 hash; if (argv > 1){ if (fs1.is_open()) { size_t block_size = 0; byte digest[CryptoPP::SHA256::DIGESTSIZE]; fs1.seekg(0, fs1.end); int digest_size = 0; int pos = fs1.tellg(); while(pos > 0){ block_size = (pos - 1) % BLOCK_SIZE + 1; pos -= block_size; fs1.seekg(pos); byte buf[block_size + digest_size];\ fs1.read(reinterpret_cast<char*>(buf), block_size); for (int i = 0; i < digest_size; i++) buf[block_size + i] = digest[i]; hash.CalculateDigest(digest, buf, block_size+digest_size); digest_size = CryptoPP::SHA256::DIGESTSIZE; } for (int i = 0; i < CryptoPP::SHA256::DIGESTSIZE; i++) std::cout << std::hex << (int)digest[i] << std::dec; std::cout << std::endl; } else { std::cout << "cannot open file " << argc[1]; } }else{ byte digest[CryptoPP::SHA256::DIGESTSIZE]; byte test[2] = {1, 1}; hash.CalculateDigest(digest, test, 2); for (int i = 0; i < CryptoPP::SHA256::DIGESTSIZE; i++) std::cout << std::hex << (int)digest[i] << std::dec; } std::cout << std::endl; return 0; }
void testConnectedComponent() { Mat testMat(480,640,CV_32FC1); Mat mask(480,640,CV_32FC1); mask.setTo(Scalar(1.0)); Mat firstGroup = testMat(Range(0,120),Range(0,200)); Mat secondGroup = testMat(Range(120,240),Range(200,400)); Mat thirdGroup = testMat(Range(240,480),Range(400,640)); firstGroup.setTo(Scalar(15)); secondGroup.setTo(Scalar(21)); thirdGroup.setTo(Scalar(15)); FileStorage fs1("testCompon.yml",FileStorage::READ); fs1["Depth"] >> testMat; fs1.release(); //Next we want to dilate and erode just a little dilate(testMat,testMat,Mat(),Point(-1,-1),2); //FileStorage fs3("FilteredDepthDilate.yml",FileStorage::WRITE); //fs3 << "FilteredDepthDilate" << filteredDepth; //fs3.release(); //Next we want to dilate and erode just a little erode(testMat,testMat,Mat(),Point(-1,-1),2); //We will need to normalize to such that it fits in 255 to 0 for the canny function so create a mat for that Mat normalizedFilteredDepth(testMat.size(),CV_8UC1); normalize(testMat,normalizedFilteredDepth,0,255,NORM_MINMAX,CV_32FC1); testMat = normalizedFilteredDepth; imshow("TestMat",testMat); Mat testComponentMat; struct ConnectedComponentConfig config; config.eightWayNeighborhood = true; config.depthDifferenceThreshold = .05f; config.minPixelArea = 10; vector<vector <Point> > testComponents = findConnectedComponents(config, testMat, mask, testComponentMat); displayComponentResults(testComponentMat); displayComponentResults(testComponents, testMat.size()); }
bool ValidateDSA(bool thorough) { cout << "\nDSA validation suite running...\n\n"; bool pass = true; FileSource fs1("TestData/dsa1024.dat", true, new HexDecoder()); DSA::Signer priv(fs1); DSA::Verifier pub(priv); FileSource fs2("TestData/dsa1024b.dat", true, new HexDecoder()); DSA::Verifier pub1(fs2); CRYPTOPP_ASSERT(pub.GetKey() == pub1.GetKey()); pass = SignatureValidate(priv, pub, thorough) && pass; pass = RunTestDataFile("TestVectors/dsa.txt", g_nullNameValuePairs, thorough) && pass; return pass; }
//Because of Unknow Error, so I have to use 6 XML files to save those matrixs void myPCA::saveModel() { FileStorage fs1("mean.xml", FileStorage::WRITE); FileStorage fs2("sample.xml", FileStorage::WRITE); FileStorage fs3("eigen.xml", FileStorage::WRITE); FileStorage fs4("proj.xml", FileStorage::WRITE); FileStorage fs5("ID.xml", FileStorage::WRITE); FileStorage fs6("sampleOri.xml", FileStorage::WRITE); fs1 << "MeanFace" << meanFace; fs2 << "SampleMatrix" << sampleMatrix ; fs3 << "EigenVectors" << eigenVectors; fs4 << "ProjFaces" << projFaces; fs5 << "TrainImageID" << trainImageID; fs6 << "SampleMatrixOri" << sampleMatrixOri ; }
void myPCA::loadModel() { FileStorage fs1("mean.xml", FileStorage::READ); FileStorage fs2("sample.xml", FileStorage::READ); FileStorage fs3("eigen.xml", FileStorage::READ); FileStorage fs4("proj.xml", FileStorage::READ); FileStorage fs5("ID.xml", FileStorage::READ); FileStorage fs6("sampleOri.xml", FileStorage::READ); fs1["MeanFace"] >> meanFace; fs2["SampleMatrix"] >> sampleMatrix ; fs3["EigenVectors"] >> eigenVectors; fs4["ProjFaces"] >> projFaces; fs5["TrainImageID"] >> trainImageID; fs6["SampleMatrixOri"] >> sampleMatrixOri ; }
void Build_Vocabulary::doKmeans(String filename, String itemname){ clock_t start, finish; double elapsed_time; start = time(NULL); cout << "Loading Descriptor Files..." << endl; FileStorage fs("training_descriptors_" + filename + ".txt", FileStorage::READ); Mat training_descriptors; fs["training_descriptors"] >> training_descriptors; fs.release(); /* */ BOWKMeansTrainer bowtrainer(1000); //num clusters bowtrainer.add(training_descriptors); cout << "Clustering Bag-of-Words features..." << endl; Mat vocabulary = bowtrainer.cluster(); FileStorage fs1("vocabulary_" + filename + "_1000.txt", FileStorage::WRITE); fs1 << "vocabulary" << vocabulary; fs1.release(); /* Mat Label, kMeanCenter; TermCriteria KmeanTerm(CV_TERMCRIT_EPS, 100, 0.001); kmeans(training_descriptors, 1000, Label , KmeanTerm, 2, KMEANS_PP_CENTERS, kMeanCenter); */ /* FileStorage fs2("kMeans_1000.txt", FileStorage::WRITE); fs2 << "label" << Label; fs2 << "kMeanCenter" << kMeanCenter; fs2.release(); */ /* */ finish=time(NULL); elapsed_time = finish-start; int hours = (int) elapsed_time / 3600; int minutes = (int) (elapsed_time - hours * 3600) / 60; int seconds = (int) elapsed_time - hours * 3600 - minutes * 60; cout << "Elapsed Time for Clustering: " << hours << ":" << minutes << ":" << seconds << endl << endl; cout << "------- Finished Build Vocabulary ---------\n" << endl; }
void MasterTimer_Test::restart() { MasterTimer* mt = m_doc->masterTimer(); mt->start(); Function_Stub fs1(m_doc); fs1.start(mt, FunctionParent::master()); Function_Stub fs2(m_doc); fs2.start(mt, FunctionParent::master()); Function_Stub fs3(m_doc); fs3.start(mt, FunctionParent::master()); QTest::qWait(60); QVERIFY(mt->runningFunctions() == 3); mt->stop(); QTest::qWait(60); QVERIFY(mt->runningFunctions() == 0); QVERIFY(mt->m_functionList.size() == 0); QVERIFY(mt->m_functionListMutex.tryLock() == true); mt->m_functionListMutex.unlock(); // QVERIFY(mt->m_running == false); QVERIFY(mt->m_stopAllFunctions == false); mt->start(); QVERIFY(mt->runningFunctions() == 0); QVERIFY(mt->m_functionList.size() == 0); QVERIFY(mt->m_functionListMutex.tryLock() == true); mt->m_functionListMutex.unlock(); // QVERIFY(mt->m_running == true); QVERIFY(mt->m_stopAllFunctions == false); fs1.start(mt, FunctionParent::master()); fs2.start(mt, FunctionParent::master()); fs3.start(mt, FunctionParent::master()); QTest::qWait(60); QVERIFY(mt->runningFunctions() == 3); mt->stopAllFunctions(); }
void MasterTimer_Test::stop() { MasterTimer* mt = m_doc->masterTimer(); mt->start(); Function_Stub fs1(m_doc); fs1.start(mt, FunctionParent::master()); Function_Stub fs2(m_doc); fs2.start(mt, FunctionParent::master()); Function_Stub fs3(m_doc); fs3.start(mt, FunctionParent::master()); QTest::qWait(60); QVERIFY(mt->runningFunctions() == 3); mt->stop(); QTest::qWait(60); QVERIFY(mt->runningFunctions() == 0); // QVERIFY(mt->m_running == false); }
// muestra el sistema, matriz A y vector b en archivos separado void Sistema_Lineal::mostrar_sistema(Matriz *a, Vector *x, Vector *b) { unsigned long long n,i,j; // n = cant filas = cant columnas n = a->Columnas(); cout<<"tamaño"<<n<<"\n\n"; //cout<<".....................................................................::::::::::::::::::::::::::: tamaño"<<n<<"\n\n"; ofstream fs1("/home/usuario/Escritorio/carpeta/matriz.dat"); //crear archivo de salida con la matriz ofstream fs2("/home/usuario/Escritorio/carpeta/vector.dat"); //crear archivo de salida con el vector for(i=0; i<n; i++) { for(j=0; j<n; j++) { fs1 << a->Retorna(i,j) <<" ";//enviar la matriz al archivo de salida //cout << a->Retorna(i,j) <<" \t"; } fs1 << "\n"; } for(i=0; i<n; i++) { fs2 << b->Retorna(i)<<" \n"; //enviar el vector al archivo de salida } fs1.close(); //cerrar archivo de salida fs2.close(); }
int main() { std::pair<std::string, std::string> temp_files = get_temp_file_names(); std::string& temp1 = temp_files.first; std::string& temp2 = temp_files.second; assert(temp1 != temp2); { std::ofstream fs1(temp1.c_str()); std::ofstream fs2(temp2.c_str()); fs1 << 3.25; fs2 << 4.5; swap(fs1, fs2); fs1 << ' ' << 3.25; fs2 << ' ' << 4.5; } { std::ifstream fs(temp1.c_str()); double x = 0; fs >> x; assert(x == 3.25); fs >> x; assert(x == 4.5); } std::remove(temp1.c_str()); { std::ifstream fs(temp2.c_str()); double x = 0; fs >> x; assert(x == 4.5); fs >> x; assert(x == 3.25); } std::remove(temp2.c_str()); { std::wofstream fs1(temp1.c_str()); std::wofstream fs2(temp2.c_str()); fs1 << 3.25; fs2 << 4.5; swap(fs1, fs2); fs1 << ' ' << 3.25; fs2 << ' ' << 4.5; } { std::wifstream fs(temp1.c_str()); double x = 0; fs >> x; assert(x == 3.25); fs >> x; assert(x == 4.5); } std::remove(temp1.c_str()); { std::wifstream fs(temp2.c_str()); double x = 0; fs >> x; assert(x == 4.5); fs >> x; assert(x == 3.25); } std::remove(temp2.c_str()); }
void explicit_constructor(short s) { FromShort fs1(s); FromShort fs2 = s; FromShortExplicitly fse1(s); FromShortExplicitly fse2 = s; // expected-error{{error: cannot initialize 'fse2' with an lvalue of type 'short'}} }
void TestStores2() { B(s10, Stream storage, 0) W(s10a); W(s10b); W(s10c); { // s10a is original // s10b is a copy, random access // s10c is a serialized copy c4_StringProp p1 ("p1"); c4_ViewProp p2 ("p2"); c4_IntProp p3 ("p3"); { c4_Storage s1 ("s10a", 1); s1.SetStructure("a[p1:S,p2[p3:I]]"); c4_View v1 = s1.View("a"); v1.Add(p1 ["one"]); v1.Add(p1 ["two"]); c4_View v2 = p2 (v1[0]); v2.Add(p3 [1]); v2 = p2 (v1[1]); v2.Add(p3 [11]); v2.Add(p3 [22]); v1.InsertAt(1, p1 ["three"]); v2 = p2 (v1[1]); v2.Add(p3 [111]); v2.Add(p3 [222]); v2.Add(p3 [333]); s1.Commit(); } { c4_Storage s1 ("s10a", 0); c4_Storage s2 ("s10b", 1); s2.SetStructure("a[p1:S,p2[p3:I]]"); s2.View("a") = s1.View("a"); s2.Commit(); } { c4_Storage s3 ("s10b", 0); c4_FileStream fs1 (fopen("s10c", "wb"), true); s3.SaveTo(fs1); } { c4_Storage s1 ("s10c", 0); // new after 2.01: serialized is no longer special c4_View v1 = s1.View("a"); A(v1.GetSize() == 3); c4_View v2 = p2 (v1[0]); A(v2.GetSize() == 1); c4_View v3 = p2 (v1[1]); A(v3.GetSize() == 3); c4_View v4 = p2 (v1[2]); A(v4.GetSize() == 2); } { c4_Storage s1; c4_FileStream fs1 (fopen("s10c", "rb"), true); s1.LoadFrom(fs1); c4_View v1 = s1.View("a"); A(v1.GetSize() == 3); c4_View v2 = p2 (v1[0]); A(v2.GetSize() == 1); c4_View v3 = p2 (v1[1]); A(v3.GetSize() == 3); c4_View v4 = p2 (v1[2]); A(v4.GetSize() == 2); } { c4_Storage s1 ("s10c", 1); c4_View v1 = s1.View("a"); A(v1.GetSize() == 3); c4_View v2 = p2 (v1[0]); A(v2.GetSize() == 1); c4_View v3 = p2 (v1[1]); A(v3.GetSize() == 3); c4_View v4 = p2 (v1[2]); A(v4.GetSize() == 2); v1.Add(p1 ["four"]); s1.Commit(); } { c4_Storage s1 ("s10c", 0); c4_View v1 = s1.View("a"); A(v1.GetSize() == 4); c4_View v2 = p2 (v1[0]); A(v2.GetSize() == 1); c4_View v3 = p2 (v1[1]); A(v3.GetSize() == 3); c4_View v4 = p2 (v1[2]); A(v4.GetSize() == 2); c4_View v5 = p2 (v1[3]); A(v5.GetSize() == 0); } } D(s10a); D(s10b); D(s10c); R(s10a); R(s10b); R(s10c); E; B(s11, Commit and rollback, 0) W(s11a); { c4_IntProp p1 ("p1"); { c4_Storage s1 ("s11a", 1); s1.SetStructure("a[p1:I]"); c4_View v1 = s1.View("a"); v1.Add(p1 [123]); s1.Commit(); } { c4_Storage s1 ("s11a", 0); c4_View v1 = s1.View("a"); A(v1.GetSize() == 1); A(p1 (v1[0]) == 123); v1.InsertAt(0, p1 [234]); A(v1.GetSize() == 2); A(p1 (v1[0]) == 234); A(p1 (v1[1]) == 123); s1.Rollback(); // 19990916 - semantics changed, still 2 rows, but 0 props A(v1.GetSize() == 2); A(v1.NumProperties() == 0); v1 = s1.View("a"); A(v1.GetSize() == 1); A(p1 (v1[0]) == 123); } } D(s11a); R(s11a); E; B(s12, Remove subview, 0) W(s12a); { c4_IntProp p1 ("p1"), p3 ("p3"); c4_ViewProp p2 ("p2"); { c4_Storage s1 ("s12a", 1); s1.SetStructure("a[p1:I,p2[p3:I]]"); c4_View v1 = s1.View("a"); c4_View v2; v2.Add(p3 [234]); v1.Add(p1 [123] + p2 [v2]); s1.Commit(); } { c4_Storage s1 ("s12a", 1); c4_View v1 = s1.View("a"); A(v1.GetSize() == 1); A(p1 (v1[0]) == 123); c4_View v2 = p2 (v1[0]); A(v2.GetSize() == 1); A(p3 (v2[0]) == 234); v1.RemoveAt(0); A(v1.GetSize() == 0); s1.Commit(); A(v1.GetSize() == 0); } } D(s12a); R(s12a); E; B(s13, Remove middle subview, 0) W(s13a); { c4_IntProp p1 ("p1"), p3 ("p3"); c4_ViewProp p2 ("p2"); { c4_Storage s1 ("s13a", 1); s1.SetStructure("a[p1:I,p2[p3:I]]"); c4_View v1 = s1.View("a"); c4_View v2a; v2a.Add(p3 [234]); v1.Add(p1 [123] + p2 [v2a]); c4_View v2b; v2b.Add(p3 [345]); v2b.Add(p3 [346]); v1.Add(p1 [124] + p2 [v2b]); c4_View v2c; v2c.Add(p3 [456]); v2c.Add(p3 [457]); v2c.Add(p3 [458]); v1.Add(p1 [125] + p2 [v2c]); s1.Commit(); } { c4_Storage s1 ("s13a", 1); c4_View v1 = s1.View("a"); A(v1.GetSize() == 3); A(p1 (v1[0]) == 123); A(p1 (v1[1]) == 124); A(p1 (v1[2]) == 125); c4_View v2a = p2 (v1[0]); A(v2a.GetSize() == 1); A(p3 (v2a[0]) == 234); c4_View v2b = p2 (v1[1]); A(v2b.GetSize() == 2); A(p3 (v2b[0]) == 345); c4_View v2c = p2 (v1[2]); A(v2c.GetSize() == 3); A(p3 (v2c[0]) == 456); v1.RemoveAt(1); A(v1.GetSize() == 2); v2a = p2 (v1[0]); A(v2a.GetSize() == 1); A(p3 (v2a[0]) == 234); v2b = p2 (v1[1]); A(v2b.GetSize() == 3); A(p3 (v2b[0]) == 456); s1.Commit(); A(v1.GetSize() == 2); A(p1 (v1[0]) == 123); A(p1 (v1[1]) == 125); } } D(s13a); R(s13a); E; B(s14, Replace attached subview, 0) W(s14a); { c4_IntProp p1 ("p1"); c4_ViewProp p2 ("p2"); { c4_Storage s1 ("s14a", 1); s1.SetStructure("a[p1:I,p2[p3:I]]"); c4_View v1 = s1.View("a"); v1.Add(p1 [123] + p2 [c4_View ()]); A(v1.GetSize() == 1); v1[0] = p2 [c4_View ()]; A(v1.GetSize() == 1); A(p1 (v1[0]) == 0); s1.Commit(); } } D(s14a); R(s14a); E; B(s15, Add after removed subviews, 0) W(s15a); { c4_IntProp p1 ("p1"), p3 ("p3"); c4_ViewProp p2 ("p2"); { c4_Storage s1 ("s15a", 1); s1.SetStructure("a[p1:I,p2[p3:I]]"); c4_View v1 = s1.View("a"); c4_View v2; v2.Add(p3 [234]); v1.Add(p1 [123] + p2 [v2]); v1.Add(p1 [456] + p2 [v2]); v1.Add(p1 [789] + p2 [v2]); A(v1.GetSize() == 3); v1[0] = v1[2]; v1.RemoveAt(2); v1[0] = v1[1]; v1.RemoveAt(1); v1.RemoveAt(0); v1.Add(p1 [111] + p2 [v2]); s1.Commit(); } } D(s15a); R(s15a); E; B(s16, Add after removed ints, 0) W(s16a); { c4_IntProp p1 ("p1"); c4_Storage s1 ("s16a", 1); s1.SetStructure("a[p1:I,p2[p3:I]]"); c4_View v1 = s1.View("a"); v1.Add(p1 [1]); v1.Add(p1 [2]); v1.Add(p1 [3]); v1.RemoveAt(2); v1.RemoveAt(1); v1.RemoveAt(0); v1.Add(p1 [4]); s1.Commit(); } D(s16a); R(s16a); E; B(s17, Add after removed strings, 0) W(s17a); { c4_StringProp p1 ("p1"); c4_Storage s1 ("s17a", 1); s1.SetStructure("a[p1:S,p2[p3:I]]"); c4_View v1 = s1.View("a"); v1.Add(p1 ["one"]); v1.Add(p1 ["two"]); v1.Add(p1 ["three"]); v1.RemoveAt(2); v1.RemoveAt(1); v1.RemoveAt(0); v1.Add(p1 ["four"]); s1.Commit(); } D(s17a); R(s17a); E; B(s18, Empty storage, 0) W(s18a); { c4_Storage s1 ("s18a", 1); } D(s18a); R(s18a); E; B(s19, Empty view outlives storage, 0) W(s19a); { c4_View v1; c4_Storage s1 ("s19a", 1); v1 = s1.GetAs("a[p1:I,p2:S]"); } D(s19a); R(s19a); E; }
ShaderProgram::ShaderProgram(const char *vertex, const char *fragment, const ShaderFlags &flags) { File::uptr vs, fs; v = glCreateShader(GL_VERTEX_SHADER); f = glCreateShader(GL_FRAGMENT_SHADER); uint64 size; vs = File::map(vertex, File::Read, &size); std::unique_ptr<char[]> vs1(new char[size + 1]); memcpy(vs1.get(), vs.get(), size * sizeof(char)); vs1[size] = 0; fs = File::map(fragment, File::Read, &size); std::unique_ptr<char[]> fs1(new char[size + 1]); memcpy(fs1.get(), fs.get(), size * sizeof(char)); fs1[size] = 0; //TODO: Może troszkę to ulepszyć... (Chodzi o to, że header trzeba dokleić po #version) const char * vv = vs1.get(); std::string fscode = fs1.get(); size_t ver = fscode.find("#version"); ver = fscode.find("\n", ver); std::string ffs = fscode.substr(0, ver) + "\n" + flags.getHeader() + fscode.substr(ver + 1); const char * ff = ffs.c_str(); glShaderSource(v, 1, &vv, NULL); glShaderSource(f, 1, &ff, NULL); GLint status; glCompileShader(v); glGetShaderiv(v, GL_INFO_LOG_LENGTH, &status); std::unique_ptr<GLchar[]> buffer(new GLchar[status]); glGetShaderInfoLog(v, status, &status, buffer.get()); glGetShaderiv(v, GL_COMPILE_STATUS, &status); if(status != GL_TRUE) RAISE(ShaderException, "Error while compiling Vertex Shader!", buffer.get()); else LOG(errorLogger, "Vertex Shader Info Log:%s\n", buffer.get()); glCompileShader(f); glGetShaderiv(f, GL_INFO_LOG_LENGTH, &status); buffer = std::unique_ptr<GLchar[]>(new GLchar[status]); glGetShaderInfoLog(f, status, &status, buffer.get()); glGetShaderiv(f, GL_COMPILE_STATUS, &status); if(status != GL_TRUE) RAISE(ShaderException, "Error while compiling Fragment Shader!", buffer.get()); else LOG(errorLogger, "Fragment Shader Info Log:%s\n", buffer.get()); p = glCreateProgram(); glAttachShader(p, v); glAttachShader(p, f); glLinkProgram(p); glValidateProgram(p); glGetProgramiv(p, GL_INFO_LOG_LENGTH, &status); buffer = std::unique_ptr<GLchar[]>(new GLchar[status]); glGetProgramInfoLog(p, status, &status, buffer.get()); glGetProgramiv(p, GL_VALIDATE_STATUS, &status); if(status != GL_TRUE) RAISE(ShaderException, "Error while linking / validating Shader Program!", buffer.get()); else LOG(errorLogger, "Shader Program Info Log:%s\n", buffer.get()); HASSERT(p && v && f); }
void TestLimits() { B(l00, Lots of properties, 0)W(l00a); { c4_String desc; for (int i = 1; i < 150; ++i) { char buf[20]; sprintf(buf, ",p%d:I", i); desc += buf; } desc = "a[" + desc.Mid(1) + "]"; c4_Storage s1("l00a", 1); s1.SetStructure(desc); c4_View v1 = s1.View("a"); c4_IntProp p123("p123"); v1.Add(p123[123]); s1.Commit(); } D(l00a); R(l00a); E; B(l01, Over 32 Kb of integers, 0)W(l01a); { c4_Storage s1("l01a", 1); s1.SetStructure("a[p1:I]"); c4_View v1 = s1.View("a"); c4_IntProp p1("p1"); v1.SetSize(9000); for (int i = 0; i < v1.GetSize(); ++i) { p1(v1[i]) = 1000000L + i; A(p1(v1[i]) - 1000000L == i); } for (int j = 0; j < v1.GetSize(); ++j) { A(p1(v1[j]) - 1000000L == j); } s1.Commit(); for (int k = 0; k < v1.GetSize(); ++k) { A(p1(v1[k]) - 1000000L == k); } } D(l01a); R(l01a); E; B(l02, Over 64 Kb of strings, 0)W(l02a); { static char *texts[3] = { "Alice in Wonderland", "The wizard of Oz", "I'm singin' in the rain" }; c4_Storage s1("l02a", 1); s1.SetStructure("a[p1:S]"); c4_View v1 = s1.View("a"); c4_StringProp p1("p1"); c4_Row r1; for (int i = 0; i < 3500; ++i) { p1(r1) = texts[i % 3]; v1.Add(r1); A(p1(v1[i]) == (c4_String)texts[i % 3]); } for (int j = 0; j < v1.GetSize(); ++j) { A(p1(v1[j]) == (c4_String)texts[j % 3]); } s1.Commit(); for (int k = 0; k < v1.GetSize(); ++k) { A(p1(v1[k]) == (c4_String)texts[k % 3]); } } D(l02a); R(l02a); E; B(l03, Force sections in storage, 0)W(l03a); W(l03b); { c4_ViewProp p1("p1"); c4_IntProp p2("p2"); { c4_Storage s1("l03a", 1); s1.SetStructure("a[p1[p2:I]]"); c4_View v1 = s1.View("a"); c4_View v2; v2.SetSize(1); for (int i = 0; i < 500; ++i) { p2(v2[0]) = 9000+i; v1.Add(p1[v2]); } s1.Commit(); } { c4_Storage s1("l03a", 0); c4_View v1 = s1.View("a"); for (int i = 0; i < 500; ++i) { c4_View v2 = p1(v1[i]); A(p2(v2[0]) == 9000+i); } c4_FileStream fs1(fopen("l03b", "wb"), true); s1.SaveTo(fs1); } { c4_Storage s1; c4_FileStream fs1(fopen("l03b", "rb"), true); s1.LoadFrom(fs1); c4_View v1 = s1.View("a"); for (int i = 0; i < 500; ++i) { c4_View v2 = p1(v1[i]); A(p2(v2[0]) == 9000+i); } } } D(l03a); D(l03b); R(l03a); R(l03b); E; B(l04, Modify sections in storage, 0)W(l04a); { c4_ViewProp p1("p1"); c4_IntProp p2("p2"); { c4_Storage s1("l04a", 1); s1.SetStructure("a[p1[p2:I]]"); c4_View v1 = s1.View("a"); c4_View v2; v2.SetSize(1); for (int i = 0; i < 500; ++i) { p2(v2[0]) = 9000+i; v1.Add(p1[v2]); } s1.Commit(); } { c4_Storage s1("l04a", 1); c4_View v1 = s1.View("a"); c4_View v2 = p1(v1[0]); p2(v2[0]) = 1; // this corrupted file in 1.5: free space was bad after load s1.Commit(); } { c4_Storage s1("l04a", 0); } } D(l04a); R(l04a); E; B(l05, Delete from 32 Kb of strings, 0)W(l05a); { static char *texts[3] = { "Alice in Wonderland", "The wizard of Oz", "I'm singin' in the rain" }; c4_Storage s1("l05a", 1); s1.SetStructure("a[p1:I,p2:S,p3:S]"); c4_View v1 = s1.View("a"); c4_IntProp p1("p1"); c4_StringProp p2("p2"), p3("p3"); c4_Row r1; for (int i = 0; i < 1750; ++i) { p1(r1) = i; p2(r1) = texts[i % 3]; p3(r1) = texts[i % 3]; v1.Add(r1); A(p2(v1[i]) == (c4_String)texts[i % 3]); } for (int j = 0; j < v1.GetSize(); ++j) { A(p1(v1[j]) == j); A(p2(v1[j]) == (c4_String)texts[j % 3]); A(p3(v1[j]) == (c4_String)texts[j % 3]); } s1.Commit(); while (v1.GetSize() > 1) // randomly remove entries v1.RemoveAt((unsigned short)(211 *v1.GetSize()) % v1.GetSize()); s1.Commit(); } D(l05a); R(l05a); E; B(l06, Bit field manipulations, 0)W(l06a); { c4_IntProp p1("p1"); c4_View v2; { c4_Storage s1("l06a", 1); s1.SetStructure("a[p1:I]"); c4_View v1 = s1.View("a"); c4_Row r1; for (int i = 2; i <= 256; i <<= 1) { for (int j = 0; j < 18; ++j) { p1(r1) = j &(i - 1); v1.InsertAt(j, r1, j + 1); v2.InsertAt(j, r1, j + 1); } s1.Commit(); } } { c4_Storage s1("l06a", 0); c4_View v1 = s1.View("a"); int n = v2.GetSize(); A(n == v1.GetSize()); for (int i = 0; i < n; ++i) { long v = p1(v2[i]); A(p1(v1[i]) == v); } } } D(l06a); R(l06a); E; B(l07, Huge description, 0)W(l07a); { c4_String desc; for (int i = 1; i < 150; ++i) { char buf[50]; // 1999-07-25: longer size to force over 4 Kb of description sprintf(buf, ",a123456789a123456789a123456789p%d:I", i); desc += buf; } desc = "a[" + desc.Mid(1) + "]"; c4_Storage s1("l07a", 1); s1.SetStructure(desc); c4_View v1 = s1.View("a"); c4_IntProp p123("p123"); v1.Add(p123[123]); s1.Commit(); } D(l07a); R(l07a); E; }
/// Calibrates the extrinsic parameters of the setup and saves it to an XML file /// Press'r' to retreive chessboard corners /// 's' to save and exit /// 'c' to exit without saving /// In: inputCapture1: video feed of camera 1 /// inputCapture2: video feed of camera 2 void CalibrateEnvironment(VideoCapture& inputCapture1, VideoCapture& inputCapture2) { Size boardSize; boardSize.width = BOARD_WIDTH; boardSize.height = BOARD_HEIGHT; const string fileName1 = "CameraIntrinsics1.xml"; const string fileName2 = "CameraIntrinsics2.xml"; cerr << "Attempting to open configuration files" << endl; FileStorage fs1(fileName1, FileStorage::READ); FileStorage fs2(fileName2, FileStorage::READ); Mat cameraMatrix1, cameraMatrix2; Mat distCoeffs1, distCoeffs2; fs1["Camera_Matrix"] >> cameraMatrix1; fs1["Distortion_Coefficients"] >> distCoeffs1; fs2["Camera_Matrix"] >> cameraMatrix2; fs2["Distortion_Coefficients"] >> distCoeffs2; if (cameraMatrix1.data == NULL || distCoeffs1.data == NULL || cameraMatrix2.data == NULL || distCoeffs2.data == NULL) { cerr << "Could not load camera intrinsics\n" << endl; } else{ cerr << "Loaded intrinsics\n" << endl; cerr << "Camera Matrix1: " << cameraMatrix1 << endl; cerr << "Camera Matrix2: " << cameraMatrix2 << endl; } Mat translation; Mat image1, image2; Mat mapX1, mapX2, mapY1, mapY2; inputCapture1.read(image1); Size imageSize = image1.size(); bool rotationCalibrated = false; while(inputCapture1.isOpened() && inputCapture2.isOpened()) { inputCapture1.read(image1); inputCapture2.read(image2); if (rotationCalibrated) { Mat t1 = image1.clone(); Mat t2 = image2.clone(); remap(t1, image1, mapX1, mapY1, INTER_LINEAR); remap(t2, image2, mapX2, mapY2, INTER_LINEAR); t1.release(); t2.release(); } char c = waitKey(15); if (c == 'c') { cerr << "Cancelling..." << endl; return; } else if(c == 's' && rotationCalibrated) { cerr << "Saving..." << endl; const string fileName = "EnvironmentCalibration.xml"; FileStorage fs(fileName, FileStorage::WRITE); fs << "Camera_Matrix_1" << getOptimalNewCameraMatrix(cameraMatrix1, distCoeffs1, imageSize, 1,imageSize, 0); fs << "Camera_Matrix_2" << getOptimalNewCameraMatrix(cameraMatrix2, distCoeffs2, imageSize, 1, imageSize, 0); fs << "Mapping_X_1" << mapX1; fs << "Mapping_Y_1" << mapY1; fs << "Mapping_X_2" << mapX2; fs << "Mapping_Y_2" << mapY2; fs << "Translation" << translation; cerr << "Exiting..." << endl; destroyAllWindows(); return; } else if(c == 's' && !rotationCalibrated) { cerr << "Exiting..." << endl; destroyAllWindows(); return; } else if (c == 'r') { BoardSettings s; s.boardSize.width = BOARD_WIDTH; s.boardSize.height = BOARD_HEIGHT; s.cornerNum = s.boardSize.width * s.boardSize.height; s.squareSize = (float)SQUARE_SIZE; vector<Point3f> objectPoints; vector<vector<Point2f> > imagePoints1, imagePoints2; if (RetrieveChessboardCorners(imagePoints1, imagePoints2, s, inputCapture1, inputCapture2, ITERATIONS)) { vector<vector<Point3f> > objectPoints(1); CalcBoardCornerPositions(s.boardSize, s.squareSize, objectPoints[0]); objectPoints.resize(imagePoints1.size(),objectPoints[0]); Mat R, T, E, F; Mat rmat1, rmat2, rvec; double rms = stereoCalibrate(objectPoints, imagePoints1, imagePoints2, cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2, imageSize, R, T, E, F, TermCriteria( CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 1000, 0.01), CV_CALIB_FIX_INTRINSIC); cerr << "Original translation: " << T << endl; cerr << "Reprojection error reported by camera: " << rms << endl; // convert to rotation vector and then remove 90 degree offset Rodrigues(R, rvec); rvec.at<double>(1,0) -= 1.570796327; // equal rotation applied to each image...not necessarily needed rvec = rvec/2; Rodrigues(rvec, rmat1); invert(rmat1,rmat2); initUndistortRectifyMap(cameraMatrix1, distCoeffs1, rmat1, getOptimalNewCameraMatrix(cameraMatrix1, distCoeffs1, imageSize, 1,imageSize, 0), imageSize, CV_32FC1, mapX1, mapY1); initUndistortRectifyMap(cameraMatrix2, distCoeffs2, rmat2, getOptimalNewCameraMatrix(cameraMatrix2, distCoeffs2, imageSize, 1, imageSize, 0), imageSize, CV_32FC1, mapX2, mapY2); // reproject points in camera 1 since its rotation has been changed // need to find the translation between cameras based on the new camera 1 orientation for (int i = 0; i < imagePoints1.size(); i++) { Mat pointsMat1 = Mat(imagePoints1[i]); Mat pointsMat2 = Mat(imagePoints2[i]); undistortPoints(pointsMat1, imagePoints1[i], cameraMatrix1, distCoeffs1, rmat1,getOptimalNewCameraMatrix(cameraMatrix1, distCoeffs1, imageSize, 1, imageSize, 0)); undistortPoints(pointsMat2, imagePoints2[i], cameraMatrix2, distCoeffs2, rmat2,getOptimalNewCameraMatrix(cameraMatrix2, distCoeffs2, imageSize, 1, imageSize, 0)); pointsMat1.release(); pointsMat2.release(); } Mat temp1, temp2; R.release(); T.release(); E.release(); F.release(); // TODO: remove this // CalcBoardCornerPositions(s.boardSize, s.squareSize, objectPoints[0]); // objectPoints.resize(imagePoints1.size(),objectPoints[0]); stereoCalibrate(objectPoints, imagePoints1, imagePoints2, cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2, imageSize, R, T, E, F, TermCriteria( CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 1000, 0.01), CV_CALIB_FIX_INTRINSIC); // need to alter translation matrix so // [0] = distance in X direction (right from perspective of camera 1 is positive) // [1] = distance in Y direction (away from camera 1 is positive) // [2] = distance in Z direction (up is positive) translation = T; double temp = -translation.at<double>(0,0); translation.at<double>(0,0) = translation.at<double>(2,0); translation.at<double>(2,0) = temp; cerr << "Translation reproj: " << translation << endl; Rodrigues(R, rvec); cerr << "Reprojected rvec: " << rvec << endl; imagePoints1.clear(); imagePoints2.clear(); rvec.release(); rmat1.release(); rmat2.release(); R.release(); T.release(); E.release(); F.release(); rotationCalibrated = true; } } imshow("Image View1", image1); imshow("Image View2", image2); } }
int main(int argc, char** argv) { string dir = "foodcamimages/TRAIN", filepath; DIR *dp; struct dirent *dirp; struct stat filestat; dp = opendir( dir.c_str() ); // detecting keypoints SurfFeatureDetector detector(400); //FastFeatureDetector detector(1,true); vector<KeyPoint> keypoints; // computing descriptors //Ptr<DescriptorExtractor > extractor(new SurfDescriptorExtractor());// extractor; Ptr<DescriptorExtractor > extractor( new OpponentColorDescriptorExtractor( Ptr<DescriptorExtractor>(new SurfDescriptorExtractor()) ) ); Mat descriptors; Mat training_descriptors(1,extractor->descriptorSize(),extractor->descriptorType()); Mat img; cout << "------- build vocabulary ---------\n"; cout << "extract descriptors.."<<endl; //int count = 0; Rect clipping_rect = Rect(0,120,640,480-120); Mat bg_ = imread("background.png")(clipping_rect), img_fg; while (dirp = readdir( dp )) { // count++; filepath = dir + "/" + dirp->d_name; // If the file is a directory (or is in some way invalid) we'll skip it if (stat( filepath.c_str(), &filestat )) continue; if (S_ISDIR( filestat.st_mode )) continue; img = imread(filepath); if (!img.data) { continue; } img = img(clipping_rect); img_fg = img - bg_; detector.detect(img_fg, keypoints); // { // Mat out; //img_fg.copyTo(out); // drawKeypoints(img, keypoints, out, Scalar(255)); // imshow("fg",img_fg); // imshow("keypoints", out); // waitKey(0); // } extractor->compute(img, keypoints, descriptors); training_descriptors.push_back(descriptors); cout << "."; } cout << endl; closedir( dp ); cout << "Total descriptors: " << training_descriptors.rows << endl; FileStorage fs("training_descriptors.yml", FileStorage::WRITE); fs << "training_descriptors" << training_descriptors; fs.release(); BOWKMeansTrainer bowtrainer(1000); //num clusters bowtrainer.add(training_descriptors); cout << "cluster BOW features" << endl; Mat vocabulary = bowtrainer.cluster(); FileStorage fs1("vocabulary_color_1000.yml", FileStorage::WRITE); fs1 << "vocabulary" << vocabulary; fs1.release(); }
void TestStores4() { B(s30, Memo storage, 0)W(s30a); { c4_Bytes hi("hi", 2); c4_Bytes gday("gday", 4); c4_Bytes hello("hello", 5); c4_MemoProp p1("p1"); c4_Storage s1("s30a", 1); s1.SetStructure("a[p1:B]"); c4_View v1 = s1.View("a"); v1.Add(p1[hi]); A(p1(v1[0]) == hi); v1.Add(p1[hello]); A(p1(v1[0]) == hi); A(p1(v1[1]) == hello); v1.InsertAt(1, p1[gday]); A(p1(v1[0]) == hi); A(p1(v1[1]) == gday); A(p1(v1[2]) == hello); s1.Commit(); A(p1(v1[0]) == hi); A(p1(v1[1]) == gday); A(p1(v1[2]) == hello); } D(s30a); R(s30a); E; // this failed in the unbuffered 1.8.5a interim release in Mk4tcl 1.0.5 B(s31, Check sort buffer use, 0)W(s31a); { c4_IntProp p1("p1"); c4_Storage s1("s31a", 1); s1.SetStructure("a[p1:I]"); c4_View v1 = s1.View("a"); v1.Add(p1[3]); v1.Add(p1[1]); v1.Add(p1[2]); s1.Commit(); c4_View v2 = v1.SortOn(p1); A(v2.GetSize() == 3); A(p1(v2[0]) == 1); A(p1(v2[1]) == 2); A(p1(v2[2]) == 3); } D(s31a); R(s31a); E; // this failed in 1.8.6, fixed 19990828 B(s32, Set memo empty or same size, 0)W(s32a); { c4_Bytes empty; c4_Bytes full("full", 4); c4_Bytes more("more", 4); c4_MemoProp p1("p1"); c4_Storage s1("s32a", 1); s1.SetStructure("a[p1:B]"); c4_View v1 = s1.View("a"); v1.Add(p1[full]); A(p1(v1[0]) == full); s1.Commit(); A(p1(v1[0]) == full); p1(v1[0]) = empty; A(p1(v1[0]) == empty); s1.Commit(); A(p1(v1[0]) == empty); p1(v1[0]) = more; A(p1(v1[0]) == more); s1.Commit(); A(p1(v1[0]) == more); p1(v1[0]) = full; A(p1(v1[0]) == full); s1.Commit(); A(p1(v1[0]) == full); } D(s32a); R(s32a); E; // this failed in 1.8.6, fixed 19990828 B(s33, Serialize memo fields, 0)W(s33a); W(s33b); W(s33c); { c4_Bytes hi("hi", 2); c4_Bytes gday("gday", 4); c4_Bytes hello("hello", 5); c4_MemoProp p1("p1"); c4_Storage s1("s33a", 1); s1.SetStructure("a[p1:B]"); c4_View v1 = s1.View("a"); v1.Add(p1[hi]); v1.Add(p1[gday]); v1.Add(p1[hello]); A(p1(v1[0]) == hi); A(p1(v1[1]) == gday); A(p1(v1[2]) == hello); s1.Commit(); A(p1(v1[0]) == hi); A(p1(v1[1]) == gday); A(p1(v1[2]) == hello); { c4_FileStream fs1(fopen("s33b", "wb"), true); s1.SaveTo(fs1); } c4_Storage s2("s33c", 1); c4_FileStream fs2(fopen("s33b", "rb"), true); s2.LoadFrom(fs2); c4_View v2 = s2.View("a"); A(p1(v2[0]) == hi); A(p1(v2[1]) == gday); A(p1(v2[2]) == hello); s2.Commit(); A(p1(v2[0]) == hi); A(p1(v2[1]) == gday); A(p1(v2[2]) == hello); s2.Commit(); A(p1(v2[0]) == hi); A(p1(v2[1]) == gday); A(p1(v2[2]) == hello); } D(s33a); D(s33b); D(s33c); R(s33a); R(s33b); R(s33c); E; // check smarter commit and commit failure on r/o B(s34, Smart and failed commits, 0)W(s34a); { c4_IntProp p1("p1"); { c4_Storage s1("s34a", 1); s1.SetStructure("a[p1:I]"); c4_View v1 = s1.View("a"); v1.Add(p1[111]); A(v1.GetSize() == 1); A(p1(v1[0]) == 111); bool f1 = s1.Commit(); A(f1); A(v1.GetSize() == 1); A(p1(v1[0]) == 111); bool f2 = s1.Commit(); A(f2); // succeeds, but should not write anything A(v1.GetSize() == 1); A(p1(v1[0]) == 111); } { c4_Storage s1("s34a", 0); c4_View v1 = s1.View("a"); v1.Add(p1[222]); A(v1.GetSize() == 2); A(p1(v1[0]) == 111); A(p1(v1[1]) == 222); bool f1 = s1.Commit(); A(!f1); A(v1.GetSize() == 2); A(p1(v1[0]) == 111); A(p1(v1[1]) == 222); } } D(s34a); R(s34a); E; B(s35, Datafile with preamble, 0)W(s35a); { { c4_FileStream fs1(fopen("s35a", "wb"), true); fs1.Write("abc", 3); } c4_IntProp p1("p1"); { c4_Storage s1("s35a", 1); s1.SetStructure("a[p1:I]"); c4_View v1 = s1.View("a"); v1.Add(p1[111]); A(v1.GetSize() == 1); A(p1(v1[0]) == 111); bool f1 = s1.Commit(); A(f1); A(v1.GetSize() == 1); A(p1(v1[0]) == 111); bool f2 = s1.Commit(); A(f2); // succeeds, but should not write anything A(v1.GetSize() == 1); A(p1(v1[0]) == 111); } { c4_FileStream fs1(fopen("s35a", "rb"), true); char buffer[10]; int n1 = fs1.Read(buffer, 3); A(n1 == 3); A(c4_String(buffer, 3) == "abc"); } { c4_Storage s1("s35a", 0); c4_View v1 = s1.View("a"); A(v1.GetSize() == 1); A(p1(v1[0]) == 111); v1.Add(p1[222]); A(v1.GetSize() == 2); A(p1(v1[0]) == 111); A(p1(v1[1]) == 222); bool f1 = s1.Commit(); A(!f1); A(v1.GetSize() == 2); A(p1(v1[0]) == 111); A(p1(v1[1]) == 222); } } D(s35a); R(s35a); E; B(s36, Commit after load, 0)W(s36a); W(s36b); { c4_IntProp p1("p1"); c4_Storage s1("s36a", 1); s1.SetStructure("a[p1:I]"); c4_View v1 = s1.View("a"); v1.Add(p1[111]); A(v1.GetSize() == 1); A(p1(v1[0]) == 111); { c4_FileStream fs1(fopen("s36b", "wb"), true); s1.SaveTo(fs1); } p1(v1[0]) = 222; v1.Add(p1[333]); bool f1 = s1.Commit(); A(f1); A(v1.GetSize() == 2); A(p1(v1[0]) == 222); A(p1(v1[1]) == 333); c4_FileStream fs2(fopen("s36b", "rb"), true); s1.LoadFrom(fs2); //A(v1.GetSize() == 0); // should be detached, but it's still 2 c4_View v2 = s1.View("a"); A(v2.GetSize() == 1); A(p1(v2[0]) == 111); // this fails in 2.4.0, reported by James Lupo, August 2001 bool f2 = s1.Commit(); A(f2); } D(s36a); D(s36b); R(s36a); R(s36b); E; // fails in 2.4.1, reported Oct 31. 2001 by Steve Baxter B(s37, Change short partial fields, 0)W(s37a); { c4_BytesProp p1("p1"); c4_Storage s1("s37a", true); c4_View v1 = s1.GetAs("v1[key:I,p1:B]"); v1.Add(p1[c4_Bytes("12345", 6)]); A(v1.GetSize() == 1); s1.Commit(); c4_Bytes buf = p1(v1[0]); A(buf.Size() == 6); A(buf == c4_Bytes("12345", 6)); buf = p1(v1[0]).Access(1, 3); A(buf == c4_Bytes("234", 3)); p1(v1[0]).Modify(c4_Bytes("ab", 2), 2, 0); s1.Commit(); buf = p1(v1[0]); A(buf == c4_Bytes("12ab5", 6)); } D(s37a); R(s37a); E; // Gross memory use (but no leaks), January 2002, Murat Berk B(s38, Lots of empty subviews, 0)W(s38a); { c4_BytesProp p1("p1"); { c4_Storage s1("s38a", true); c4_View v = s1.GetAs("v[v1[p1:S]]"); v.SetSize(100000); s1.Commit(); } { c4_Storage s2("s38a", true); c4_View v2 = s2.View("v"); // this should not materialize all the empty subviews v2.SetSize(v2.GetSize() + 1); // nor should this s2.Commit(); } { c4_Storage s3("s38a", true); c4_View v3 = s3.View("v"); v3.RemoveAt(1, v3.GetSize() - 2); A(v3.GetSize() == 2); s3.Commit(); } } D(s38a); R(s38a); E; // Fix bug introduced on 7-2-2002, as reported by M. Berk B(s39, Do not detach empty top-level views, 0)W(s39a); { c4_IntProp p1("p1"); c4_Storage s1("s39a", true); c4_View v1 = s1.GetAs("v1[p1:I]"); s1.Commit(); A(v1.GetSize() == 0); v1.Add(p1[123]); A(v1.GetSize() == 1); s1.Commit(); c4_View v2 = s1.View("v1"); A(v2.GetSize() == 1); // fails with 0 due to recent bug } D(s39a); R(s39a); E; }