// Save the training data to the file 'facedata.xml'. void storeTrainingData() { CvFileStorage * fileStorage; int i; // create a file-storage interface fileStorage = cvOpenFileStorage( facedata, 0, CV_STORAGE_WRITE ); // Store the person names. Added by Shervin. cvWriteInt( fileStorage, "nPersons", nPersons ); for (i=0; i<nPersons; i++) { char varname[200]; sprintf( varname, "personName_%d", (i+1) ); cvWriteString(fileStorage, varname, personNames[i].c_str(), 0); } // store all the data cvWriteInt( fileStorage, "nEigens", nEigens ); cvWriteInt( fileStorage, "nTrainFaces", nTrainFaces ); cvWrite(fileStorage, "trainPersonNumMat", personNumTruthMat, cvAttrList(0,0)); cvWrite(fileStorage, "eigenValMat", eigenValMat, cvAttrList(0,0)); cvWrite(fileStorage, "projectedTrainFaceMat", projectedTrainFaceMat, cvAttrList(0,0)); cvWrite(fileStorage, "avgTrainImg", pAvgTrainImg, cvAttrList(0,0)); for(i=0; i<nEigens; i++) { char varname[200]; sprintf( varname, "eigenVect_%d", i ); cvWrite(fileStorage, varname, eigenVectArr[i], cvAttrList(0,0)); } // release the file-storage interface cvReleaseFileStorage( &fileStorage ); }
void SaveFeature( FEATURE* feature, char* fileName){ CvFileStorage* fs = cvOpenFileStorage( fileName, 0, CV_STORAGE_WRITE, NULL); if (fs==NULL){ fprintf(stderr, "can't open feature file\n"); return; } cvWriteInt(fs, "radius", feature->radius); cvWriteInt(fs, "neighbors", feature->neighbors); cvWriteInt(fs, "grid_x", feature->grid_x); cvWriteInt(fs, "grid_y", feature->grid_y); cvWriteInt(fs, "num_faces", feature->num_faces); char faceid[1024]; char id[1024]; for (int i=0; i<feature->num_faces; i++){ strcpy(faceid, "face-"); sprintf(id, "%d", i); strcat(faceid, id); cvWrite( fs, faceid, feature->histogram[i], cvAttrList(0,0) ); } if (HUELBP_ON){ for (int i=0; i<feature->num_faces; i++){ strcpy(faceid, "hue-face-"); sprintf(id, "%d", i); strcat(faceid, id); cvWrite( fs, faceid, feature->hue_histogram[i], cvAttrList(0,0) ); } } cvReleaseFileStorage( &fs ); }
//存储训练结果 void storeTrainingData() { CvFileStorage * fileStorage; int i; fileStorage = cvOpenFileStorage( "facedata.xml", 0, CV_STORAGE_WRITE ); //存储特征值,投影矩阵,平均矩阵等训练结果 cvWriteInt( fileStorage, "nEigens", nEigens ); cvWriteInt( fileStorage, "nTrainFaces", nTrainFaces ); cvWrite(fileStorage, "trainPersonNumMat", personNumTruthMat, cvAttrList(0,0)); cvWrite(fileStorage, "eigenValMat", eigenValMat, cvAttrList(0,0)); cvWrite(fileStorage, "projectedTrainFaceMat", projectedTrainFaceMat, cvAttrList(0,0)); cvWrite(fileStorage, "avgTrainImg", pAvgTrainImg, cvAttrList(0,0)); for(i=0; i<nEigens; i++) { char varname[200]; sprintf( varname, "eigenVect_%d", i ); cvWrite(fileStorage, varname, eigenVectArr[i], cvAttrList(0,0)); } cvReleaseFileStorage( &fileStorage ); }
int main( int argc, char** argv ) { const char* size_opt = "--size="; char comment[1024]; CvHaarClassifierCascade* cascade = 0; CvSize size; help(); if( argc != 4 || strncmp( argv[1], size_opt, strlen(size_opt) ) != 0 ) { help(); return -1; } sscanf( argv[1], "--size=%ux%u", &size.width, &size.height ); cascade = cvLoadHaarClassifierCascade( argv[2], size ); if( !cascade ) { fprintf( stderr, "Input cascade could not be found/opened\n" ); return -1; } sprintf( comment, "Automatically converted from %s, window size = %dx%d", argv[2], size.width, size.height ); cvSave( argv[3], cascade, 0, comment, cvAttrList(0,0) ); return 0; }
void save_posture_model (CvFileStorage *fs, CvMat *mean, CvMat *cov) { static int i=0; static char asd[]="posture-00"; cvStartWriteStruct(fs, asd, CV_NODE_MAP, NULL, cvAttrList(0,0)); cvWriteInt(fs, "type", i++); cvWrite(fs, "mean", (void*)mean, cvAttrList(0,0)); cvWrite(fs, "cov", (void*)cov, cvAttrList(0,0)); cvEndWriteStruct(fs); if (++asd[9] == ':') { asd[9] = '0'; asd[8]++; } }
void save_sequence (const char *file, ptseq seq, int N) { CvFileStorage *fs; fs = cvOpenFileStorage(file, NULL, CV_STORAGE_WRITE, NULL); cvWriteInt(fs, "N", N); cvWrite(fs, "seq", seq.ptr, cvAttrList(0,0)); cvReleaseFileStorage(&fs); }
int main (int argc, char **argv) { char filename[] = "save_cv.xml"; // file name int i; int a; float b; CvMat** mat; CvFileStorage *cvfs; // (1)create sample data a = 10; b = 0.1; mat = (CvMat**)cvAlloc(3*sizeof(CvMat*)); for(i=0;i<3;i++){ mat[i] = cvCreateMat(3,3,CV_32FC1); cvSet(mat[i], cvScalarAll(i), NULL); } // (2)open file storage cvfs = cvOpenFileStorage(filename,NULL,CV_STORAGE_WRITE); // (3)write data to file cvWriteInt(cvfs, "a", a); cvWriteReal(cvfs, "b", b); cvStartWriteStruct(cvfs, "mat_array", CV_NODE_SEQ, NULL, cvAttrList(NULL, NULL)); // create node for(i=0; i<3; i++){ cvWrite(cvfs, NULL, mat[i], cvAttrList(NULL, NULL)); } cvEndWriteStruct(cvfs); // (4)close file storage cvReleaseFileStorage(&cvfs); // release mat for(i=0; i<3; i++){ cvReleaseMat(mat+i); } cvFree(mat); return 0; }
void storeTrainingData() { CvFileStorage * fileStorage; int i; fileStorage = cvOpenFileStorage( "/etc/pam_face_authentication/facedata.xml", 0, CV_STORAGE_WRITE ); cvWriteInt( fileStorage, "numberOfEigenVectors", numberOfEigenVectors ); cvWriteInt( fileStorage, "numberOfTrainingFaces", numberOfTrainingFaces ); cvWrite(fileStorage, "eigenValueMatrix", eigenValueMatrix, cvAttrList(0,0)); cvWrite(fileStorage, "projectedTrainFaceMat", projectedTrainFaceMat, cvAttrList(0,0)); cvWrite(fileStorage, "avgTrainImg", averageTrainingImage, cvAttrList(0,0)); for (i=0; i<numberOfEigenVectors; i++) { char varname[200]; sprintf( varname, "eigenVect_%d", i ); cvWrite(fileStorage, varname, eigenVectorArray[i], cvAttrList(0,0)); } cvReleaseFileStorage( &fileStorage ); }
////////////////////////////////// // storeTrainingData() // void faceRecognition::storeTrainingData() { CvFileStorage * fileStorage; int i; // create a file-storage interface fileStorage = cvOpenFileStorage( "./res/facedata.xml", 0, CV_STORAGE_WRITE ); // store all the data cvWriteInt( fileStorage, "nEigens", nEigens ); cvWriteInt( fileStorage, "nTrainFaces", nTrainFaces ); cvWrite(fileStorage, "trainPersonNumMat", personNumTruthMat, cvAttrList(0,0)); cvWrite(fileStorage, "eigenValMat", eigenValMat, cvAttrList(0,0)); cvWrite(fileStorage, "projectedTrainFaceMat", projectedTrainFaceMat, cvAttrList(0,0)); cvWrite(fileStorage, "avgTrainImg", pAvgTrainImg, cvAttrList(0,0)); for(i=0; i<nEigens; i++){ char varname[200]; sprintf( varname, "eigenVect_%d", i ); cvWrite(fileStorage, varname, eigenVectArr[i], cvAttrList(0,0)); } // release the file-storage interface cvReleaseFileStorage( &fileStorage); }
void save_pseudocolor(char* file, Pseudocolor *psdata) { CvFileStorage* storage = cvOpenFileStorage( file, 0, CV_STORAGE_WRITE_TEXT ); if(storage==NULL){ fprintf(stderr, "Error open file %s to write \n",file); return; } cvStartWriteStruct(storage, "p", CV_NODE_SEQ, NULL, cvAttrList(0,0)); cvWriteRawData(storage, psdata->p,3,"f"); cvEndWriteStruct(storage); cvStartWriteStruct(storage, "t", CV_NODE_SEQ, NULL, cvAttrList(0,0)); cvWriteRawData(storage, psdata->t,3,"f"); cvEndWriteStruct(storage); cvStartWriteStruct(storage, "table", CV_NODE_SEQ, NULL, cvAttrList(0,0)); cvWriteRawData(storage, psdata->table,255,"u"); cvEndWriteStruct(storage); cvReleaseFileStorage( &storage ); }
bool ObjectDefinition::Save(const char* filename) { do{ CvFileStorage* storage = cvOpenFileStorage(filename, 0, CV_STORAGE_WRITE); cvWrite(storage, "keypoints", m_keypoints); cvWrite(storage, "descriptor", m_descriptor); cvStartWriteStruct(storage, "corners", CV_NODE_SEQ, NULL, cvAttrList(0,0)); cvWriteRawData(storage, m_corners, 4, "ii"); cvEndWriteStruct(storage); cvReleaseFileStorage(&storage); m_filename = filename; return true; }while(false); return false; }
/*! \fn CvBinGabAdaFeatureSelect::saveweaks(const char *filename) */ void CvBinGabAdaFeatureSelect::saveweaks(const char *filename) { CvMemStorage* storage = cvCreateMemStorage(0); CvSeq* seq = cvCreateSeq(0, sizeof(CvSeq), sizeof(CvGaborTree), storage ); int num = weaks.size(); for(int i = 0; i < num; i++ ) { CvGaborFeature *feature; feature = new_pool->getfeature(i); CvGaborTree tree; tree.x = feature->getx(); tree.y = feature->gety(); tree.Mu = feature->getMu(); tree.Nu = feature->getNu(); tree.alpha = alphas[i]; tree.threshold = weaks[i].getthreshold(); tree.parity = weaks[i].getparity(); cvSeqPush( seq, &tree ); } char *weakname = new char[20]; CvMemStorage* xstorage = cvCreateMemStorage( 0 ); CvFileStorage *fs = cvOpenFileStorage( filename, xstorage, CV_STORAGE_WRITE ); for (int i = 0; i <seq->total; i++) { CvGaborTree *atree = (CvGaborTree*)cvGetSeqElem(seq, i); sprintf(weakname, "weak_%d", i); cvStartWriteStruct( fs, weakname, CV_NODE_MAP, "CvGaborTree", cvAttrList(0,0) ); cvWriteInt(fs, "x", atree->x); cvWriteInt(fs, "y", atree->y); cvWriteInt(fs, "Mu", atree->Mu); cvWriteInt(fs, "Nu", atree->Nu); cvWriteReal(fs, "alpha", atree->alpha); cvWriteReal(fs, "threshold", atree->threshold); cvWriteReal(fs, "parity", atree->parity); cvEndWriteStruct( fs ); } /* release memory storage in the end */ delete [] weakname; cvReleaseMemStorage( &xstorage ); cvReleaseMemStorage( &storage ); cvReleaseFileStorage(&fs); }
/*! \fn CvGaborFeature::writeXML(const char* filename) const */ void CvGaborFeature::writeXML(const char* filename) const { CvMemStorage* storage = cvCreateMemStorage( 0 ); CvFileStorage* fs = cvOpenFileStorage( filename, storage, CV_STORAGE_WRITE); cvStartWriteStruct( fs, "CvGaborFeature", CV_NODE_MAP, NULL, cvAttrList(0,0)); cvWriteInt(fs, "x", getx()); cvWriteInt(fs, "y", gety()); cvWriteInt(fs, "Mu",getMu()); cvWriteInt(fs, "Nu",getNu()); cvEndWriteStruct(fs); cvEndWriteStruct( fs ); cvReleaseFileStorage(&fs); cvReleaseMemStorage(&storage); }
/* reads matrix, image, sequence, graph etc. */ CV_IMPL void* cvRead( CvFileStorage* fs, CvFileNode* node, CvAttrList* list ) { void* obj = 0; CV_CHECK_FILE_STORAGE( fs ); if( !node ) return 0; if( !CV_NODE_IS_USER(node->tag) || !node->info ) CV_Error( CV_StsError, "The node does not represent a user object (unknown type?)" ); obj = node->info->read( fs, node ); if( list ) *list = cvAttrList(0,0); return obj; }
void ShapeClassifier::Save() { if (!isTrained) return; Classifier::Save(); USES_CONVERSION; WCHAR filename[MAX_PATH]; // save the contour data wcscpy(filename,directoryName); wcscat(filename, FILE_CONTOUR_NAME); const char* contour_attrs[] = { "recursive", "1", 0 }; cvSave(W2A(filename), templateContours, 0, 0, cvAttrList(contour_attrs,0)); }
int Eigenfaces::saveConfig(const string& dir) { if (DEBUG) cout << "Saving config in "<< dir << endl; string configFile = dir + string("/libface-config.xml"); CvFileStorage* fileStorage = cvOpenFileStorage(d->configFile.c_str(), 0, CV_STORAGE_WRITE); if (!fileStorage) { if (DEBUG) cout << "Cant open for storing :" << d->configFile << endl; return 1; } // Start storing unsigned int nIds = d->faceImgArr.size(), i; // Write some initial params and matrices cvWriteInt( fileStorage, "nIds", nIds ); cvWriteInt( fileStorage, "FACE_WIDTH", d->FACE_WIDTH); cvWriteInt( fileStorage, "FACE_HEIGHT", d->FACE_HEIGHT); cvWriteReal( fileStorage, "THRESHOLD", d->THRESHOLD); // Write all the training faces for ( i = 0; i < nIds; i++ ) { char facename[200]; sprintf(facename, "person_%d", i); cvWrite(fileStorage, facename, d->faceImgArr.at(i), cvAttrList(0,0)); } for ( i = 0; i < nIds; i++ ) { char idname[200]; sprintf(idname, "id_%d", i); cvWriteInt(fileStorage, idname, d->indexMap.at(i)); } // Release the fileStorage cvReleaseFileStorage(&fileStorage); return 0; }
int main(int argc, char*argv[]) { int device; cvNamedWindow(camwindow,CV_WINDOW_AUTOSIZE); CvCapture* capture; CvMat* intrinsic ; CvMat* distortion; if (strcmp(argv[1],"-nocalib") == 0 && (argc == 4)){ MODE = 1; H = (CvMat*)cvLoad(argv[2],NULL,NULL,NULL); device = atoi(argv[3]); capture = cvCaptureFromCAM( device) ; Z=28; printf("\nUsage:\nReset: 'r'\nCrop-ROI: 'c'\nZoom: 'u' +/- 'd'\nSave: 's'\n Quit: 'q' | ESC key\n"); } else if ((strcmp(argv[1],"-calib") == 0) && (argc == 7) ) { MODE = 2; board_w = atoi(argv[2]); board_h = atoi(argv[3]); intrinsic = (CvMat*)cvLoad(argv[4],NULL,NULL,NULL); distortion = (CvMat*)cvLoad(argv[5],NULL,NULL,NULL); device = atoi(argv[6]); capture = cvCaptureFromCAM( device) ; printf("\nUsage:\nZoom: 'u' +/- 'd'\nBird-I-View: 't'\n Quit: 'q' | ESC key\n"); }else { printf("Error:Wrong numbers of input parameters\n"); printf("* if -option == -nocalib then only first 2 parameters are required \ \n Homography matrix \ \n usb-camera device driver \ * if -option == -calib then only 5 addition parameter are required \ \n #inner checkerboard corners generally it is 7x7 \ \n Intrinsic (xml) from Camera Calibration \ \n Distortion (xml) from Camera Calibration \ \n usb-camera device driver\n"); return -1; } if (capture == NULL ){ perror("\nFailure to access camera device\n"); return -1; } CvSize board_sz = cvSize( board_w, board_h ); int board_n = board_w*board_h; int frame=0, found = 0,corner_count = 0; CvPoint2D32f corners[board_n]; cvNamedWindow(BVwindow, CV_WINDOW_AUTOSIZE); cvSetMouseCallback(BVwindow, on_mouse, 0); CvMat stub; IplImage *image = cvQueryFrame( capture ); IplImage *gray_image = cvCreateImage(cvGetSize(image),8,1);//subpixel frame++; //Bird Eye View with ROI birdsview_image = cvCreateImage( cvGetSize(image), image->depth,3 ); Mbvimg = cvGetMat(birdsview_image,&stub,NULL,0); while((MODE == 1 )){ // Capture bird's view image every 10 frames if (frame % board_dt == 0) { cvWarpPerspective( image, birdsview_image, H, CV_INTER_LINEAR | CV_WARP_FILL_OUTLIERS |CV_WARP_INVERSE_MAP , cvScalarAll(0) ); cvShowImage( BVwindow, birdsview_image ); updateImage(); frame=1; } char key = (char) cvWaitKey(2); switch( (char) key ) { case 'r': reset(); if (frame % board_dt != 0) // sychronized updated updateImage(); break; case 'c': BirdEyeROI(); break; case 'u': Z+=0.5; CV_MAT_ELEM(*H,float,2,2) = Z; printf("\n%f",Z); break; case 'd': Z-=0.5; CV_MAT_ELEM(*H,float,2,2) = Z; printf("\n%f",Z); break; case 's': cvSaveImage("birdviewROIimg.bmp",birdsview_image,0); printf("\nImage Saved! Name: birdviewROIimg\n"); break; case 27: case 'q': return 0; break; } cvShowImage(camwindow, image); //overlay points in web cam stream window image = cvQueryFrame(capture); //Get next image frame++; } //Bird Eye View to extract Homography matrix while((MODE == 2 )){ //Skip every board_dt frames to allow user to move chessboard if (frame % board_dt == 0) { found = cvFindChessboardCorners(image,board_sz,corners,&corner_count,CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_FILTER_QUADS); if (found){ cvCvtColor( image,gray_image,CV_BGR2GRAY ); cvFindCornerSubPix( gray_image,corners,corner_count,cvSize(11,11),cvSize(-1,-1),cvTermCriteria( CV_TERMCRIT_EPS |CV_TERMCRIT_ITER,30,0.1)); frame=1; } } char key = (char)cvWaitKey(2); switch (key) { case 'u': Z +=0.5; printf("\n%f",Z); break; case 'd': Z -=0.5; printf("\n%f",Z); break; case 't': BirdsIview(intrinsic,distortion,cvCloneImage(image),corners); break; case 27: case 'q': if (H != NULL){ cvSave("H.xml",H,NULL,NULL,cvAttrList(0,0)); printf("\nHomography Saved! Name: H.xml\n"); } return 0; break; } cvDrawChessboardCorners(image, board_sz, corners, corner_count,found); cvShowImage(camwindow, image); //overlay points in web cam stream window frame++; image = cvQueryFrame(capture); //Get next image } return 0; }
// Main function, defines the entry point for the program. int main( int argc, char** argv ) { // Structure for getting video from camera or avi CvCapture* capture = 0; // Images to capture the frame from video or camera or from file IplImage *frame, *frame_copy = 0; // Input file name for avi or image file. const char* vectorList; const char* testImage; // Check for the correct usage of the command line if( argc == 2 ) { //vectorList = argv[1]; testImage = argv[1]; } else { fprintf( stderr, "Usage: eigenDecomp testImage\n" ); return -1; } // Allocate the memory storage storage = cvCreateMemStorage(0); // Create a new named window with title: result cvNamedWindow( "result", 1 ); std::vector<IplImage*> images; std::vector<char*> labels; //Load Labels printf("Loading Labels... "); FILE* f = fopen( "labels.txt", "rt" ); if( f ) { char buf[100+1]; // Get the line from the file while( fgets( buf, 100, f ) ) { // Remove the spaces if any, and clean up the name int len = (int)strlen(buf); while( len > 0 && isspace(buf[len-1]) ) len--; buf[len] = '\0'; char* str = (char*)malloc(sizeof(char)*100); memcpy(str, buf, 100); labels.push_back(str); } // Close the file fclose(f); printf("%d Labels loaded.\n", labels.size()); } else printf("Failed.\n"); //Load Eigenvectors: printf("Loading Eigenvectors... "); CvFileStorage* fs2 = cvOpenFileStorage("eigenvectors.yml", NULL, CV_STORAGE_READ); char vectorname[50]; CvFileNode* vectorloc = cvGetFileNodeByName(fs2, NULL, "vector0"); for(int i = 1; vectorloc != NULL; i++) { images.push_back((IplImage*)cvRead(fs2, vectorloc, &cvAttrList(0,0))); //printf("pushed %s\n", vectorname); sprintf(vectorname, "vector%d", i); vectorloc = cvGetFileNodeByName(fs2, NULL, vectorname); } //cvReleaseFileStorage(&fs2); This may delete the images printf("%d Eigenvectors (and 1 average) loaded.\n", images.size()-1); //TODO: unfix this number! - Done! //printf("FLANN DIMS: %d, %d\n", 165, images.size()); //cv::Mat mat( 165, images.size(), CV_32F ); //flann::Matrix<float> flannmat; //flann::load_from_file(flannmat, "flann.dat", "flann.dat"); //flann::Index::Index flannIndex(flannmat, flann::LinearIndexParams()); printf("Loading Nearest Neighbor Matrix... "); CvMat* flannmat; CvFileStorage* fs = cvOpenFileStorage("nn.yml", NULL, CV_STORAGE_READ); flannmat = (CvMat*)cvRead(fs, cvGetFileNodeByName(fs, NULL, "data"), &cvAttrList(0,0)); //cvReleaseFileStorage(&fs); This will delete the matrix printf("Done. DIMS: %d, %d\n", flannmat->rows, flannmat->cols); cv::flann::Index::Index flannIndex(flannmat, cv::flann::LinearIndexParams()); int nn_dims = flannmat->cols; //number of nearest neighbor dimensions available int projection_dims = images.size()-1; //number of dimensions to project into eigenspace. IplImage* eigenArray[projection_dims]; IplImage* avgImage = images[0]; for(int i = 0; i < projection_dims; i++) { eigenArray[i] = images[i+1]; } //load test image printf("Loading Test Image...\n"); IplImage* testImg = cvLoadImage(testImage, CV_LOAD_IMAGE_GRAYSCALE); float projection[projection_dims]; // Project the test image onto the PCA subspace printf("Conducting Eigen Decomposite...\n"); cvEigenDecomposite( testImg, //test object projection_dims, //number of eigen vectors (void*)eigenArray, //eigenVectors 0, 0, //ioflags, user callback data avgImage, //root eigen vector projection); //print projection //printf("Eigenvector Coefficents:\n"); //for(int i = 0; i < projection_dims; i++) //printf("%5f ", projection[i]); //printf("\n"); int neighbors = 10; //to test against std::vector<float> proj(nn_dims); std::vector<float> dists(neighbors); std::vector<int> indicies(neighbors); for(int i = 0; i < nn_dims; i++) proj[i] = projection[i]; flannIndex.knnSearch(proj, indicies, dists, neighbors, NULL); for(int i = 0; i < neighbors; i++) printf("Index Match0: %4d, dist: %13.3f, Label: %s\n", indicies[i], dists[i], labels[indicies[i]]); // Destroy the window previously created with filename: "result" cvDestroyWindow("result"); printf("Done.\n"); // return 0 to indicate successfull execution of the program return 0; }
int main( int argc, char *argv[] ) { //IplImage *img = cvLoadImage( "/home/sir/sir02mz/local/FaceDB/FERET/fa/PPMS/00001_930831_fa_a.ppm", CV_LOAD_IMAGE_ANYCOLOR ); // IplImage *img = cvLoadImage( "/local/1_1_2.jpg", CV_LOAD_IMAGE_ANYCOLOR ); // IplImage *grayimg = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 1); // cvCvtColor( img, grayimg, CV_RGB2GRAY ); // cvReleaseImage(&img); // // for(int i = -1; i <= 3; i++) // { // for(int j = 3; j <4 ; j++) // { // CvGabor gabor(j,i); // IplImage *reimg = cvCreateImage(cvGetSize(grayimg), IPL_DEPTH_8U, 1); // gabor.conv_img(grayimg, reimg, CV_GABOR_MAG); // // char *filename = new char[30]; // sprintf(filename, "/local/eteser_%d_%d.jpg", i, j); // cvSaveImage( filename, (IplImage*)reimg ); // delete [] filename; // cvReleaseImage(&reimg); // } // } // // cvReleaseImage(&grayimg); // /* CvTrainingData data; data.loadIris("/local/iris.data"); CvTrainingData *bindata = data.split(2,3); bindata->stat(); CvAdaBoost boost; //boost.train(bindata, 20, CvWeakLearner::ANN); boost.train(bindata, 20, CvWeakLearner::BAYES); delete bindata; */ CvGabor gabor(3,3); CvMat* remat = gabor.get_matrix(CV_GABOR_REAL); CvMat* immat = gabor.get_matrix(CV_GABOR_IMAG); cvSave( "/local/rematrix.xml", (CvMat*)remat, NULL, NULL, cvAttrList()); cvSave( "/local/immatrix.xml", (CvMat*)immat, NULL, NULL, cvAttrList()); IplImage *img = cvLoadImage( "/home/sir/sir02mz/local/FaceDB/FERET/fa/PPMS/00001_930831_fa_a.ppm", CV_LOAD_IMAGE_ANYCOLOR ); IplImage *grayimg = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 1); cvCvtColor( img, grayimg, CV_RGB2GRAY ); IplImage *reimg = cvCreateImage(cvGetSize(grayimg), IPL_DEPTH_32F, 1); cvSave( "/local/gragimage.xml", (IplImage*)grayimg, NULL, NULL, cvAttrList()); gabor.conv_img_a(grayimg, reimg, CV_GABOR_MAG); cvSave( "/local/magimage.xml", (IplImage*)reimg, NULL, NULL, cvAttrList()); cvReleaseImage(&reimg); cvReleaseImage(&img); cvReleaseImage(&grayimg); return 0; }
/*! \fn CvBinGabAdaFeatureSelect::saveweights(const char* filename) */ void CvBinGabAdaFeatureSelect::saveweights(const char* filename) { cvSave( filename, weights, NULL, NULL, cvAttrList()); }
int main(int argc, char* argv[]) { int i, j; CvMemStorage* storage = cvCreateMemStorage(0); IplImage* img = cvCreateImage( cvSize(w,w), 8, 1 ); IplImage* img32f = cvCreateImage( cvSize(w,w), IPL_DEPTH_32F, 1 ); IplImage* img32s = cvCreateImage( cvSize(w,w), IPL_DEPTH_32S, 1 ); IplImage* img3 = cvCreateImage( cvSize(w,w), 8, 3 ); (void)argc; (void)argv; help(); cvZero( img ); for( i=0; i < 6; i++ ) { int dx = (i%2)*250 - 30; int dy = (i/2)*150; CvScalar white = cvRealScalar(255); CvScalar black = cvRealScalar(0); if( i == 0 ) { for( j = 0; j <= 10; j++ ) { double angle = (j+5)*CV_PI/21; cvLine(img, cvPoint(cvRound(dx+100+j*10-80*cos(angle)), cvRound(dy+100-90*sin(angle))), cvPoint(cvRound(dx+100+j*10-30*cos(angle)), cvRound(dy+100-30*sin(angle))), white, 3, 8, 0); } } cvEllipse( img, cvPoint(dx+150, dy+100), cvSize(100,70), 0, 0, 360, white, -1, 8, 0 ); cvEllipse( img, cvPoint(dx+115, dy+70), cvSize(30,20), 0, 0, 360, black, -1, 8, 0 ); cvEllipse( img, cvPoint(dx+185, dy+70), cvSize(30,20), 0, 0, 360, black, -1, 8, 0 ); cvEllipse( img, cvPoint(dx+115, dy+70), cvSize(15,15), 0, 0, 360, white, -1, 8, 0 ); cvEllipse( img, cvPoint(dx+185, dy+70), cvSize(15,15), 0, 0, 360, white, -1, 8, 0 ); cvEllipse( img, cvPoint(dx+115, dy+70), cvSize(5,5), 0, 0, 360, black, -1, 8, 0 ); cvEllipse( img, cvPoint(dx+185, dy+70), cvSize(5,5), 0, 0, 360, black, -1, 8, 0 ); cvEllipse( img, cvPoint(dx+150, dy+100), cvSize(10,5), 0, 0, 360, black, -1, 8, 0 ); cvEllipse( img, cvPoint(dx+150, dy+150), cvSize(40,10), 0, 0, 360, black, -1, 8, 0 ); cvEllipse( img, cvPoint(dx+27, dy+100), cvSize(20,35), 0, 0, 360, white, -1, 8, 0 ); cvEllipse( img, cvPoint(dx+273, dy+100), cvSize(20,35), 0, 0, 360, white, -1, 8, 0 ); } cvNamedWindow( "image", 1 ); cvShowImage( "image", img ); cvConvert( img, img32f ); findCComp( img32f ); cvConvert( img32f, img32s ); cvFindContours( img32s, storage, &contours, sizeof(CvContour), CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0) ); //cvFindContours( img, storage, &contours, sizeof(CvContour), // CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0) ); { const char* attrs[] = {"recursive", "1", 0}; cvSave("contours.xml", contours, 0, 0, cvAttrList(attrs, 0)); contours = (CvSeq*)cvLoad("contours.xml", storage, 0, 0); } // comment this out if you do not want approximation contours = cvApproxPoly( contours, sizeof(CvContour), storage, CV_POLY_APPROX_DP, 3, 1 ); cvNamedWindow( "contours", 1 ); cvCreateTrackbar( "levels+3", "contours", &levels, 7, on_trackbar ); { CvRNG rng = cvRNG(-1); CvSeq* tcontours = contours; cvCvtColor( img, img3, CV_GRAY2BGR ); while( tcontours->h_next ) tcontours = tcontours->h_next; for( ; tcontours != 0; tcontours = tcontours->h_prev ) { CvScalar color; color.val[0] = cvRandInt(&rng) % 256; color.val[1] = cvRandInt(&rng) % 256; color.val[2] = cvRandInt(&rng) % 256; color.val[3] = cvRandInt(&rng) % 256; cvDrawContours(img3, tcontours, color, color, 0, -1, 8, cvPoint(0,0)); if( tcontours->v_next ) { color.val[0] = cvRandInt(&rng) % 256; color.val[1] = cvRandInt(&rng) % 256; color.val[2] = cvRandInt(&rng) % 256; color.val[3] = cvRandInt(&rng) % 256; cvDrawContours(img3, tcontours->v_next, color, color, 1, -1, 8, cvPoint(0,0)); } } } cvShowImage( "colored", img3 ); on_trackbar(0); cvWaitKey(0); cvReleaseMemStorage( &storage ); cvReleaseImage( &img ); cvReleaseImage( &img32f ); cvReleaseImage( &img32s ); cvReleaseImage( &img3 ); return 0; }