<font size=2 face="sans-serif">Hello there,</font>
<br>
<br><font size=2 face="sans-serif">Thank you for your comments, the component
is running *almost* properly now. Long story short, I was not allocating
the memory for the FramePair structure correctly.</font>
<br>
<br><font size=2 face="sans-serif">The execution and the data in the output
port is correct, however, I still have a problem when exiting the component.
When the destructor Task class is called I get a pretty ugly error starting
by:</font>
<br>
<br><font size=2 face="sans-serif">*** glibc detected *** /.../orogen_default__Task:
free(): invalid pointer</font>
<br>
<br><font size=2 face="sans-serif">and followed by a backtrace and a memory
map. I guess the error has to do with the fact that I am not de-allocating
the memory properly. I tried doing so in the cleanupHook without success
though. Here below is the code from the Task.cpp (only coded Hooks). How
should I de-allocate the memory for the frame_pair structure?</font>
<br>
<br><font size=2 face="sans-serif"><code></font>
<br>
<br><font size=3>bool Task::configureHook()<br>
{<br>
if (! TaskBase::configureHook())<br>
return false;<br>
<br>
index_frame=0;<br>
<br>
base::Time t;<br>
frame_pair.time = t.now();
//! frame_pair is defined in Task.hpp
as a FramePair structure type.<br>
frame_pair.first.init(_width.value(),_height.value(),_channel_data_depth.value(),_output_format.value());<br>
frame_pair.second.init(_width.value(),_height.value(),_channel_data_depth.value(),_output_format.value());<br>
</font><a href=http://frame_pair.id/><font size=3 color=blue><u>frame_pair.id</u></font></a><font size=3>
= 0;<br>
output_frame_pair.reset(&frame_pair);<br>
<br>
if (_undistort.value())<br>
{<br>
undistort_image = true;<br>
stereo_calibration = _calibration_parameters;<br>
}</font>
<br><font size=3><br>
return true;<br>
}<br>
<br>
void Task::updateHook()<br>
{<br>
TaskBase::updateHook();<br>
<br>
if (_frame_in.read(input_frame)==RTT::NewData)<br>
{<br>
Frame* left = new Frame(input_frame->size.width,
input_frame->size.height, 8, input_frame->frame_mode);<br>
Frame* right = new Frame(input_frame->size.width,
input_frame->size.height, 8, input_frame->frame_mode);<br>
deInterlace(*input_frame,*left,*right);<br>
<br>
FramePair* frame_pair_ptr=output_frame_pair.write_access();<br>
<br>
if (undistort_image)<br>
{<br>
frame_helper.setCalibrationParameter(stereo_calibration.camLeft);<br>
frame_helper.convert(*left,
frame_pair_ptr->first, 0, 0, frame_helper::INTER_LINEAR, true);<br>
frame_helper.setCalibrationParameter(stereo_calibration.camRight);<br>
frame_helper.convert(*right,
frame_pair_ptr->second, 0, 0, frame_helper::INTER_LINEAR ,true);<br>
}<br>
else<br>
{<br>
frame_helper.convert(*left,
frame_pair_ptr->first, 0, 0, frame_helper::INTER_LINEAR, false);<br>
frame_helper.convert(*right,
frame_pair_ptr->second, 0, 0, frame_helper::INTER_LINEAR, false);<br>
}</font>
<br><font size=3><br>
frame_pair_ptr->id=index_frame++;<br>
frame_pair_ptr->time = input_frame->time;<br>
output_frame_pair.reset(frame_pair_ptr);<br>
_frame_out.write(output_frame_pair);<br>
}<br>
}<br>
<br>
void Task::cleanupHook()<br>
{<br>
TaskBase::cleanupHook();</font>
<br><font size=3> <i>/// I tried deleting frame_pair and similar
things here...</i><br>
}</font>
<br>
<br><font size=3></code></font>
<br>
<br><font size=2 face="sans-serif"><b>Any ideas about what to put in the
cleanupHook or class destructor to avoid the error at exit?</b></font>
<br>
<br><font size=2 face="sans-serif">Thanks again for your support,</font><font size=3><br>
</font>
<p><font size=2 color=#001fe2 face="Verdana">Martin Azkarate</font>
<p><font size=1 color=#8f8f8f face="Verdana"><b>ESA - European Space Agency</b><br>
Spanish Trainee, TEC-MMA - Automation and Robotics Section </font>
<p><font size=1 color=#8f8f8f face="Verdana"><b>ESTEC - European Space
research and TEchnology Centre</b><br>
Keplerlaan 1, PO Box 299 <br>
NL-2200 AG Noordwijk, The Netherlands <br>
Martin.Azkarate@esa.int | </font><a href=www.esa.int><font size=1 color=#8f8f8f face="Verdana">www.esa.int</font></a><font size=1 color=#8f8f8f face="Verdana">
<br>
Tel +31 71 565 3480 | Mob +31 650 625 564 </font>
<br>
<br>
<br>
<br><font size=1 color=#5f5f5f face="sans-serif">From:
</font><font size=1 face="sans-serif">Javier Hidalgo Carrió
<javier.hidalgo_carrio@dfki.de></font>
<br><font size=1 color=#5f5f5f face="sans-serif">To:
</font><font size=1 face="sans-serif">Martin.Azkarate@esa.int</font>
<br><font size=1 color=#5f5f5f face="sans-serif">Cc:
</font><font size=1 face="sans-serif">rock-dev@dfki.de</font>
<br><font size=1 color=#5f5f5f face="sans-serif">Date:
</font><font size=1 face="sans-serif">15/07/2013 09:39</font>
<br><font size=1 color=#5f5f5f face="sans-serif">Subject:
</font><font size=1 face="sans-serif">Re: [Rock-dev]
using FramePair structure to output two frames together</font>
<br><font size=1 color=#5f5f5f face="sans-serif">Sent by:
</font><font size=1 face="sans-serif">rock-dev-bounces@dfki.de</font>
<br>
<hr noshade>
<br>
<br>
<br><font size=3>Hello Martin,<br>
<br>
Since you have a segmentation fault (Signal 11). Did you debug the code
with gdb looking to the backtrace?<br>
Here it is explained how to do it:<br>
</font><font size=3 color=blue><u><br>
</u></font><a href=http://rock.opendfki.de/wiki/WikiStart/Troubleshooting/DebuggingTechniques><font size=3 color=blue><u>http://rock.opendfki.de/wiki/WikiStart/Troubleshooting/DebuggingTechniques</u></font></a><font size=3><br>
<br>
<br>
Nevertheless,:<br>
<br>
FramePair* frame_pair;<br>
frame_pair->time=input_frame->time;<br>
<br>
To which object is frame_pair pointing to?<br>
<br>
Regards, <br>
<br>
Javier.<br>
<br>
On 07/12/2013 05:14 PM, </font><a href=mailto:Martin.Azkarate@esa.int><font size=3 color=blue><u>Martin.Azkarate@esa.int</u></font></a><font size=3>
wrote:</font>
<br><font size=3>Hello,<br>
<br>
I have the following code that works fine to separate two interlaced images
that arrive in a single port and separates them into two frames that are
sent out in two different ports:<br>
<br>
void Task::updateHook()<br>
{<br>
TaskBase::updateHook();<br>
<br>
if (_frame_in.read(input_frame)==RTT::NewData)<br>
{<br>
Frame* left = new Frame(input_frame->size.width, input_frame->size.height,
8, input_frame->frame_mode);<br>
Frame* right = new Frame(input_frame->size.width, input_frame->size.height,
8, input_frame->frame_mode);<br>
deInterlace(*input_frame,*left,*right);<br>
Frame* left_gray = new Frame(left->size.width, left->size.height,
8, MODE_GRAYSCALE);<br>
Frame* right_gray = new Frame(right->size.width,
right->size.height, 8, MODE_GRAYSCALE);<br>
frame_helper.convertColor(*left,*left_gray);<br>
frame_helper.convertColor(*right,*right_gray);<br>
frame_left.reset(left_gray);<br>
frame_right.reset(right_gray);<br>
_frame_left.write(frame_left);<br>
_frame_right.write(frame_right);<br>
}<br>
}<br>
<br>
void Task::deInterlace(const base::samples::frame::Frame &input, base::samples::frame::Frame
&left, base::samples::frame::Frame &right)<br>
{ <br>
//! Note: input frame has a data depth of 16bits while the
left and right have a data depth of 8 bits. Bytes in the input frame are
mixed in order, one byte from the left, one byte from the right, and so
on. <br>
//! So in "one pixel" of 16bits of the input frame
there are "two pixels" of 8bits one of each left and right frames.<br>
uint32_t width=(input.size.width*2);<br>
uint32_t height=input.size.height;<br>
<br>
int i = (width*height)-1;<br>
int j = ((width*height)>>1)-1;<br>
<br>
while (i >= 0) {<br>
right.image[j] = input.image[i--];<br>
left.image[j--] = input.image[i--];<br>
}<br>
<br>
left.copyImageIndependantAttributes(input);<br>
right.copyImageIndependantAttributes(input);<br>
<br>
}<br>
<br>
input_frame, frame_left and frame_right are ReadOnlyPointers of type Frame
defined in Task.hpp. Rest of the Hooks are empty/default.<u><br>
<br>
Question</u>: Even thought this does the work for me, I would like to know
if this is a correct way of doing it. Mostly regarding the creation of
several Frame pointers and allocation of memory for those in the middle
of the updateHook? (This is actually important because it is related to
the question below)<br>
<br>
Now, I would like to send out both images left and right in a single port
using the structure FramePair, to make sure that they arrive together to
the stereo processing component with a single timestamp for both (as they
were both taken at the same time by a stereo camera). However, I have tried
to replicate the same logic using the FramePair structure and always got
errors in execution (compilation is ok).<br>
<br>
Changing the last part of the updateHook to the following:<br>
<br>
void Task::updateHook()<br>
{<br>
TaskBase::updateHook();<br>
<br>
if (_frame_in.read(input_frame)==RTT::NewData)<br>
{<br>
Frame* left = new Frame(input_frame->size.width, input_frame->size.height,
8, input_frame->frame_mode);<br>
Frame* right = new Frame(input_frame->size.width, input_frame->size.height,
8, input_frame->frame_mode);<br>
deInterlace(*input_frame,*left,*right);<br>
Frame* left_gray = new Frame(left->size.width, left->size.height,
8, MODE_GRAYSCALE);<br>
Frame* right_gray = new Frame(right->size.width,
right->size.height, 8, MODE_GRAYSCALE);<br>
frame_helper.convertColor(*left,*left_gray);<br>
frame_helper.convertColor(*right,*right_gray);<br>
FramePair* frame_pair;<br>
frame_pair->id=index_frame++; //! index_frame is
defined in Task.hpp and initialized to 0 in configureHook.<br>
frame_pair->time = input_frame->time;<br>
frame_pair->first = *left_gray;<br>
frame_pair->second = *right_gray;<br>
output_frame_pair.reset(frame_pair); //! output_frame_pair
is also a ReadOnlyPointer in Task.hpp<br>
_frame_out.write(output_frame_pair);<br>
}<br>
}<br>
<br>
gives me the following error when I run it: Orocos[WARN]: deployment <i>[myTaskContext]</i>
unexpectedly terminated with signal 11<br>
<br>
After trying several ways of assigning the frames's data to the frame_pair
structure without success I understood I was not using FramePair the right
way. So I tried something very simple as:<br>
<br>
void Task::updateHook()<br>
{<br>
TaskBase::updateHook(); <br>
<br>
if (_frame_in.read(input_frame)==RTT::NewData)<br>
{<br>
FramePair* frame_pair;<br>
frame_pair->time=input_frame->time;<br>
frame_pair->id=index_frame++;<br>
frame_pair->first.init(1024,768,8,MODE_GRAYSCALE);<br>
frame_pair->second.init(1024,768,8,MODE_GRAYSCALE);<br>
output_frame_pair.reset(frame_pair);<br>
_frame_out.write(output_frame_pair);<br>
}<br>
}<br>
<br>
And it gives the same error as above and actually the execution stops before
the end of the updateHook at the line where the first.init() function is
called.<br>
<br>
I make it even simpler:<br>
<br>
void Task::updateHook()<br>
{<br>
TaskBase::updateHook(); <br>
<br>
if (_frame_in.read(input_frame)==RTT::NewData)<br>
{<br>
FramePair* frame_pair;<br>
frame_pair->time=input_frame->time;<br>
frame_pair->id=index_frame++;<br>
output_frame_pair.reset(frame_pair);<br>
_frame_out.write(output_frame_pair);<br>
}<br>
}<br>
<br>
I get the same error when exiting the updateHook.<u><br>
<br>
Question:</u> What is it that I am missing about FramePair structure that
makes it so different to the Frame structure when it comes to memory allocation?
Somebody can put some light in this?<br>
<br>
Thank you very much for your attention,<br>
<br>
Martin<br>
</font>
<p><font size=2 color=#001fe2 face="Verdana">Martin Azkarate</font><font size=3>
</font>
<p><font size=1 color=#8f8f8f face="Verdana"><b>ESA - European Space Agency</b><br>
Spanish Trainee, TEC-MMA - Automation and Robotics Section </font>
<p><font size=1 color=#8f8f8f face="Verdana"><b>ESTEC - European Space
research and TEchnology Centre</b><br>
Keplerlaan 1, PO Box 299 <br>
NL-2200 AG Noordwijk, The Netherlands </font><font size=1 color=blue face="Verdana"><u><br>
</u></font><a href=mailto:Martin.Azkarate@esa.int><font size=1 color=blue face="Verdana"><u>Martin.Azkarate@esa.int</u></font></a><font size=1 color=#8f8f8f face="Verdana">
| </font><a href=www.esa.int><font size=1 color=#8f8f8f face="Verdana"><u>www.esa.int</u></font></a><font size=1 color=#8f8f8f face="Verdana">
<br>
Tel +31 71 565 3480 | Mob +31 650 625 564 </font>
<p><tt><font size=3>This message and any attachments are intended for the
use of the addressee or addressees only. The unauthorised disclosure, use,
dissemination or copying (either in whole or in part) of its content is
not permitted. If you received this message in error, please notify the
sender and delete it from your system. Emails can be altered and their
integrity cannot be guaranteed by the sender.<br>
<br>
Please consider the environment before printing this email.<br>
</font></tt>
<br><font size=3><br>
</font>
<br><tt><font size=3>_______________________________________________<br>
Rock-dev mailing list<br>
</font></tt><a href="mailto:Rock-dev@dfki.de"><tt><font size=3 color=blue><u>Rock-dev@dfki.de</u></font></tt></a><tt><font size=3><br>
</font></tt><a href="http://www.dfki.de/mailman/cgi-bin/listinfo/rock-dev"><tt><font size=3 color=blue><u>http://www.dfki.de/mailman/cgi-bin/listinfo/rock-dev</u></font></tt></a><tt><font size=3><br>
</font></tt>
<br><font size=3><br>
</font><tt><font size=2>_______________________________________________<br>
Rock-dev mailing list<br>
Rock-dev@dfki.de<br>
</font></tt><a href="http://www.dfki.de/mailman/cgi-bin/listinfo/rock-dev"><tt><font size=2>http://www.dfki.de/mailman/cgi-bin/listinfo/rock-dev</font></tt></a><tt><font size=2><br>
</font></tt>
<br><PRE>This message and any attachments are intended for the use of the addressee or addressees only. The unauthorised disclosure, use, dissemination or copying (either in whole or in part) of its content is not permitted. If you received this message in error, please notify the sender and delete it from your system. Emails can be altered and their integrity cannot be guaranteed by the sender.
Please consider the environment before printing this email.
</PRE>