Exemple #1
0
gboolean
gtk_css_node_declaration_equal (gconstpointer elem1,
                                gconstpointer elem2)
{
  const GtkCssNodeDeclaration *decl1 = elem1;
  const GtkCssNodeDeclaration *decl2 = elem2;
  GQuark *classes1, *classes2;
  GtkRegion *regions1, *regions2;
  guint i;

  if (decl1 == decl2)
    return TRUE;

  if (decl1->type != decl2->type)
    return FALSE;

  if (decl1->name != decl2->name)
    return FALSE;

  if (decl1->state != decl2->state)
    return FALSE;

  if (decl1->id != decl2->id)
    return FALSE;

  if (decl1->n_classes != decl2->n_classes)
    return FALSE;

  classes1 = get_classes (decl1);
  classes2 = get_classes (decl2);
  for (i = 0; i < decl1->n_classes; i++)
    {
      if (classes1[i] != classes2[i])
        return FALSE;
    }

  if (decl1->n_regions != decl2->n_regions)
    return FALSE;

  regions1 = get_regions (decl1);
  regions2 = get_regions (decl2);
  for (i = 0; i < decl1->n_regions; i++)
    {
      if (regions1[i].class_quark != regions2[i].class_quark ||
          regions1[i].flags != regions2[i].flags)
        return FALSE;
    }

  if (decl1->junction_sides != decl2->junction_sides)
    return FALSE;

  return TRUE;
}
Exemple #2
0
void
gtk_css_node_declaration_add_to_widget_path (const GtkCssNodeDeclaration *decl,
                                             GtkWidgetPath               *path,
                                             guint                        pos)
{
  GQuark *classes;
  GtkRegion *regions;
  guint i;

  /* Set name and id */
  gtk_widget_path_iter_set_object_name (path, pos, decl->name);
  if (decl->id)
    gtk_widget_path_iter_set_name (path, pos, decl->id);

  /* Set widget regions */
  regions = get_regions (decl);
  for (i = 0; i < decl->n_regions; i++)
    {
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
      gtk_widget_path_iter_add_region (path, pos,
                                       g_quark_to_string (regions[i].class_quark),
                                       regions[i].flags);
G_GNUC_END_IGNORE_DEPRECATIONS
    }

  /* Set widget classes */
  classes = get_classes (decl);
  for (i = 0; i < decl->n_classes; i++)
    {
      gtk_widget_path_iter_add_qclass (path, pos, classes[i]);
    }

  /* Set widget state */
  gtk_widget_path_iter_set_state (path, pos, decl->state);
}
Exemple #3
0
guint
gtk_css_node_declaration_hash (gconstpointer elem)
{
  const GtkCssNodeDeclaration *decl = elem;
  GQuark *classes;
  GtkRegion *regions;
  guint hash, i;
  
  hash = (guint) decl->type;
  hash ^= GPOINTER_TO_UINT (decl->name);
  hash <<= 5;
  hash ^= GPOINTER_TO_UINT (decl->id);

  classes = get_classes (decl);
  for (i = 0; i < decl->n_classes; i++)
    {
      hash <<= 5;
      hash += classes[i];
    }

  regions = get_regions (decl);
  for (i = 0; i < decl->n_regions; i++)
    {
      hash <<= 5;
      hash += regions[i].class_quark;
      hash += regions[i].flags;
    }

  hash ^= ((guint) decl->junction_sides) << (sizeof (guint) * 8 - 5);
  hash ^= decl->state;

  return hash;
}
Exemple #4
0
gboolean
gtk_css_node_declaration_add_region (GtkCssNodeDeclaration **decl,
                                     GQuark                  region_quark,
                                     GtkRegionFlags          flags)
{
  GtkRegion *regions;
  guint pos;

  if (find_region (*decl, region_quark, &pos))
    return FALSE;

  gtk_css_node_declaration_make_writable_resize (decl,
                                                 (char *) &get_regions (*decl)[pos] - (char *) *decl,
                                                 sizeof (GtkRegion),
                                                 0);
  (*decl)->n_regions++;
  regions = get_regions(*decl);
  regions[pos].class_quark = region_quark;
  regions[pos].flags = flags;

  return TRUE;
}
Exemple #5
0
gboolean
gtk_css_node_declaration_clear_regions (GtkCssNodeDeclaration **decl)
{
  if ((*decl)->n_regions == 0)
    return FALSE;

  gtk_css_node_declaration_make_writable_resize (decl,
                                                 (char *) get_regions (*decl) - (char *) *decl,
                                                 0,
                                                 sizeof (GtkRegion) * (*decl)->n_regions);
  (*decl)->n_regions = 0;

  return TRUE;
}
Exemple #6
0
static gboolean
find_region (const GtkCssNodeDeclaration *decl,
             GQuark                       region_quark,
             guint                       *position)
{
  gint min, max, mid;
  gboolean found = FALSE;
  GtkRegion *regions;
  guint pos;

  if (position)
    *position = 0;

  if (decl->n_regions == 0)
    return FALSE;

  min = 0;
  max = decl->n_regions - 1;
  regions = get_regions (decl);

  do
    {
      GQuark item;

      mid = (min + max) / 2;
      item = regions[mid].class_quark;

      if (region_quark == item)
        {
          found = TRUE;
          pos = mid;
          break;
        }
      else if (region_quark > item)
        min = pos = mid + 1;
      else
        {
          max = mid - 1;
          pos = mid;
        }
    }
  while (min <= max);

  if (position)
    *position = pos;

  return found;
}
Exemple #7
0
GList *
gtk_css_node_declaration_list_regions (const GtkCssNodeDeclaration *decl)
{
  GtkRegion *regions;
  GList *result;
  guint i;

  regions = get_regions (decl);
  result = NULL;

  for (i = 0; i < decl->n_regions; i++)
    {
      result = g_list_prepend (result, GUINT_TO_POINTER (regions[i].class_quark));
    }

  return result;
}
Exemple #8
0
gboolean
gtk_css_node_declaration_remove_region (GtkCssNodeDeclaration **decl,
                                        GQuark                  region_quark)
{
  guint pos;

  if (!find_region (*decl, region_quark, &pos))
    return FALSE;

  gtk_css_node_declaration_make_writable_resize (decl,
                                                 (char *) &get_regions (*decl)[pos] - (char *) *decl,
                                                 0,
                                                 sizeof (GtkRegion));
  (*decl)->n_regions--;

  return TRUE;
}
Exemple #9
0
gboolean
gtk_css_node_declaration_has_region (const GtkCssNodeDeclaration  *decl,
                                     GQuark                        region_quark,
                                     GtkRegionFlags               *flags_return)
{
  guint pos;

  if (!find_region (decl, region_quark, &pos))
    {
      if (flags_return)
        *flags_return = 0;
      return FALSE;
    }

  if (flags_return)
    *flags_return = get_regions (decl)[pos].flags;

  return TRUE;
}
Exemple #10
0
int main(int argc, char *argv[])
{
	DWORD dwPid = 7668;//GetCurrentProcessId();
	HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwPid);
	 
	for (auto region : get_regions(hProcess))
		print_range((ULONG_PTR)region.BaseAddress, (ULONG_PTR)region.BaseAddress + region.RegionSize); 

	printf("\nDLLs:\n"); 

	for (auto module : get_modules(hProcess))
		print_range((ULONG_PTR)module.lpBaseOfDll, (ULONG_PTR)module.lpBaseOfDll + (ULONG_PTR)module.lpBaseOfDll);

	printf("\nThreads:\n");
	for (auto thread : get_threads(dwPid))
		print_range((ULONG_PTR)thread.Eip, (ULONG_PTR)thread.Esp);

	getchar();
	return 0;
}
Exemple #11
0
/**
 * @brief Main principal
 * @param argc El número de argumentos del programa
 * @param argv Cadenas de argumentos del programa
 * @return Nada si es correcto o algún número negativo si es incorrecto
 */
int main( int argc, char** argv ) {
	
	if( argc < 5 )
		return -1;

	// Declaración de variables
	gsl_rng *rng;
	IplImage *frame, *hsv_frame;
	float **ref_histos, histo_aux[atoi(argv[4])][HTAM];
	CvCapture *video;
	particle **particles, **aux, **nuevas_particulas;
	CvScalar color_rojo = CV_RGB(255,0,0), color_azul = CV_RGB(0,0,255);
	float factor = 1.0 / 255.0, sum = 0.0f;
	CvRect *regions;
	int num_objects = 0;
	int MAX_OBJECTS = atoi(argv[3]), PARTICLES = atoi(argv[2]);
	FILE *datos;
	char name[45], num[3], *p1, *p2;
	double t_ini, t_fin;
	
	video = cvCaptureFromFile( argv[1] );
	if( !video ) {
		printf("No se pudo abrir el fichero de video %s\n", argv[1]);
		exit(-1);
	}

	int nFrames = (int) cvGetCaptureProperty( video , CV_CAP_PROP_FRAME_COUNT );
	first_frame = cvQueryFrame( video );
	num_objects = get_regions( &regions,  MAX_OBJECTS, argv[1] );
	if( num_objects == 0 )
		exit(-1);

	t_ini = omp_get_wtime();
	// Inicializamos el generador de números aleatorios
	gsl_rng_env_setup();
	rng = gsl_rng_alloc( gsl_rng_mt19937 );
	gsl_rng_set(rng, (unsigned long) time(NULL));

	hsv_frame = bgr2hsv( first_frame );
	nuevas_particulas = (particle**) malloc( num_objects * sizeof( particle* ) );
	for( int j = 0; j < num_objects; ++j )
		nuevas_particulas[j] = (particle*) malloc( PARTICLES * sizeof( particle ) );
	
	// Computamos los histogramas de referencia y distribuimos las partículas iniciales
	ref_histos = compute_ref_histos( hsv_frame, regions, num_objects );
	particles = init_distribution( regions, num_objects, PARTICLES );

	// Mostramos el tracking
	if( show_tracking ) {

		// Mostramos todas las partículas
		if( show_all )
			for( int k = 0; k < num_objects; ++k )
				for( int j = 0; j < PARTICLES; ++j )
					display_particle( first_frame, particles[k][j], color_azul );

		// Dibujamos la partícula más prometedora de cada objeto
		for( int k = 0; k < num_objects; ++k )
			display_particle( first_frame, particles[k][0], color_rojo );

		cvNamedWindow( "RGB", 1 );
		cvShowImage( "RGB", first_frame );
		cvWaitKey( 5 );
	}

	// Exportamos los histogramas de referencia y los frames
	if( exportar ) {
		export_ref_histos( ref_histos, num_objects );
		export_frame( first_frame, 1 );

		for( int k = 0; k < num_objects; ++k ) {
			sprintf( num, "%02d", k );
			strcpy( name, REGION_BASE);
			p1 = strrchr( argv[1], '/' );
			p2 = strrchr( argv[1], '.' );
			strncat( name, (++p1), p2-p1 );
			strcat( name, num );
			strcat( name, ".txt" );
			datos = fopen( name, "a+" );
			if( ! datos ) {
				printf("Error creando fichero para datos\n");
				exit(-1);;
			}
			fprintf( datos, "%d\t%f\t%f\n", 0, particles[k][0].x, particles[k][0].y );
			fclose( datos );
		}
	}

	// Bucle principal!!
	#pragma omp parallel num_threads(atoi(argv[4])) shared(sum)
	for(int i = 1; i < nFrames; ++i) {

		// Recordar que frame no se puede liberar debido al cvQueryFrame
		#pragma omp master
			frame = cvQueryFrame( video );
		#pragma omp barrier

		#pragma omp for schedule(guided,1)
		for( int f = 0 ; f < hsv_frame->height; ++f ) {
			float *ptrHSV = (float*) ( hsv_frame->imageData + hsv_frame->widthStep*f );
			unsigned char *ptrRGB = (unsigned char*) ( frame->imageData + frame->widthStep*f );
			float h;
			for( int col = 0, despH = 0; col < hsv_frame->width; ++col, despH+=3 ) {
				int despS = despH+1;
				int despV = despH+2;
				float b = ptrRGB[despH] * factor;
				float g = ptrRGB[despS] * factor;
				float r = ptrRGB[despV] * factor;
				float min = MIN(MIN(b, g), r);
				float max = MAX(MAX(b, g), r);
				ptrHSV[despV] = max; // v
				if( max != min ) {
					float delta = max - min;
					ptrHSV[despS] = delta / max; // s = (max - min) / max = 1.0 - (min / max)
					if( r == max )
						h = ( g - b ) / delta;
					else if( g == max )
						h = 2.0f + (( b - r ) / delta);
					else
						h = 4.0f + (( r - g ) / delta);
					h *= 60.0f;
					if(h < 0.0f)
						h += 360.0f;
					ptrHSV[despH] = h; // h
				}
				else {
					ptrHSV[despH] = 0.0f; // h
					ptrHSV[despS] = 0.0f; // s
				}
			}
		}

		// Realizamos la predicción y medición de probabilidad para cada partícula
		for( int k = 0; k < num_objects; ++k ) {

			sum = 0.0f;
			#pragma omp for reduction(+:sum) schedule(guided, 1)
			for( int j = 0; j < PARTICLES; ++j ) {
				transition( &particles[k][j], frame->width, frame->height, rng );
				particles[k][j].w = likelihood( hsv_frame, &particles[k][j], ref_histos[k], histo_aux[omp_get_thread_num()] );
				sum += particles[k][j].w;
			}
		
			// Normalizamos los pesos y remuestreamos un conjunto de partículas no ponderadas
			#pragma omp for
			for( int j = 0; j < PARTICLES; ++j )
				particles[k][j].w /= sum;
		}

		// Remuestreamos un conjunto de partículas no ponderadas
		#pragma omp for
		for (int k = 0; k < num_objects; ++k )
			resample( particles[k], PARTICLES, nuevas_particulas[k] );

		#pragma omp master
		{
			aux = particles;
			particles = nuevas_particulas;
			nuevas_particulas = aux;

			// Mostramos el tracking
			if( show_tracking ) {

				// Mostramos todas las partículas
				if( show_all )
					for( int k = 0; k < num_objects; ++k )
						for( int j = 0; j < PARTICLES; ++j )
							display_particle( frame, particles[k][j], color_azul );
	
				// Dibujamos la partícula más prometedora de cada objeto
				for( int k = 0; k < num_objects; ++k )
					display_particle( frame, particles[k][0], color_rojo );
				cvNamedWindow( "RGB", 1 );
				cvShowImage( "RGB", frame );
				cvWaitKey( 5 );
			}

			// Exportamos los histogramas de referencia y los frames
			if( exportar ) {
				export_frame( frame, i+1 );

				for( int k = 0; k < num_objects; ++k ) {
					sprintf( num, "%02d", k );
					strcpy( name, REGION_BASE);
					p1 = strrchr( argv[1], '/' );
					p2 = strrchr( argv[1], '.' );
					strncat( name, (++p1), p2-p1 );
					strcat( name, num );
					strcat( name, ".txt" );
					datos = fopen( name, "a+" );
					if( ! datos ) {
						printf("Error abriendo fichero para datos\n");
						exit(-1);
					}
					fprintf( datos, "%d\t%f\t%f\n", i, particles[k][0].x, particles[k][0].y );
					fclose( datos );
				}
			}
		}
	}
	
	// Liberamos todos los recursos usados (mallocs, gsl y frames)
	cvReleaseImage( &hsv_frame );
	cvReleaseCapture( &video );
	gsl_rng_free( rng );
	free( regions );

	for( int i = 0; i < num_objects; ++i ) {
		free( ref_histos[i] );
		free( particles[i] );
		free( nuevas_particulas[i] );
	}

	free( particles );
	free( nuevas_particulas );

	t_fin = omp_get_wtime();
	printf("%d\t%d\t%.10g\n", PARTICLES, num_objects, (t_fin - t_ini) * 1000);
}
Exemple #12
0
/**
 * @brief Main principal
 * @param argc El número de argumentos del programa
 * @param argv Cadenas de argumentos del programa
 * @return Nada si es correcto o algún número negativo si es incorrecto
 */
int main( int argc, char** argv ) {
	
	if( argc < 4 )
		return -1;

	// Declaración de variables
	gsl_rng *rng;
	IplImage *frame, *hsv_frame;
	histogram **ref_histos, *histo_aux;
	CvCapture *video;
	particle **particles, **aux, **nuevas_particulas;
	CvScalar color_rojo = CV_RGB(255,0,0), color_azul = CV_RGB(0,0,255);
	CvRect *regions;
	int num_objects = 0;
	int i = 1, MAX_OBJECTS = atoi(argv[3]), PARTICLES = atoi(argv[2]);
	FILE *datos;
	char name[45], num[3], *p1, *p2;
	clock_t t_ini, t_fin;
	double ms;
	
	video = cvCaptureFromFile( argv[1] );
	if( !video ) {
		printf("No se pudo abrir el fichero de video %s\n", argv[1]);
		exit(-1);
	}

	first_frame = cvQueryFrame( video );
	num_objects = get_regions( &regions,  MAX_OBJECTS, argv[1] );
	if( num_objects == 0 )
		exit(-1);

	t_ini = clock();
	hsv_frame = bgr2hsv( first_frame );
	histo_aux = (histogram*) malloc( sizeof(histogram) );
	histo_aux->n = NH*NS + NV;
	nuevas_particulas = (particle**) malloc( num_objects * sizeof( particle* ) );
	for( int j = 0; j < num_objects; ++j )
		nuevas_particulas[j] = (particle*) malloc( PARTICLES * sizeof( particle ) );
			
	// Computamos los histogramas de referencia y distribuimos las partículas iniciales
	ref_histos = compute_ref_histos( hsv_frame, regions, num_objects );
	particles = init_distribution( regions, num_objects, PARTICLES );

	// Mostramos el tracking
	if( show_tracking ) {

		// Mostramos todas las partículas
		if( show_all )
			for( int k = 0; k < num_objects; ++k )
				for( int j = 0; j < PARTICLES; ++j )
					display_particle( first_frame, particles[k][j], color_azul );

		// Dibujamos la partícula más prometedora de cada objeto
		for( int k = 0; k < num_objects; ++k )
			display_particle( first_frame, particles[k][0], color_rojo );

		cvNamedWindow( "Video", 1 );
		cvShowImage( "Video", first_frame );
		cvWaitKey( 5 );
	}

	// Exportamos los histogramas de referencia y los frames
	if( exportar ) {
		export_ref_histos( ref_histos, num_objects );
		export_frame( first_frame, 1 );

		for( int k = 0; k < num_objects; ++k ) {
			sprintf( num, "%02d", k );
			strcpy( name, REGION_BASE);
			p1 = strrchr( argv[1], '/' );
			p2 = strrchr( argv[1], '.' );
			strncat( name, (++p1), p2-p1 );
			strcat( name, num );
			strcat( name, ".txt" );
			datos = fopen( name, "a+" );
			if( ! datos ) {
				printf("Error creando fichero para datos\n");
				return -1;
			}
			fprintf( datos, "%d\t%f\t%f\n", 0, particles[k][0].x, particles[k][0].y );
			fclose( datos );
		}
	}

	cvReleaseImage( &hsv_frame );
	
	// Inicializamos el generador de números aleatorios
	gsl_rng_env_setup();
	rng = gsl_rng_alloc( gsl_rng_mt19937 );
	gsl_rng_set(rng, (unsigned long) time(NULL));

	// Recordar que frame no se puede liberar debido al cvQueryFrame
	while( frame = cvQueryFrame( video ) ) {
		hsv_frame = bgr2hsv( frame );

		// Realizamos la predicción y medición de probabilidad para cada partícula
		for( int k = 0; k < num_objects; ++k )
			for( int j = 0; j < PARTICLES; ++j ) {
				transition( &particles[k][j], frame->width, frame->height, rng );
				particles[k][j].w = likelihood( hsv_frame, &particles[k][j], ref_histos[k], histo_aux );
			}
			
		// Normalizamos los pesos y remuestreamos un conjunto de partículas no ponderadas
		normalize_weights( particles, num_objects, PARTICLES );
		for (int k = 0; k < num_objects; ++k )
			resample( particles[k], PARTICLES, nuevas_particulas[k] );
		aux = particles;
		particles = nuevas_particulas;
		nuevas_particulas = aux;

		// Mostramos el tracking
		if( show_tracking ) {

			// Mostramos todas las partículas
			if( show_all )
				for( int k = 0; k < num_objects; ++k )
					for( int j = 0; j < PARTICLES; ++j )
						display_particle( frame, particles[k][j], color_azul );
		
			// Dibujamos la partícula más prometedora de cada objeto
			for( int k = 0; k < num_objects; ++k )
				display_particle( frame, particles[k][0], color_rojo );
			cvNamedWindow( "Video", 1 );
			cvShowImage( "Video", frame );
			cvWaitKey( 5 );
		}

		// Exportamos los histogramas de referencia y los frames
		if( exportar ) {
			export_frame( frame, i+1 );

			for( int k = 0; k < num_objects; ++k ) {
				sprintf( num, "%02d", k );
				strcpy( name, REGION_BASE);
				p1 = strrchr( argv[1], '/' );
				p2 = strrchr( argv[1], '.' );
				strncat( name, (++p1), p2-p1 );
				strcat( name, num );
				strcat( name, ".txt" );
				datos = fopen( name, "a+" );
				if( ! datos ) {
					printf("Error abriendo fichero para datos\n");
					return -1;
				}
				fprintf( datos, "%d\t%f\t%f\n", i, particles[k][0].x, particles[k][0].y );
				fclose( datos );
			}
		}

		cvReleaseImage( &hsv_frame );
		++i;
	}
	
	// Liberamos todos los recursos usados (mallocs, gsl y frames)
	cvReleaseCapture( &video );
	gsl_rng_free( rng );
	free( histo_aux );
	free( regions );

	for( int i = 0; i < num_objects; ++i ) {
		free( ref_histos[i] );
		free( particles[i] );
		free( nuevas_particulas[i] );
	}

	free( particles );
	free( nuevas_particulas );

	t_fin = clock();
	ms = ((double)(t_fin - t_ini) / CLOCKS_PER_SEC) * 1000.0;
	printf("%d\t%d\t%.10g\n", PARTICLES, num_objects, ms);
}