示例#1
0
文件: Statistic.cpp 项目: Dzzirt/OOP
void CStatistic::PrintStats(std::string const& physicalQuantity)const
{
	std::cout << "Max " << physicalQuantity.c_str() << ":" << GetMax() << std::endl;
	std::cout << "Min " << physicalQuantity.c_str() << ":" << GetMin() << std::endl;
	std::cout << "Average " << physicalQuantity.c_str() << ":" << GetAverage() << std::endl;
	std::cout << "----------------" << std::endl;
}
示例#2
0
文件: main.cpp 项目: trankimhieu/KTLT
void main()
{
	int a[100];
	int n;
	RandomArray(a,n);
	PrintArray(a,n);
	GetAverage(a,n);
	getch();
}
//input box ::符合in5out4規則保留下來的點
static void   MaskEvaluate(int x,int y,int d,unsigned char* src_buf,int buf_width, int buf_height,double* MeanIn,double* MeanOut,double* VarIn,double* VarOut)
{
		int i,j,InNum=0, OutNum=0, AveIn[NumOfInter], AveOut[NumOfOuter];
		//Inter 5
		for(i = y-d;i<=y+d;i=i+d)
		{
		 if(i>=0&&i<buf_height&&x>=0&&x<buf_width)
		 {
		  AveIn[InNum]=  (int)src_buf[x*2+i*buf_width*2];
		  InNum++;
		 }
		}
		if((x-d)>=0&&(x-d)<buf_width)
		{
			AveIn[InNum]=  (int)src_buf[(x-d)*2+y*buf_width*2];//左內
			InNum++;
		}
		if((x+d)>=0&&(x+d)<buf_width)
		{
			AveIn[InNum]=  (int)src_buf[(x+d)*2+y*buf_width*2];//右內
			InNum++;
		}

		//Outer 4
		for( i = x-d;i<=x+d;i+=d*2)
		{
		 for(j = y-d;j<=y+d;j+=d*2)
		 {
		  if(i>=0&&i<buf_width&&j>=0&&j<buf_height)
		  { 
		   AveOut[OutNum]=  (int)src_buf[i*2+j*buf_width*2];
		   OutNum++;
		  }
		 }
		}
		//-------算平均值&變異數--------
		if(InNum!=FALSE&&OutNum!=FALSE)
		{
			*MeanIn  = GetAverage(AveIn,InNum);
			*MeanOut = GetAverage(AveOut,OutNum);
			*VarIn   = GetVariance(AveIn,InNum);
			*VarOut  = GetVariance(AveOut,OutNum);
		}
}
示例#4
0
void OpticalFlow::PrepareTracking(IplImage* rgbImage,
                                  IplImage* currGrayImage, int curr_indx,
                                  ProbDistrProvider* pProbProv,
                                  const CuScanMatch& match,
                                  ConstMaskIt mask,
                                  int target_num_features,
                                  int winsize_width,
                                  int winsize_height,
                                  double min_distance,
                                  double max_feature_error)
{
  m_pProbDistrProvider = pProbProv;
  m_target_num_features = target_num_features;
  m_num_features_tracked = 0;
  m_prev_buf_meaningful = false;
  m_winsize_width = winsize_width;
  m_winsize_height = winsize_height;
  m_min_distance = min_distance;
  m_max_feature_error = max_feature_error;
  
  // first find a big set of features that sits on corners
  int num_corners = m_target_num_features*3;
  CPointVector corners;
  corners.resize(num_corners);
  CRect bbox(match);
  FindGoodFeatures(currGrayImage, bbox, corners);

  // then play with the color probability distribution to pick
  // the ones that are on skin color, or if those aren't enough,
  // pick some additional ones on skin colored pixels
  m_features[0].resize(m_target_num_features);
  m_features[1].resize(m_target_num_features);
  m_feature_status.resize(m_target_num_features);
  m_errors.resize(m_target_num_features);
  PickSkinColoredFeatures(rgbImage, corners, m_features[curr_indx], match, mask);

  // fine-tune feature locations
  cvFindCornerSubPix(currGrayImage,
                     (CvPoint2D32f*) &m_features[curr_indx][0],
                     m_target_num_features, 
                     cvSize(5,5), cvSize(-1,-1),
                     cvTermCriteria( CV_TERMCRIT_ITER, 10, 0.1f ));

  // set status right for these features
  for (int i=0; i<m_target_num_features; i++) {
    m_feature_status[i] = 1;
  }
  GetAverage(m_features[curr_indx], m_mean_feature_pos);

  m_condens_is_tracking = false;
  m_condens_init_rect = CRect(match);

  m_prepared = true;
}
示例#5
0
Stopwatch::~Stopwatch()
{
	// Write log contents out to file.
	GetAverage();
	std::ofstream fileOut;
	fileOut.open(filename, std::ios::app);
	
	for (auto iter = log.begin(); iter != log.end(); iter++)
	{
		fileOut << (*iter) << std::endl;
	}


	fileOut.close();
}
示例#6
0
文件: stats.c 项目: Gaikokujin/WinNT4
BOOL 
Get_Stats(
    double      *array,               
    long        num_samples,          
    const       filter_option,        
    long        var_limit,             
    PTEST_STATS stats)                 

    {  

        double  Averagetmp;
        double  StdDevtmp;
        long    NumSamplestmp;

        if(!GetAverage(array, num_samples, &Averagetmp))
            return FALSE; 

        SortUp(array, num_samples);

        if(!GetStdDev(array, Averagetmp, num_samples, &StdDevtmp))
            return FALSE;

        stats->Minimum_Result   = array[0];
        stats->Maximum_Result   = array[num_samples - 1];

        if(filter_option == NO_FILTER)
        {
            stats->Average = Averagetmp;
            stats->StdDev  = StdDevtmp;
            stats->NumSamplesValid  = num_samples;
            return TRUE;
        }


        NumSamplestmp   = num_samples;
        if(!FilterResults(array,&Averagetmp,&StdDevtmp,&NumSamplestmp,var_limit,filter_option))
            return FALSE;

        stats->Average              = Averagetmp;
        stats->StdDev               = StdDevtmp;
        stats->NumSamplesValid      = NumSamplestmp;
        return TRUE;

    }
示例#7
0
int OpticalFlow::Track(IplImage* rgbImage,
                       IplImage* prevImage, IplImage* currImage,
                       int prev_indx, int curr_indx, 
                       int last_width, int last_height,
                       bool flock, bool use_prob_distr)
{
  ASSERT(m_prepared);

  m_prev_buf_meaningful = true;

  LKPyramids(prevImage, currImage, prev_indx, curr_indx);

#if 0
  if (todo) {
    /* track a number of KLT features with an n-stage pyramid
    * and globally optimize their positions with Condensation
    */
    const int condens_num_samples = 128;
    if (!m_condens_is_tracking) {
      InitCondensation(condens_num_samples);
      ASSERT(m_pConDens->SamplesNum==condens_num_samples);
      m_condens_is_tracking = true;
    }

    UpdateCondensation(rgbImage, prev_indx, curr_indx);
    ASSERT(m_pConDens->SamplesNum==condens_num_samples);
  }
#endif

  if (flock) {
    ConcentrateFeatures(rgbImage, m_features[curr_indx], m_feature_status, 
                        last_width, last_height, use_prob_distr);

  } else {
    AddNewFeatures(rgbImage, m_features[curr_indx], m_feature_status, 
                   last_width, last_height, use_prob_distr);
  }

  GetAverage(m_features[curr_indx], m_mean_feature_pos);
  m_saved_prev_indx = prev_indx;
  m_saved_curr_indx = curr_indx;

  return m_num_features_tracked;
} // Track
示例#8
0
int main()
{
	//assigning variables
	
	int numbers[5];
	int size = sizeof(numbers) / sizeof(int);
	int total = 0;
	int i = 0;
	float averageNumber;
	float sum;
	char command;
	bool loopCon = true;
	
	//welcome message
	printf("WELCOME TO FUN WITH FIVE NUMBERS!\n");


	//collect numbers, put in array
	for (i = 0; i < size; i++)
	{
		printf("Enter number %i: ", i + 1);
		scanf(" %i", &numbers[i]);
	}

	//repeat numbers in the array

	PrintNumbers(numbers, size);

	//do while x is not typed
	do {

		loopCon = true;

		//print options to user
		printf("Select one of the following commands (type x to finish):\n");
		printf("1 - Show the average of the numbers\n");
		printf("2 - Sort the numbers from smallest to largest\n");
		printf("3 - Show the sum of the numbers\n");
		printf("4 - Show the sum in 32-bit binary form\n");
		printf("5 - Change the five numbers\n");
		printf("x - End Program\n");

		printf("Your command: ");
		scanf(" %c", &command);

		
		switch (command)
		{
		case '1'://average number
			averageNumber = GetAverage(numbers, size);
			printf("The average of your numbers is %.1f \n\n", averageNumber);
			break;
			
		case '2'://acending order
			SortedNumbers(numbers, size);
			PrintNumbers(numbers, size);
			break;

		case '3'://sum of numbers
			sum = GetSum(numbers, size);
			printf("The sum of your numbers is %.1f \n\n", sum);
			break;
		
		case '4'://sum in binary
			printf("The sum of yours numbers in binary form is: ");
			PrintSumAsBinary(numbers, size);
			printf("\n\n");
			break;
		
		case '5'://new numbers
			for (i = 0; i < size; i++)
			{
				printf("Enter number %i: ", i + 1);
				scanf(" %i", &numbers[i]);
			}
			
			//repeat numbers in the array
			PrintNumbers(numbers, size);
			break;

		case 'x'://exit
			loopCon = false;
			printf("Thanks for playing!\n");
			break;

		default:
			if(loopCon != false)
			{
				printf("\nInvalid command. Try again.\n");
			}
			
		}
		
		

	} while (command != 'x');
	
	
	
	
	
	
	
	
	return 0;
}
示例#9
0
void OpticalFlow::UpdateCondensation(IplImage* /*rgbImage*/,
                                     int prev_indx, int curr_indx)
{
  //VERBOSE5(3, "m_condens_state x %f, y %f, vx %f, vy %f, a %f", 
  //  m_condens_state.x, m_condens_state.y, m_condens_state.vx, m_condens_state.vy, m_condens_state.angle);

  // for each condensation sample, predict the feature locations,
  // compare to the observed KLT tracking, and check the probmask
  // at each predicted location. The combination of these yields the
  // confidence in this sample's estimate.
  int num_ft = (int) m_features[prev_indx].size();
  CPointVector predicted;
  predicted.resize(num_ft);
  CDoubleVector probs_locations;
  CDoubleVector probs_colors;
  probs_locations.reserve(m_pConDens->SamplesNum);
  probs_colors.reserve(m_pConDens->SamplesNum);
  double sum_probs_locations = 0.0;
  double sum_probs_colors = 0.0;
  CDoubleVector old_lens;
  CDoubleVector old_d_angles;
  // prepare data structures so that prediction based on centroid
  // is fast
  PreparePredictFeatureLocations(m_condens_state, m_features[prev_indx], old_lens, old_d_angles);
  CvPoint2D32f avg_obs, avg_prev;
  GetAverage(m_features[curr_indx], avg_prev);
//  GetAverage(m_features[prev_indx], avg_prev);
  GetAverage(m_features[curr_indx]/*_observation*/, avg_obs);
  double dvx = avg_obs.x - avg_prev.x;
  double dvy = avg_obs.y - avg_prev.y;

  // for each sample
  for (int scnt=0; scnt<m_pConDens->SamplesNum; scnt++) {
    // hack - todo
    if (scnt==m_pConDens->SamplesNum-1) {
      m_pConDens->flSamples[scnt][0] = avg_obs.x;
      m_pConDens->flSamples[scnt][2] = avg_obs.y;
      m_pConDens->flSamples[scnt][1] = (float) dvx;
      m_pConDens->flSamples[scnt][3] = (float) dvy;
    }

    // the Condensation sample's guess:
    CondensState sample_state;
    sample_state.x = m_pConDens->flSamples[scnt][0];
    sample_state.y = m_pConDens->flSamples[scnt][2];
    sample_state.vx = m_pConDens->flSamples[scnt][1];
    sample_state.vy = m_pConDens->flSamples[scnt][3];
    sample_state.angle = 0;//m_pConDens->flSamples[scnt][4];
    ASSERT(!isnan(sample_state.x) && !isnan(sample_state.y) && !isnan(sample_state.angle));
    
    double fac = (m_condens_init_rect.right-m_condens_init_rect.left)/3.0;
    double dx = avg_obs.x - sample_state.x;
    double dy = avg_obs.y - sample_state.y;
    double probloc = dx*dx+dy*dy;
    probloc = fac/(fac+probloc);
    probs_locations.push_back(probloc);
    sum_probs_locations += probloc;

#if 0
    PredictFeatureLocations(old_lens, old_d_angles, sample_state, predicted);

    // probability of predicted feature locations given the KLT observation
    int discard_num_distances = (int)(0.15*(double)num_ft);
    double probloc = EstimateProbability(predicted, m_features[curr_indx]/*_observation*/, discard_num_distances);
    probs_locations.push_back(probloc);
    sum_probs_locations += probloc;

    // probability of predicted feature locations given the outside probability map (color)
    double probcol = EstimateProbability(predicted, rgbImage);
    probs_colors.push_back(probcol);
    sum_probs_colors += probcol;
#endif

  } // end for each sample

//  ASSERT(!isnan(sum_probs_locations) && sum_probs_locations>0);

  //
  // normalize the individual probabilities and set sample confidence
  //
  int best_sample_indx = -1;
  double best_confidence = 0;
  for (int scnt=0; scnt<m_pConDens->SamplesNum; scnt++) {
    double norm_prob_locations = probs_locations[scnt]/sum_probs_locations;
//    double norm_prob_colors    = probs_colors[scnt]/sum_probs_colors;
    double confidence;
    if (sum_probs_colors>0) {
 //     confidence = norm_prob_locations*norm_prob_colors;
      confidence = norm_prob_locations;
    } else {
      confidence = norm_prob_locations;
    }
    m_pConDens->flConfidence[scnt] = (float) confidence;
    m_sample_confidences[scnt] = confidence;
    if (confidence>best_confidence) {
      best_confidence = confidence;
      best_sample_indx = scnt;
    }
  }
//  for (int scnt=0; scnt<m_pConDens->SamplesNum; scnt++) {
//    VERBOSE2(3, "%d: %f ", scnt, m_sample_confidences[scnt]);
//  }
  ASSERT(best_sample_indx!=-1);

  ASSERT(best_sample_indx==m_pConDens->SamplesNum-1);
 
  CondensState best_sample_state;
  best_sample_state.x = m_pConDens->flSamples[best_sample_indx][0];
  best_sample_state.y = m_pConDens->flSamples[best_sample_indx][2];
  best_sample_state.vx = m_pConDens->flSamples[best_sample_indx][1];
  best_sample_state.vy = m_pConDens->flSamples[best_sample_indx][3];
  best_sample_state.angle = m_pConDens->flSamples[best_sample_indx][4];
  //VERBOSE3(3, "sample_state %f, %f, %f", 
  // sample_state.x, sample_state.y, sample_state.angle);
  //    VERBOSE4(3, "sample_state %f, %f, %f, %f"), 
  //      sample_state.x, sample_state.y, sample_state.vx, sample_state.vy);
  ASSERT(!isnan(best_sample_state.x) && !isnan(best_sample_state.y) && !isnan(best_sample_state.angle));

  // probability of predicted feature locations given the KLT observation
  m_tmp_predicted.resize(m_features[0].size());
  PredictFeatureLocations(old_lens, old_d_angles, best_sample_state, m_tmp_predicted);

  //
  // do one condensation step, then get the state prediction from Condensation;
  //
  cvConDensUpdateByTime(m_pConDens);

#if 0
  if (false) { // todo
    m_condens_state.x = max(0, min(rgbImage->width-1, m_pConDens->State[0]));
    m_condens_state.y = max(0, min(rgbImage->height-1, m_pConDens->State[2]));
    m_condens_state.vx = m_pConDens->State[1];
    m_condens_state.vy = m_pConDens->State[3];
    m_condens_state.angle = m_pConDens->State[4];
  } else 
#endif
  {
    m_condens_state.x = best_sample_state.x;
    m_condens_state.y = best_sample_state.y;
    m_condens_state.vx = best_sample_state.vx;
    m_condens_state.vy = best_sample_state.vy ;
    m_condens_state.angle = best_sample_state.angle;
  }
  ASSERT(!isnan(m_condens_state.x) && !isnan(m_condens_state.y) && !isnan(m_condens_state.angle));
  ASSERT(!isnan(m_condens_state.vx) && !isnan(m_condens_state.vy));

  // now move the current features to where Condensation thinks they should be;
  // the observation is no longer needed
#if 0
  if (false) { // todo
    PredictFeatureLocations(old_lens, old_d_angles, m_condens_state, m_tmp_predicted);
    FollowObservationForSmallDiffs(m_tmp_predicted, m_features[curr_indx]/*observation*/, 
                                  m_features[curr_indx]/*output*/, 2.0);
  } else 
#endif
  {
    PredictFeatureLocations(old_lens, old_d_angles, m_condens_state, m_features[curr_indx]);
  }

  {
    // initialize bounds for state
    float lower_bound[OF_CONDENS_DIMS];
    float upper_bound[OF_CONDENS_DIMS];
    // velocity bounds highly depend on the frame rate that we will achieve,
    // increase the factor for lower frame rates;
    // it states how much the center can move in either direction in a single
    // frame, measured in terms of the width or height of the initial match size
    double velocity_factor = .25; 
    CvPoint2D32f avg;
    GetAverage(m_features[curr_indx]/*_observation*/, avg);
    double cx = avg.x;
    double cy = avg.y;
    double width = (m_condens_init_rect.right-m_condens_init_rect.left)*velocity_factor;
    double height = (m_condens_init_rect.bottom-m_condens_init_rect.top)*velocity_factor;
    lower_bound[0] = (float) (cx-width);
    upper_bound[0] = (float) (cx+width);
    lower_bound[1] = (float) (-width);
    upper_bound[1] = (float) (+width);
    lower_bound[2] = (float) (cy-height);
    upper_bound[2] = (float) (cy+height);
    lower_bound[3] = (float) (-height);
    upper_bound[3] = (float) (+height);
    lower_bound[4] = (float) (-10.0*velocity_factor*M_PI/180.0);
    upper_bound[4] = (float) (+10.0*velocity_factor*M_PI/180.0);
    CvMat lb = cvMat(OF_CONDENS_DIMS, 1, CV_MAT3x1_32F, lower_bound);
    CvMat ub = cvMat(OF_CONDENS_DIMS, 1, CV_MAT3x1_32F, upper_bound);
    cvConDensInitSampleSet(m_pConDens, &lb, &ub);
  }

}