Exemplo n.º 1
0
void get_hand_interval_2 (IplImage *body, int *interval)
{
	CvMat *data, *labels, *means;
	int count;

#define CLUSTERS 2
	
	count = cvCountNonZero(body);
	data = cvCreateMat(count, 1, CV_32FC1);
	labels = cvCreateMat(count, 1, CV_32SC1);
	means = cvCreateMat(CLUSTERS, 1, CV_32FC1);

	fill_mat(body, data);
	cvKMeans2(data, CLUSTERS, labels,
		  cvTermCriteria(CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 10, 10.0),
		  1, 0, 0, means, 0);

	double tmp;
	cvMinMaxLoc(body, &tmp, NULL, NULL, NULL, NULL);
	interval[0] = tmp;
	cvMinMaxLoc(means, &tmp, NULL, NULL, NULL, NULL);
	interval[1] = tmp;
		  
	cvReleaseMat(&data);
	cvReleaseMat(&labels);
}
/*!
** merge this fucntion merges two files ibc into res
**
** @param input1
** @param input2
** @param res
**
** @return
*/
inline s_ppm		*merge(s_ppm	**input1,
			       s_ppm	**input2,
			       s_ppm	*res)
{
  t_pixel		tmp;

  if (((*input1)->learned == 0) || ((*input2)->learned == 0) ||
      ((*input1)->size != (*input2)->size))
    exit(1);
  res = xmalloc(sizeof (s_ppm));
  res->pixel = xmalloc((*input1)->size * sizeof (s_pixel));
  res->size = (*input1)->size;
  res->largeur = (*input1)->largeur;
  res->hauteur = (*input1)->hauteur;
  res->lambda = -1;
  short	l = (*input1)->learned;
  short	k = (*input2)->learned;
  res->learned = l + k;
  for (int i = 0; i < res->size; i++)
    {
      tmp = (*input1)->pixel[i].red * l + (*input2)->pixel[i].red * k;
      res->pixel[i].red = tmp / (l + k);
      tmp = (*input1)->pixel[i].green * l + (*input2)->pixel[i].green * k;
      res->pixel[i].green = tmp / (k + l);
      tmp = (*input1)->pixel[i].blue * l + (*input2)->pixel[i].blue * k;
      res->pixel[i].blue = tmp / (l + k);
      fill_mat(&res, input1, input2, i);
    }
  return (res);
}
Exemplo n.º 3
0
int main(void) {

    fill_mat((double*)a);
    // print_mat((double*)a);

    stopwatch_restart();
    // assume L[i][i] == 1
    // #pragma omp parallel for
    // for (size_t j = 0; j < N; j++){
    //     for (size_t i = 0; i < N; i++){
    //         if(i <= j){
    //             double sum = 0;
    //             for (int k = 0; k < i; k++)
    //                 sum += a[i][k] * a[k][j];
    //             a[i][j] -= sum;
    //         }
    //         if(i > j){
    //             double sum = 0;
    //             for (int k = 0; k < j; k++)
    //                 sum += a[i][k] * a[k][j];
    //             a[i][j] = (a[i][j] - sum) / a[j][j];
    //         }
    //     }
    // }
    //

    //LU-decomposition based on Gaussian Elimination
    // - Arranged so that the multiplier doesn't have to be computed multiple times
    for(int k = 0; k < N-1; k++){ //iterate over rows/columns for elimination
        // The "multiplier" is the factor by which a row is multiplied when
        //  being subtracted from another row.
        for(int row = k + 1; row < N; row++){
            // the multiplier only depends on (k,row),
            // it is invariant with respect to col
            double factor = a[row][k]/a[k][k];

            //Eliminate entries in sub (subtract rows)
            for(int col = k + 1; col < N; col++){ //column
                a[row][col] = a[row][col] - factor*a[k][col];
            }

            a[row][k] = factor;
        }
    }

    printf("time = %llu us\n", (long long unsigned)stopwatch_record());

    // print_mat((double*)a);

    return 0;

}
Exemplo n.º 4
0
int		get_mat(char *info, t_v3D **coord, t_materiau *mater)
{
  int		j;
  int		*mat;

  j = -1;
  if (!info)
    return (write(2, MALLOC_ERR, 21));
  while (++j < 1)
    if (!my_strcmp(info, g_defmat[j].name))
    {
      mater = &(g_defmat[j].materiau);
      return (0);
    }
  if (!(mat = parse_it(info, 5)))
    return (write(2, MALLOC_ERR, 21));
  if (!(mater = fill_mat(mat)))
    return (write(2, MALLOC_ERR, 21));
  free(info);
  return (0);
}
Exemplo n.º 5
0
/*!
 * \brief Compute depth interval defined by the hand. 
 *
 * Starting from the depth body image this function computes the depth
 * interval related to the hand, these two depth values are later used
 * as thresholds for the binarization procedure. This interval is
 * calculated through a K-means clustering of the body image.
 *
 * \param[in]      body depth image
 * \param[out]  hand depth min max values 
 */
void get_hand_interval (IplImage *body, int *interval)
{
	CvMat  *data, *par, *means;
	double var;
	int    min, count = cvCountNonZero(body);

	data  = cvCreateMat(count, 1, CV_32FC1);
	par   = cvCreateMat(count, 1, CV_8UC1);
	means = cvCreateMat(K, 1, CV_32FC1);

	fill_mat(body, data);

	min = kmeans_clustering(data, means, par);

	//var = get_cluster_var(data, par);

	interval[0] = min;
	interval[1] = (int)cvmGet(means, 0, 0); //- var;

	cvReleaseMat(&data);
	cvReleaseMat(&par);
	cvReleaseMat(&means);
}