Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to run CamShift using threads
    text
    copied!<p>I wrote code that creates 2 threads (I'm using glib). The first thread runs a function called <code>Camera</code> that just starts capturing from the camera, and shows the captured frames on the screen. The second function is the algorithm <code>CamShift</code> that uses the captured image from the first function to start running. I made the first function to capture from the camera because later I will add more algorithms like <code>CamShift</code> that will access the captures from the first function. </p> <p>My problem is that I want these 2 functions to continue running until I tell them to stop. But I'm new using threads and the way I wrote the code it compiles fine and runs the 2 functions, but they just "pause" immediately after they start. Below is the code of my 2 functions.</p> <pre><code>//**********Sensa iluminacion (hilo)****************************************** GThread *idGHilo,*idGHilo1, *idGHilo2, *idGHilo3, *idGHilo4; GError **error = NULL; char *valorDevuelto = NULL;/* Valor que va a devolver el thread hijo */ if(!g_thread_supported()) // se inicializa el sistema de hilos (se emplea cuando se g_thread_init( NULL ); // emplean más de un hilo idGHilo1 = g_thread_create( (GThreadFunc) Camara, NULL, TRUE, error );//esto lo cambie ayer 23 /* Comprobamos el error al arrancar el thread */ if(error) { g_print( "Error: %s\n", error[0]-&gt;message ); g_error_free( error[0] ); //exit (-1); } sleep( 10 ); // se da un retardo para dar tiempo a que termine el hilo idGHilo2 = g_thread_create( (GThreadFunc) CamShift2, NULL, FALSE, error ); if(error) { g_print( "Error: %s\n", error[0]-&gt;message ); g_error_free( error[0] ); //exit (-1); } sleep( 10 ); //10...5 g_thread_join( idGHilo1 ); g_thread_join( idGHilo2 ); //**************************** // This is the camera function void Camara() { capture = cvCaptureFromCAM( 0 ); while( stop != 's' ) { // get a frame frame = cvQueryFrame( capture ); // always check if( !frame ) break; // 'fix' frame cvFlip( frame, frame, 2 ); frame-&gt;origin = 0; cvNamedWindow( "Camara", CV_WINDOW_AUTOSIZE ); cvShowImage( "Camara", frame ); // quit if user press 'q' stop = cvWaitKey( 10 ); } } </code></pre> <p>The other function is the regular <code>CamShift</code> algorithm that comes with OpenCV. I just modified it to use the captured frames from the <code>Camera</code> function. That works fine, but the problem is, like I said before, the 2 functions start and then just pause.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload