The handler must extend this interface in order to use context.Session:
System.Web.SessionState.IReadOnlySessionState
Tuesday, March 22, 2011
Monday, February 21, 2011
kmeans2 opencv
void main( int argc, char** argv )
{
#define MAX_CLUSTERS 5
//read from file
vector< vector < float > > descriptor;
vector classes;
ifstream f;
f.open("c:\\bayes2.txt");
while(f)
{
string str = "";
f>>str;
vector desc;
size_t found = str.find(",");
while(found<100 && found>0)
{
string t = str.substr(0,found);
desc.push_back(strtod(t.c_str(), NULL));
str = str.substr(found+1);
found = str.find(",");
}
if(desc.size()>0)
{
descriptor.push_back(desc);
classes.push_back(strtod(str.c_str(), NULL));
}
}
f.close();
int k, cluster_count = MAX_CLUSTERS;
int i, sample_count = descriptor.size(),num_features = descriptor[0].size();
CvMat* points = cvCreateMat( sample_count, num_features, CV_32FC2 );
CvMat* clusters = cvCreateMat( sample_count, 1, CV_32SC1 );
for(int i=0;i
{
for(int j=0;j
CV_MAT_ELEM(*points,float,i,j)=descriptor[i][j];
}
cvKMeans2( points, cluster_count, clusters,
cvTermCriteria( CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 200, 1.0 ));
for (int i=0; i
cout << "i*: " << i << " " << (clusters->data.i[i]) << " "<< endl;
}
cvReleaseMat( &points );
cvReleaseMat( &clusters );
}
{
#define MAX_CLUSTERS 5
//read from file
vector< vector < float > > descriptor;
vector
ifstream f;
f.open("c:\\bayes2.txt");
while(f)
{
string str = "";
f>>str;
vector
size_t found = str.find(",");
while(found<100 && found>0)
{
string t = str.substr(0,found);
desc.push_back(strtod(t.c_str(), NULL));
str = str.substr(found+1);
found = str.find(",");
}
if(desc.size()>0)
{
descriptor.push_back(desc);
classes.push_back(strtod(str.c_str(), NULL));
}
}
f.close();
int k, cluster_count = MAX_CLUSTERS;
int i, sample_count = descriptor.size(),num_features = descriptor[0].size();
CvMat* points = cvCreateMat( sample_count, num_features, CV_32FC2 );
CvMat* clusters = cvCreateMat( sample_count, 1, CV_32SC1 );
for(int i=0;i
{
for(int j=0;j
CV_MAT_ELEM(*points,float,i,j)=descriptor[i][j];
}
cvKMeans2( points, cluster_count, clusters,
cvTermCriteria( CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 200, 1.0 ));
for (int i=0; i
cout << "i*: " << i << " " << (clusters->data.i[i]) << " "<< endl;
}
cvReleaseMat( &points );
cvReleaseMat( &clusters );
}
Thursday, February 17, 2011
View AVI in browser (IE)
http://www.beansoftware.com/ASP.NET-Tutorials/Media-Player.aspx
IE
< OBJECT width="300px" height="250px" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" VIEWASTEXT >
< PARAM name="autoStart" value="True">
< PARAM name="URL" value="movie.avi">
< PARAM name="enabled" value="True">
< PARAM name="balance" value="0">
< PARAM name="currentPosition" value="0">
< PARAM name="enableContextMenu" value="True">
< PARAM name="fullScreen" value="False">
< PARAM name="mute" value="False">
< PARAM name="playCount" value="1">
< PARAM name="rate" value="1">
< PARAM name="stretchToFit" value="False">
< PARAM name="uiMode" value="full">
< img dynsrc="movie.avi" >
IE
< OBJECT width="300px" height="250px" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" VIEWASTEXT >
< PARAM name="autoStart" value="True">
< PARAM name="URL" value="movie.avi">
< PARAM name="enabled" value="True">
< PARAM name="balance" value="0">
< PARAM name="currentPosition" value="0">
< PARAM name="enableContextMenu" value="True">
< PARAM name="fullScreen" value="False">
< PARAM name="mute" value="False">
< PARAM name="playCount" value="1">
< PARAM name="rate" value="1">
< PARAM name="stretchToFit" value="False">
< PARAM name="uiMode" value="full">
< img dynsrc="movie.avi" >
Read Movie and frames using Open-CV
int main( int argc, char** argv )
{
CvCapture* capture = 0;
IplImage *frame, *frame_copy = 0;
static CvMemStorage* storage = cvCreateMemStorage(0);
capture = cvCaptureFromAVI( "G:\FlickAnimation.avi" );
cvNamedWindow( "Picture:", 1 );
int index = 0;
if( capture )
{
for(;;)
{
if( !cvGrabFrame( capture ))
break;
frame = cvRetrieveFrame( capture );
if( !frame )
break;
else
{
index++;
//save image
std::string s;
std::stringstream out;
out << index;
s = out.str();
string location = "G:\\movie\\"+s+".jpg";
cvSaveImage(location.c_str(),frame);
}
if( !frame_copy )
frame_copy = cvCreateImage(cvSize(frame->width,frame->height), IPL_DEPTH_8U, frame->nChannels );
if( frame->origin == IPL_ORIGIN_TL )
cvCopy( frame, frame_copy, 0 );
else
cvFlip( frame, frame_copy, 0 );
cvShowImage("Picture:",frame_copy);
// Varying this will vary the speed of the avi file
if( cvWaitKey( 20 ) >= 0 )
break;
}
cvReleaseImage( &frame_copy );
cvReleaseCapture( &capture );
}
cvClearMemStorage( storage );
cvDestroyWindow("Picture:");
}
{
CvCapture* capture = 0;
IplImage *frame, *frame_copy = 0;
static CvMemStorage* storage = cvCreateMemStorage(0);
capture = cvCaptureFromAVI( "G:\FlickAnimation.avi" );
cvNamedWindow( "Picture:", 1 );
int index = 0;
if( capture )
{
for(;;)
{
if( !cvGrabFrame( capture ))
break;
frame = cvRetrieveFrame( capture );
if( !frame )
break;
else
{
index++;
//save image
std::string s;
std::stringstream out;
out << index;
s = out.str();
string location = "G:\\movie\\"+s+".jpg";
cvSaveImage(location.c_str(),frame);
}
if( !frame_copy )
frame_copy = cvCreateImage(cvSize(frame->width,frame->height), IPL_DEPTH_8U, frame->nChannels );
if( frame->origin == IPL_ORIGIN_TL )
cvCopy( frame, frame_copy, 0 );
else
cvFlip( frame, frame_copy, 0 );
cvShowImage("Picture:",frame_copy);
// Varying this will vary the speed of the avi file
if( cvWaitKey( 20 ) >= 0 )
break;
}
cvReleaseImage( &frame_copy );
cvReleaseCapture( &capture );
}
cvClearMemStorage( storage );
cvDestroyWindow("Picture:");
}
Monday, February 7, 2011
Monday, January 24, 2011
SVM in OpenCV
0.1,0.12,0.43,0.11,0.13,0
0.1,0.2,0.4,0.1,0.3,0
0.12,0.22,0.41,0.12,0.32,0
0.31,0.23,0.44,0.21,0.23,0
0.13,0.23,0.43,0.13,0.23,0
0.14,0.24,0.44,0.14,0.34,0
0.14,0.42,0.44,0.14,0.34,0
0.51,0.52,0.54,0.51,0.53,0
0.51,0.52,0.54,0.51,0.53,1
0.52,0.58,0.57,0.54,0.55,1
0.53,0.54,0.55,0.56,0.54,1
0.53,0.57,0.59,0.59,0.59,1
0.69,0.62,0.69,0.69,0.53,2
0.61,0.62,0.54,0.59,0.53,2
0.71,0.72,0.74,0.51,0.53,2
0.81,0.82,0.84,0.81,0.83,2
0.85,0.82,0.85,0.81,0.83,2
0.85,0.92,0.85,0.81,0.93,2
0.95,0.82,0.85,0.91,0.83,2
- last columns represent classes and first columns represent features
vector
vector
ifstream f;
f.open("c:\\bayes.txt");
while(f)
{
string str = "";
f>>str;
vector
size_t found = str.find(",");
while(found<100 && found>0)
{
string t = str.substr(0,found);
desc.push_back(strtod(t.c_str(), NULL));
str = str.substr(found+1);
found = str.find(",");
}
if(desc.size()>0)
{
descriptor.push_back(desc);
classes.push_back(strtod(str.c_str(), NULL));
}
}
f.close();
vector
v.push_back(0.9481);
v.push_back(0.9432);
v.push_back(0.434);
v.push_back(0.0531);
v.push_back(0.533);
int num_samples = descriptor.size();
int num_features = descriptor[0].size();
CvMat* data = cvCreateMat( num_samples, num_features, CV_32F );
CvMat* responses = cvCreateMat( descriptor.size(), 1, CV_32F );
for(int i=0;i
{
for(int j=0;j
CV_MAT_ELEM(*data,float,i,j)=descriptor[i][j];
CV_MAT_ELEM(*responses,float,i,0)=classes[i];
}
// initialize parameters
CvTermCriteria crit;
crit.epsilon = CV_TERMCRIT_EPS;
crit.max_iter = 1000;
crit.type = 1;
CvSVMParams params;
params.svm_type = CvSVM::C_SVC;
params.kernel_type = CvSVM::RBF;
params.gamma = 0.1;
params.C = 3;
params.nu = 0.1;
params.term_crit = crit;
CvMat* sample = cvCreateMat( 1,num_features, CV_32F );
for(int j=0;j
CV_MAT_ELEM(*sample,float,0,j)=v[j];
CvSVM SVM;
SVM.train(data,responses,0,0,params);
float r = SVM.predict( sample );
SVM.clear();
cvReleaseMat(&sample);
cvReleaseMat(&data);
cvReleaseMat(&responses);
Subscribe to:
Posts (Atom)