An instance sequence mixed with mpi_init () and gtk_init ()

Source: Internet
Author: User
Int main (INT argc, char * argv [])
{
Int I, N;

Pthread_t draw_thread;
# Ifdef usempi
Mpi_init (& argc, & argv );
Mpi_comm_size (mpi_comm_world, & num_nodes );
Mpi_comm_rank (mpi_comm_world, & rank );
# Endif

// Parse using line ARGs
While (I = getopt (argc, argv, "d: R: W: N: shx: Y :"))! = EOF ){
Switch (I ){
Case 'D ':
DEBUG = atoi (optarg );
Break;
Case 'X ':
Initpos [0] = atoi (optarg );
Break;
Case 'y ':
Initpos [1] = atoi (optarg );
Break;
Case's ':
Showgui = 0;
Break;
Case 'N ':
Samples = atoi (optarg );
Break;
Case 'r ':
N = strlen (optarg );
If (sequence! = NULL & Rank = 0 ){
Printf ("can't use both-R and-W simultaneously !!! \ N ");
Exit (1 );
}
Sequence = calloc (n + 1, sizeof (char ));
Strcpy (sequence, optarg );
Pt_mode = pt_read;
Break;
Case 'W ':
N = strlen (optarg );
If (sequence! = NULL & Rank = 0 ){
Printf ("can't use both-R and-W simultaneously !!! \ N ");
Exit (1 );
}
Sequence = calloc (n + 1, sizeof (char ));
Strcpy (sequence, optarg );
Pt_mode = pt_write;
Break;
Case 'H ':
Default:
If (Rank = 0 ){
Printf ("Usage: partracker [Options] \ n "\
"\ N "\
"[-D <level>] \ n "\
"Displays <level> debug information \ n "\
"\ N "\
"[-R <basename] \ n "\
"Reads the frames from a sequence of JPG files named \ n "\
"<Basename> *. jpg instead of from a video4linux camera. \ n "\
"For example: \ n "\
"Partracker-r test \ n "\
"Wocould read all files named test *. jpg in sorted order \ n "\
"\ N "\
"[-W <basename>] \ n "\
"Writes the raw frames (before processing them) \ n "\
"To a sequence of JPG files starting at <basename> pai.jpg \ n "\
"\ N "\
"[-X <xpos>] \ n "\
"Sets the initial X-position of the tracker to <xpos> \ n "\
"\ N "\
"[-Y <ypos>] \ n "\
"Sets the initial y-position of the tracker to <ypos> \ n "\
"Default initial position is (30,30) \ n "\
"\ N "\
"[-N <samples] \ n "\
"Sets the number of samples per iteration of the \ n "\
"Condensation filter to <samples> (default: 1000) \ n "\
"\ N "\
"[-S] \ n "\
"Suppresses GUI display for faster processing \ n ");
}
Exit (0 );
}
}

If (Rank = 0 ){
Printf ("% d/% d: partracker v0.01: using D = % d, n = % d, % S % s, % s, (% d, % d) \ n ",
Rank, num_nodes, debug, samples,
(Sequence = NULL? "": (Pt_mode = pt_read? "Reading from": "writing ")),
(Sequence = NULL? "<Live feed>": sequence ),
(Showgui? "Gui": "No Gui"), initpos [0], initpos [1]);
}

# Ifdef nocam
If (pt_mode! = Pt_read ){
Printf ("no capture device available !!! \ Nplease specify a read sequence. Try partracker-H for usage information. \ nquitting... \ n ");
Exit (1 );
}
# Endif

G_thread_init (null );

# Ifdef Gui
If (Rank = 0 ){
Gtk_set_locale ();
Gtk_init (& argc, & argv );
Gdk_rgb_init ();
}
# Endif

// Initialize the storage structures
Memset (& gcamera, 0, sizeof (struct capturedata ));
Gcamera. current_display = small_image;
Gcamera. desired. capture_size = ecs_vga;

Pthread_mutex_init (& gcamera. desired. Lock, null );
Pthread_cond_init (& gcamera. desired. cond, null );
Pthread_mutex_init (& gcamera. image. Lock, null );

Partrackerinit ();

Open_camera (& gcamera );
Set_camera_info (& gcamera );
Get_camera_info (& gcamera );
# Ifdef Gui
If (Rank = 0 & showgui ){
Mainwindow = create_mainwindow ();
Gcamera. displayarea [small_image]. drawing_area = lookup_widget (mainwindow, "drawingarea ");
G_assert (gcamera. displayarea [small_image]. drawing_area );

Init_capture_widgets (& gcamera );
Gtk_widget_show (mainwindow );
}
# Endif
If (setup_memory_mapping (& gcamera ))
Exit (1 );

Gcamera. Timer = g_timer_new ();
G_timer_start (gcamera. Timer );

# Ifdef Gui
Pthread_create (& draw_thread, null, (void *) & draw_image, (void *) null );

Gdk_threads_enter ();
Gtk_main ();
Gdk_threads_leave ();

Gquitflag = true;
Pthread_join (draw_thread, null );
# Else
Draw_image ();
# Endif

// Clean up
Close_camera (& gcamera );

If (sequence! = NULL)
Free (sequence );

Partrackercleanup ();

# Ifdef Gui
For (I = 0; I <2; I ++ ){
If (gcamera. displayarea [I]. pixmap ){
Gdk_pixmap_unref (gcamera. displayarea [I]. pixmap );
Gcamera. displayarea [I]. pixmap = NULL;
}
}
# Endif

# Ifdef usempi
Mpi_finalize ();
# Endif
G_timer_stop (gcamera. Timer );
G_timer_destroy (gcamera. Timer );

Pthread_mutex_destroy (& gcamera. desired. Lock );
Pthread_cond_destroy (& gcamera. desired. Cond );
Pthread_mutex_destroy (& gcamera. image. Lock );

Return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.