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 );

 }

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" >

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:");
}

Monday, February 7, 2011

Events in UserControls

CMD Windows NET USE

net use y: /delete

net use Y: \\DRIVE\FOLDER qazwsx /USER:DOMAIN\user