Exemplo n.º 1
0
void HarrisBuffer::ProcessFrame(IplImage* frm, IplImage* OFx_precomp, IplImage* OFy_precomp)
{
  int i;
  if (!prevgray) cvCopy(frm,prevgray);
  else cvCopy(gray,prevgray);
  cvCopy(frm,gray);
  cvScale(gray, frame, 1.0/255.0, 0.0);

  //Ross moved this 'till later
  original.Update(frame);

  //spatial filtering
  CVUtil::GaussianSmooth(frame, tmp, sig2, FFT);
  databuffer.Update(tmp);

  //temporal filtering
  int tstamp1 = databuffer.TemporalConvolve(tmp1, TemporalMask1);
  convbuffer.Update(tmp1, tstamp1);

  int tstamp1d = convbuffer.TemporalConvolve(Lt, DerivMask);
  cvScale(Lt, Lt, sqrt(tau2_) , 0);

  convbuffer.GetFrame(tstamp1d,L);
  CVUtil::ImageGradient(L, Lx, Ly); //prb: a possible scale
  cvScale(Lx, Lx, sqrt(sig2)*0.5 , 0);
  cvScale(Ly, Ly, sqrt(sig2)*0.5 , 0);

  //update second-moment matrix
  GaussianSmoothingMul(Lx, Lx, tmp1, 2 * sig2);
  cxxbuffer.Update(tmp1,tstamp1d);
  GaussianSmoothingMul(Lx, Ly, tmp1, 2 * sig2);
  cxybuffer.Update(tmp1,tstamp1d);
  GaussianSmoothingMul(Lx, Lt, tmp1, 2 * sig2);
  cxtbuffer.Update(tmp1,tstamp1d);
  GaussianSmoothingMul(Ly, Ly, tmp1, 2 * sig2);
  cyybuffer.Update(tmp1,tstamp1d);
  GaussianSmoothingMul(Ly, Lt, tmp1, 2 * sig2);
  cytbuffer.Update(tmp1,tstamp1d);
  GaussianSmoothingMul(Lt, Lt, tmp1, 2 * sig2);
  cttbuffer.Update(tmp1, tstamp1d);

  //update Harris buffer
  int tstamp2=0;
  tstamp2=cxxbuffer.TemporalConvolve(cxx, TemporalMask2);
  tstamp2=cxybuffer.TemporalConvolve(cxy, TemporalMask2);
  tstamp2=cxtbuffer.TemporalConvolve(cxt, TemporalMask2);
  tstamp2=cyybuffer.TemporalConvolve(cyy, TemporalMask2);
  tstamp2=cytbuffer.TemporalConvolve(cyt, TemporalMask2);
  tstamp2=cttbuffer.TemporalConvolve(ctt, TemporalMask2);

  // Estimate L&K optical flow from second moment matrix
  //OpticalFlowFromSMM();
  //OpticalFlowFromLK();
  OFx=OFx_precomp;
  OFy=OFy_precomp;

  // compute 3D extension of Harris function
  HarrisFunction(kparam, tmp);
  Hbuffer.Update(tmp,tstamp2);

  //*** detect interest points
  DetectInterestPoints(Border);

  //*** compute point descriptors
  for(i=0;i<(int)ipList.size();i++) { 
    if(!ipList[i].reject)
    {
      DetectedTrackingPoint dtp(ipList[i]);
      //Here I want to add the interest point to the list of interest-points-to-track		
      pointsToTrack.push_back(dtp);
    }
  }

  //here's where I do the tracking
  // go through pointsToTrack 
  // for everything that hasn't finished tracking
  // add it's most recent location to the list that the openCV KLT function will take
  // run the opencv KLT function
  // using the same "for" structure that added the points to the tracking list,
  //  go through those points, and either add the new tracked position to the point
  //  or, if tracking was lost, 
  //   remove the point from pointsToTrack, and add it to pointsFinishedTracking

  //first, allocate the prev_features structure

  CalculateVelocityHistories();

  iFrame++;
  return;
}
Exemplo n.º 2
0
void HarrisBuffer::ProcessFrame(IplImage* frm)
{
	gray=frm;
	//todo:scale depending on input type and IMGTYPE 
	//cvNormalize(gray,frame,1,0,CV_MINMAX);
	/*double m, M;
	cvMinMaxLoc(gray, &m, &M, NULL, NULL, NULL);*/
	cvScale(gray, frame, 1.0/255.0, 0.0);// 
	/*double m, M;
	cvMinMaxLoc(frame, &m, &M, NULL, NULL, NULL); 
	std::cout<<m<<"\t"<<M<<endl;*/

	
	original.Update(frame);

	//spatial filtering
	CVUtil::GaussianSmooth(frame,tmp,sig2,FFT);
	databuffer.Update(tmp);

	//temporal filtering
	int tstamp1=databuffer.TemporalConvolve(tmp1, TemporalMask1);
	convbuffer.Update(tmp1,tstamp1);

	int tstamp1d=convbuffer.TemporalConvolve(Lt,DerivMask);
	cvScale(Lt,Lt, sqrt(tau2) , 0);

	convbuffer.GetFrame(tstamp1d,L);
	CVUtil::ImageGradient(L,Lx,Ly);//prb: a possible scale
	cvScale(Lx,Lx, sqrt(sig2)*0.5 , 0);
	cvScale(Ly,Ly, sqrt(sig2)*0.5 , 0);

	//update second-moment matrix
	GaussianSmoothingMul(Lx,Lx, tmp1,2*sig2);
	cxxbuffer.Update(tmp1,tstamp1d);
	GaussianSmoothingMul(Lx,Ly, tmp1,2*sig2);
	cxybuffer.Update(tmp1,tstamp1d);
	GaussianSmoothingMul(Lx,Lt, tmp1,2*sig2);
	cxtbuffer.Update(tmp1,tstamp1d);
	GaussianSmoothingMul(Ly,Ly, tmp1,2*sig2);
	cyybuffer.Update(tmp1,tstamp1d);
	GaussianSmoothingMul(Ly,Lt, tmp1,2*sig2);
	cytbuffer.Update(tmp1,tstamp1d);
	GaussianSmoothingMul(Lt,Lt, tmp1,2*sig2);
	cttbuffer.Update(tmp1,tstamp1d);

	//update Harris buffer

	int tstamp2=0;
	tstamp2=cxxbuffer.TemporalConvolve(cxx, TemporalMask2);
	tstamp2=cxybuffer.TemporalConvolve(cxy, TemporalMask2);
	tstamp2=cxtbuffer.TemporalConvolve(cxt, TemporalMask2);
	tstamp2=cyybuffer.TemporalConvolve(cyy, TemporalMask2);
	tstamp2=cytbuffer.TemporalConvolve(cyt, TemporalMask2);
	tstamp2=cttbuffer.TemporalConvolve(ctt, TemporalMask2);

	HarrisFunction(kparam, tmp);
	Hbuffer.Update(tmp,tstamp2);
	
	//LogMinMax(Hbuffer.Buffer,logfile);
	//databuffer.FrameIndices.print(std::cout);
	//databuffer.FrameIndices.print(logfile);
	//convbuffer.FrameIndices.print(logfile);
	//Hbuffer.FrameIndices.print(logfile);
	//std::cout<<iFrame<<std::endl;
	DetectInterestPoints(Border);

	iFrame++;
	return;
}