Example #1
0
int main(int argc, char *argv[])
{
    Corpus corp("db/corpus");
    int total_terms = 0;

    setvbuf(stdin,  (char *)malloc(1048576*16), _IOFBF, 1048576*16);
    setvbuf(stdout, (char *)malloc(1048576*16), _IOFBF, 1048576*16);

    for(;;)
    {
        static char buf[16*1048576];
        const char *end;
       
        if(doc_id % 1000 == 0) 
            fprintf(stderr, "processed articles: %d, total terms: %d\r", doc_id, total_terms);
        if(fgets(buf, sizeof(buf)-1, stdin) != buf)
            break;

        end = strchr(buf, '\n');
        run_line(buf, end, corp);

        total_terms += term_pos;
        doc_id++;
        term_pos = 0;
    }
    fprintf(stderr, "\n");
    return 0;
}
Example #2
0
int main(){
    Tserial *com;
    char ch;
    com = new Tserial();
    com->connect("COM3", 4800, spNONE);
    CvCapture *capture = 0;
    IplImage  *frame = 0;
    int       key = 0;
    com->sendChar('a');
    int rpx,rpy,ryx,ryy,bx,by,rpx1,rpy1,ryx1,ryy1,bx1,by1,ccx1,ccy1;
    int ccx=91,ccy=45;
    double theta1,theta2;
    /* initialize camera */
    capture = cvCaptureFromCAM(0);
    cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH, 1024 );

    cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT, 720 );

    /* always check */
    if ( !capture ) {
        fprintf( stderr, "Cannot open initialize webcam!\n" );
        return 1;
    }
 
    /* create a window for the video */
    cvNamedWindow( "image", CV_WINDOW_AUTOSIZE );
 
    while( key != 'q' ) {
        /* get a frame */
        img = cvQueryFrame( capture );
      
        /* always check */
        if( !img ) break;
        
        img0=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,3);
        cvCvtColor(img,img0,CV_BGR2HSV);
         cvSetMouseCallback( "image", mouseHandler, img0 );
      // cvThreshold(img0, img0, 85, 255, CV_THRESH_BINARY);
      cvDilate(img0,img0,NULL,1);
     // cvErode(img0,img0,NULL,1);
       
        /* display curent frame */
        cvShowImage( "image", img );
        rpx=corp(img0,1);
        ryx=cory(img0,1);
        bx=corr(img0,1);
        
        rpy=corp(img0,0);
        ryy=cory(img0,0);
        by=corr(img0,0);
        printf("px=%d\tyx=%d\trx=%d\t py=%d\t yy=%d\t ry=%d \n",rpx,ryx,bx,rpy,ryy,by);
        rpx1=rpx-ryx;
        rpy1=rpy-ryy;
        bx1=bx-ryx;
        by1=by-ryy;
        ccx1=ccx-ryx;
        ccy1=ccy-ryy;
        
      //printf("%lf\t %lf\t %lf\t%lf\n", theta1, theta2,theta2-theta1,M_PI+theta2-theta1);
      if(bx!= 0 ){
              com->sendChar('o');
              theta1=atan((double)rpy1/(double)rpx1);
              theta2=atan((double)by1/(double)bx1);
              if(theta1-theta2<0.4 && theta1-theta2>-0.4 && rpx1*bx1>0){
                             com->sendChar('f');
                             }
              else if(theta1-theta2<0.1 && theta1-theta2>-0.1 && rpx1*bx1<0)
                             {
                             com->sendChar('l');
                             }
              else if(rpx1>0 && bx1>0 && theta2-theta1<0)
                             com->sendChar('l');
             
             else if(rpx1>0 && bx1>0 && theta2-theta1>0)
                            com->sendChar('r');
             
             else if(rpx1 < 0 && bx1 < 0 && theta2-theta1 < 0)
                            com->sendChar('l');
             
             else if(rpx1 < 0 && bx1 < 0 && theta2-theta1 > 0)
                            com->sendChar('r');
             
             else if(rpx1>0 && bx1<0 &&M_PI+ theta2-theta1>0 && M_PI+theta2-theta1<M_PI){
                            com->sendChar('R');
             //cvWaitKey(1);
             }
             else if(rpx1>0 && bx1<0 && M_PI+ theta2-theta1>M_PI){
                            com->sendChar('L');
             //cvWaitKey(1);
             }
             else if(rpx1<0 && bx1>0 &&M_PI+ theta1-theta2>0.1 && M_PI+ theta1-theta2 <M_PI){
                            com->sendChar('L');
             //cvWaitKey(1);
             }
             else if(rpx1<0 && bx1>0 && M_PI+ theta1-theta2<M_PI){
                            com->sendChar('R');
             //cvWaitKey(1);
             }
        }
        else if (bx==0&&sqrt(double((ccx-rpx)*(ccx-rpx))+double((ccy-rpy)*(ccy-rpy)))>=35.0){  
             //printf("%lf", sqrt(double((ccx-rpx)*(ccx-rpx))+double((ccy-rpy)*(ccy-rpy))));
             theta1=atan((double)rpy1/(double)rpx1);
             theta2=atan((double)ccy1/(double)ccx1);
             com->sendChar('c');
             if(theta1-theta2<0.4 && theta1-theta2>-0.4 && rpx1*ccx1>0){
                             com->sendChar('f');
             }
             else if(theta1-theta2<0.1 && theta1-theta2>-0.1 && rpx1*ccx1<0)
             {
                             com->sendChar('l');
             }
      else if(rpx1>0 && ccx1>0 && theta2-theta1<0)
             com->sendChar('l');
             
      else if(rpx1>0 && ccx1>0 && theta2-theta1>0)
             com->sendChar('r');
             
      else if(rpx1 < 0 && ccx1 < 0 && theta2-theta1 < 0)
             com->sendChar('l');
             
      else if(rpx1 < 0 && ccx1 < 0 && theta2-theta1 > 0)
             com->sendChar('r');
             
        else if(rpx1>0 && ccx1<0 &&M_PI+ theta2-theta1>0 && M_PI+theta2-theta1<M_PI){
             com->sendChar('R');
             //cvWaitKey(1);
             }
        else if(rpx1>0 && ccx1<0 && M_PI+ theta2-theta1>M_PI){
             com->sendChar('L');
             //cvWaitKey(1);
             }
       else if(rpx1<0 && ccx1>0 &&M_PI+ theta1-theta2>0.1 && M_PI+ theta1-theta2 <M_PI){
             com->sendChar('L');
             //cvWaitKey(1);
             }
        else if(rpx1<0 && ccx1>0 && M_PI+ theta1-theta2<M_PI){
             com->sendChar('R');
             //cvWaitKey(1);
             }
             
        }
                  
        else if(sqrt(double((ccx-rpx)*(ccx-rpx))+double((ccy-rpy)*(ccy-rpy)))<40.0){
        com->sendChar('s');
        com->sendChar('o');
        }
             
        
             
                                                  
        /* exit if user press 'q' */
        key = cvWaitKey(1);
        cvReleaseImage(&img0);
        //com->sendChar('d');
        
            }


    /* free memory */
    cvDestroyWindow( "image" );
    cvReleaseCapture( &capture );
    com->disconnect();
    return 0;
}
Example #3
0
int main(){
    Tserial *com;
    char ch;
    com = new Tserial();
    com->connect("COM3", 4800, spNONE);
    CvCapture *capture = 0;
    IplImage  *frame = 0;
    int       key = 0;
    com->sendChar('a');
    int rpx,rpy,ryx,ryy,bx,by,rpx1,rpy1,ryx1,ryy1,bx1,by1;
    double theta1=0.1,theta2=0.1;
    /* initialize camera */
    capture = cvCaptureFromCAM(0);
    cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH, 1024 );

    cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT, 720 );

    /* always check */
    if ( !capture ) {
        fprintf( stderr, "Cannot open initialize webcam!\n" );
        return 1;
    }
 
    /* create a window for the video */
    cvNamedWindow( "image", CV_WINDOW_AUTOSIZE );
 
    while( key != 'q' ) {
        /* get a frame */
        img = cvQueryFrame( capture );
      
        /* always check */
        if( !img ) break;
        
        img0=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,3);
        cvCvtColor(img,img0,CV_BGR2HSV);
        // cvSetMouseCallback( "image", mouseHandler, img0 );
      // cvThreshold(img0, img0, 85, 255, CV_THRESH_BINARY);
       
        /* display curent frame */
        cvShowImage( "image", img0 );
        rpx=corp(img0,1);
        ryx=cory(img0,1);
        bx=corr(img0,1);
        rpy=corp(img0,0);
        ryy=cory(img0,0);
        by=corr(img0,0);
        rpx1=rpx-ryx;
        rpy1=rpx-ryy;
        bx1=bx-ryx;
        by1=by-ryy;
        theta1=atan((double)rpy1/(double)rpx1);
        theta2=atan((double)by1/(double)bx1);
        if(theta1>0 && theta1-theta2>0 && rpx1>0)
        com->sendChar('r');
        else if(theta1<=0 && M_PI+theta1-theta2>0)
        com->sendChar('l');
        else if(theta1<0 && theta2>=0 && rpx<ryx)
        com->sendChar('r');
        else if(theta1>0 && theta1-theta2<0)
        com->sendChar('l');
        else if(theta1>0 && theta1-theta2>0 && rpx1<0)
        com->sendChar('l');
        else if(theta1-theta2==0.0 && rpx1*bx1>0)
        com->sendChar('f');
        else if(theta1-theta2==0.0 && rpx1*bx1<0){
        com->sendChar('r');
        cvWaitKey(5);
        }
        /* exit if user press 'q' */
        key = cvWaitKey( 1 );
        cvReleaseImage(&img0);
        
            }


    /* free memory */
    cvDestroyWindow( "image" );
    cvReleaseCapture( &capture );
    com->disconnect();
    return 0;
}