Example #1
0
File: event.c Project: ocgis/ofbis
/*
** Description
** Check for keyboard or mouse event with possible timeout
** Timeout value in milliseconds, -1 means forever
**
** 1998-08-06 CG
** 1999-05-20 Tomas
*/
void
FBcheckevent (FB *f, FBEVENT *ev, int timeout) {
  int interrupted;
  struct pollfd in[2];
  int nfds=1, ret;

  in[0].fd = f->tty;
  in[0].events = POLLMASK;

  if ((f->sbuf != f->sbak) && (msefd != -1)) {
    in[1].fd = msefd;
    in[1].events = POLLMASK;
    tcflush( msefd, TCIFLUSH );
    nfds = 2;
  }

  do {
    interrupted = FALSE;

    ret = poll(in, nfds, timeout);
    if(ret == -1) {
      if(errno == EINTR) {
	interrupted = TRUE;
	
	if (msefd != -1) {
	  if (f->sbuf == f->sbak) {
	    nfds = 1;
	  } else {
	    in[1].fd = msefd;
	    in[1].events = POLLMASK;
	    tcflush( msefd, TCIFLUSH );
	    nfds = 2;
	  }
	}
      } else {
	/*
	fprintf(stderr,"ofbis: fbevent.c: tty fd=%d\n", in[0].fd);
	fprintf(stderr,"ofbis: fbevent.c: tty revents=0x%x\n",in[0].revents);
	fprintf(stderr,"ofbis: fbevent.c: mouse fd=%d\n", in[1].fd);
	fprintf(stderr,"ofbis: fbevent.c: mouse revents=0x%x\n",in[1].revents);
	*/
	FBerror( FATAL | SYSERR, "FBcheckevent: poll() returned" );
      }
    }
  } while(interrupted);

  if(ret == 0) { /* if poll() timed out */
    ev->type = FBNoEvent;
  } else if(in[0].revents & POLLIN) {
    ev->type = FBKeyEvent;
    FBprocesskey (f, &ev->key);
  } else if(in[1].revents & POLLIN) {
    ev->type = FBMouseEvent;
    FBprocessmouse (&ev->mouse);		
    /*		printf("buttons: %d x: %d y: %d\n",ev->mouse.buttons, ev->mouse.x, ev->mouse.y ); */
  }
}
void TrackerMedianFlowImpl::check_FB(const Mat& oldImage,const Mat& newImage,
        const std::vector<Point2f>& oldPoints,const std::vector<Point2f>& newPoints,std::vector<bool>& status){

    if(status.size()==0){
        status=std::vector<bool>(oldPoints.size(),true);
    }

    std::vector<uchar> LKstatus(oldPoints.size());
    std::vector<float> errors(oldPoints.size());
    std::vector<double> FBerror(oldPoints.size());
    std::vector<Point2f> pointsToTrackReprojection;
    calcOpticalFlowPyrLK(newImage, oldImage,newPoints,pointsToTrackReprojection,LKstatus,errors,Size(3,3),5,termcrit,0);

    for(int i=0;i<(int)oldPoints.size();i++){
        FBerror[i]=l2distance(oldPoints[i],pointsToTrackReprojection[i]);
    }
    double FBerrorMedian=getMedian(FBerror);
    dprintf(("point median=%f\n",FBerrorMedian));
    dprintf(("FBerrorMedian=%f\n",FBerrorMedian));
    for(int i=0;i<(int)oldPoints.size();i++){
        status[i]=(FBerror[i]<FBerrorMedian);
    }
}