In OpenCV haartraining, .vec files are given as input as the positive training examples. We can view the images inside the vec file using opencv-createsamples, but I wanted to extract images out of it. This is what is did.
I edited the file <opencvfolder>/apps/haartraining/src/cvsamples.cpp
first, include the following headers
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <string>
function edited is cvShowVecSamples, in the for-loop for showing the images, edit as following
std::ostringstream stm; //added
icvGetHaarTraininDataFromVecCallback( sample, &file );
stm<<”/temp/vecextracted/”; //added folder in which to extract images
stm << i; //added filename which will be given to save image, integer to string conversion
stm << “.pgm”; //added
std::cout<<”\n”; //added
std::cout<<stm.str(); //added
const char *filename = stm.str().c_str(); //added
std::cout<<filename; //added
cvSaveImage(filename, sample); //added
if( scale != 1.0 ) cvResize( sample, scaled_sample, CV_INTER_LINEAR);
cvShowImage(“Sample”, scaled_sample );
cvWaitKey(50);
//added == these are the lines that i have added, other lines are the default of OpenCV
Now, you have to rebuild the files. So, in the command line type
make all
Now, when you execute opencv-createsample -vec vecfile.vec, the images are extracted too.
One Trackback/Pingback
[...] Rockanjan’s Weblog Just another WordPress.com weblog « OpenCV: extract images from .vec file [...]