How to make NonPeriodicActivity update all the time?

Hi,<br><br>I just find to add a &quot;while(1)&quot; loop in &quot;main()&quot; that can run &quot;update&quot; of NonPeriodicActivity all the time.<br>Is that any other way to do that?<br><br><br>Today I get an error about &quot;Camera&quot; component:<br>
&lt;code&gt;<br>(Camera:21467): GLib-WARNING **: g_main_context_prepare(): main loop already active in another thread<br>**<br>** GLib:ERROR:(/build/buildd/glib2.0-2.16.6/glib/gmain.c:1963):g_main_dispatch: assertion failed: (source)<br>
&lt;/code&gt;<br><br>Is that meaning I should not use &quot;while&quot; loop in &quot;main&quot; part ?<br>I really don&#39;t understand what&#39;s that mean..<br><br><br>All your best,<br>GL<br><br>

How to make NonPeriodicActivity update all the time?

The Problem might be because I add &quot;cvWaitKey&quot; in &quot;main&quot;:<br>&lt;code&gt;<br>while(1)<br>{<br><div style="margin-left: 40px;">if(cvWaitKey(10)==27)<br>break;<br></div>&nbsp; <br>}<br>&lt;/code&gt;<br>It seems cvWaitKey has some problems with Orocos Camera part.<br>
<br><br><div class="gmail_quote">2009/2/17 guoliang liu <span dir="ltr">&lt;<a href="http://gliang.liu.cn">gliang.liu.cn</a>@<a href="http://gmail.com">gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br><br>I just find to add a &quot;while(1)&quot; loop in &quot;main()&quot; that can run &quot;update&quot; of NonPeriodicActivity all the time.<br>Is that any other way to do that?<br><br><br>Today I get an error about &quot;Camera&quot; component:<br>

&lt;code&gt;<br>(Camera:21467): GLib-WARNING **: g_main_context_prepare(): main loop already active in another thread<br>**<br>** GLib:ERROR:(/build/buildd/glib2.0-2.16.6/glib/gmain.c:1963):g_main_dispatch: assertion failed: (source)<br>

&lt;/code&gt;<br><br>Is that meaning I should not use &quot;while&quot; loop in &quot;main&quot; part ?<br>I really don&#39;t understand what&#39;s that mean..<br><br><br>All your best,<br><font color="#888888">GL<br><br>

</font></blockquote></div><br>

Ruben Smits's picture

How to make NonPeriodicActivity update all the time?

On Tuesday 17 February 2009 15:08:36 guoliang liu wrote:
> Hi,
>
> I just find to add a "while(1)" loop in "main()" that can run "update" of
> NonPeriodicActivity all the time. Is that any other way to do that?
>
>
> Today I get an error about "Camera" component:
> &#10;&gt; (Camera:21467): GLib-WARNING **: g_main_context_prepare(): main loop&#10;&gt; already active in another thread **&#10;&gt; **&#10;&gt; GLib:ERROR:(/build/buildd/glib2.0-2.16.6/glib/gmain.c:1963):g_main_dispatch&#10;&gt;: assertion failed: (source)
>
> Is that meaning I should not use "while" loop in "main" part ?
> I really don't understand what's that mean..

This is something that rings a bell:

It's due to the opencv threading for the windows. Did you use the camera
component from ocl?

It is due to calling cvShowImage in different threads, you should use the
function cvStartWindowThread() in every thread that uses cvShowImage. It also
enables the remove of the magic cvWaitKey() to make sure an image is actually
shown.

This is solved in the hardware/camera and vision (complete vision toolkit
which also has an ImageReporter, and IplImage Type support) of the ocl-pma
branch.

Ruben

How to make NonPeriodicActivity update all the time?

<br><br><div class="gmail_quote">2009/2/17 Ruben Smits <span dir="ltr">&lt;<a href="mailto:ruben [dot] smits [..] ...">ruben [dot] smits [..] ...</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d">On Tuesday 17 February 2009 15:08:36 guoliang liu wrote:<br>
</div><div><div></div><div class="Wj3C7c">&gt; Hi,<br>
&gt;<br>
&gt; I just find to add a &quot;while(1)&quot; loop in &quot;main()&quot; that can run &quot;update&quot; of<br>
&gt; NonPeriodicActivity all the time. Is that any other way to do that?<br>
&gt;<br>
&gt;<br>
&gt; Today I get an error about &quot;Camera&quot; component:<br>
&gt; &lt;code&gt;<br>
&gt; (Camera:21467): GLib-WARNING **: g_main_context_prepare(): main loop<br>
&gt; already active in another thread **<br>
&gt; **<br>
&gt; GLib:ERROR:(/build/buildd/glib2.0-2.16.6/glib/gmain.c:1963):g_main_dispatch<br>
&gt;: assertion failed: (source) &lt;/code&gt;<br>
&gt;<br>
&gt; Is that meaning I should not use &quot;while&quot; loop in &quot;main&quot; part ?<br>
&gt; I really don&#39;t understand what&#39;s that mean..<br>
<br>
</div></div>This is something that rings a bell:<br>
<br>
It&#39;s due to the opencv threading for the windows. Did you use the camera<br>
component from ocl?&nbsp;</blockquote><div><br>Yes, I am using camera component from ocl. <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
<br>
It is due to calling cvShowImage in different threads, you should use the<br>
function cvStartWindowThread() in every thread that uses cvShowImage. It also<br>
enables the remove of the magic cvWaitKey() to make sure an image is actually<br>
shown.</blockquote><div><br>Do you mean I should add cvStartWindowThread() before cvShowImage and cvWaitKey()?? <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
<br>
This is solved in the hardware/camera and vision (complete vision toolkit<br>
which also has an ImageReporter, and IplImage Type support) of the ocl-pma<br>
branch.</blockquote><div><br>Where is this branch? <br>In ocl-pma, can I use cvWaitKey in every thread without cvStartWindowThread()? <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
<br>
Ruben<br>
<font color="#888888"><br>
--<br>
Orocos-Users mailing list<br>
<a href="mailto:Orocos-Users [..] ...">Orocos-Users [..] ...</a><br>
<a href="http://lists.mech.kuleuven.be/mailman/listinfo/orocos-users" target="_blank">http://lists.mech.kuleuven.be/mailman/listinfo/orocos-users</a><br>
<br>
Disclaimer: <a href="http://www.kuleuven.be/cwis/email_disclaimer.htm" target="_blank">http://www.kuleuven.be/cwis/email_disclaimer.htm</a><br>
<br>
</font></blockquote></div><br><br><br>Thanks for your&nbsp; reply.. <br>GL<br>

Ruben Smits's picture

How to make NonPeriodicActivity update all the time?

On Tuesday 17 February 2009 15:36:49 guoliang liu wrote:
> 2009/2/17 Ruben Smits
> <ruben [dot] smits [..] ...<mailto:ruben [dot] smits [..] ...>>
>
> On Tuesday 17 February 2009 15:08:36 guoliang liu wrote:
> > Hi,
> >
> > I just find to add a "while(1)" loop in "main()" that can run "update" of
> > NonPeriodicActivity all the time. Is that any other way to do that?
> >
> >
> > Today I get an error about "Camera" component:
> > &#10;&gt; &gt; (Camera:21467): GLib-WARNING **: g_main_context_prepare(): main loop&#10;&gt; &gt; already active in another thread **&#10;&gt; &gt; **&#10;&gt; &gt; GLib:ERROR:(/build/buildd/glib2.0-2.16.6/glib/gmain.c:1963):g_main_dispat&#10;&gt; &gt;ch&#10;&gt; &gt;&#10;&gt; &gt;: assertion failed: (source)
> >
> > Is that meaning I should not use "while" loop in "main" part ?
> > I really don't understand what's that mean..
>
> This is something that rings a bell:
>
> It's due to the opencv threading for the windows. Did you use the camera
> component from ocl?
>
> Yes, I am using camera component from ocl.
>
>
> It is due to calling cvShowImage in different threads, you should use the
> function cvStartWindowThread() in every thread that uses cvShowImage. It
> also enables the remove of the magic cvWaitKey() to make sure an image is
> actually shown.
>
> Do you mean I should add cvStartWindowThread() before cvShowImage and
> cvWaitKey()??
>
>
> This is solved in the hardware/camera and vision (complete vision toolkit
> which also has an ImageReporter, and IplImage Type support) of the ocl-pma
> branch.
>
> Where is this branch?
> In ocl-pma, can I use cvWaitKey in every thread without
> cvStartWindowThread()?
I don't know, AFAIK the cvWaitKey only makes sense for an OpenCV window-
showing thread, so you must at least have on thread that you want to wait in.

I posted the needed patches on the mailinglist, in the camera component
cvWaitKey was used to make sure that the image was actually shown when the
camera-component had to show the raw-image while debugging (do not use it
otherwise, it will slow down the camera-component) We used cvWaitKey(3),. the
"3" was a magic number that sometimes worked, sometimes not. By calling
cvStartWindowThread() _once_ in the thread that will put images in the window
and wait for something, the cvWaitKey(3) could be removed and the strange GLib
warning disappeared.

Ruben
>
> Ruben
>
> --
> Orocos-Users mailing list
> Orocos-Users [..] ...<mailto:Orocos-Users [..] ...en
>.be> http://lists.mech.kuleuven.be/mailman/listinfo/orocos-users
>
> Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
>
>
>
>
> Thanks for your reply..
> GL

Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

How to make NonPeriodicActivity update all the time?

On Tuesday 17 February 2009 15:08:36 guoliang liu wrote:
> Hi,
>
> I just find to add a "while(1)" loop in "main()" that can run "update" of
> NonPeriodicActivity all the time.
> Is that any other way to do that?

Don't call update() directly. You should start the NonPeriodicActivity and
then in your component's updateHook() function, write:

// in case of updateHook():
this->engine()->getActivity()->trigger(); // will cause us to loop.

>
>
> Today I get an error about "Camera" component:
> &#10;&gt; (Camera:21467): GLib-WARNING **: g_main_context_prepare(): main loop&#10;&gt; already active in another thread&#10;&gt; **&#10;&gt; **&#10;&gt; GLib:ERROR:(/build/buildd/glib2.0-2.16.6/glib/gmain.c:1963):g_main_dispatch&#10;&gt;: assertion failed: (source)&#10;&gt;
>
> Is that meaning I should not use "while" loop in "main" part ?

Yes. Don't do that.

Peter

How to make NonPeriodicActivity update all the time?

<br>I also use trigger() in updateHook part. But in the main part ,I still need update keeps running, so I still need a while loop in &quot;main&quot; to give time to trigger update.<br>Do you think so?<br><br>The error part becauses I add cvWaitKey in the while loop..<br>
<br><br><div class="gmail_quote">2009/2/17 Peter Soetens <span dir="ltr">&lt;<a href="mailto:peter [dot] soetens [..] ...">peter [dot] soetens [..] ...</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d">On Tuesday 17 February 2009 15:08:36 guoliang liu wrote:<br>
&gt; Hi,<br>
&gt;<br>
&gt; I just find to add a &quot;while(1)&quot; loop in &quot;main()&quot; that can run &quot;update&quot; of<br>
&gt; NonPeriodicActivity all the time.<br>
&gt; Is that any other way to do that?<br>
<br>
</div>Don&#39;t call update() directly. You should start the NonPeriodicActivity and<br>
then in your component&#39;s updateHook() function, write:<br>
<br>
// in case of updateHook():<br>
this-&gt;engine()-&gt;getActivity()-&gt;trigger(); // will cause us to loop.<br>
<div class="Ih2E3d"><br>
&gt;<br>
&gt;<br>
&gt; Today I get an error about &quot;Camera&quot; component:<br>
&gt; &lt;code&gt;<br>
&gt; (Camera:21467): GLib-WARNING **: g_main_context_prepare(): main loop<br>
&gt; already active in another thread<br>
&gt; **<br>
&gt; **<br>
&gt; GLib:ERROR:(/build/buildd/glib2.0-2.16.6/glib/gmain.c:1963):g_main_dispatch<br>
&gt;: assertion failed: (source)<br>
&gt; &lt;/code&gt;<br>
&gt;<br>
&gt; Is that meaning I should not use &quot;while&quot; loop in &quot;main&quot; part ?<br>
<br>
</div>Yes. Don&#39;t do that.<br>
<br>
Peter<br>
<font color="#888888"><br>
--<br>
Peter Soetens -- FMTC -- &lt;<a href="http://www.fmtc.be" target="_blank">http://www.fmtc.be</a>&gt;<br>
</font></blockquote></div><br>

How to make NonPeriodicActivity update all the time?

On Tuesday 17 February 2009 15:30:32 guoliang liu wrote:
> I also use trigger() in updateHook part. But in the main part ,I still need
> update keeps running, so I still need a while loop in "main" to give time
> to trigger update.
> Do you think so?
>
> The error part becauses I add cvWaitKey in the while loop..

Ok. I misunderstood that part. So it's a pure OpenCV problem, I don't know how
to fix that.

Peter