[Rock-dev] using FramePair structure to output two frames together
Martin.Azkarate at esa.int
Martin.Azkarate at esa.int
Mon Jul 15 19:02:37 CEST 2013
I run the component with valgrind and use rock-display to transition in
the component states (execute hooks), I start from PRE_OPERATIONAL and go
to PRE_OPERATIONAL again going through configure, start, stop and cleanup
and no error are shown (the class destructor is not called at this point).
When calling configure for the second time, I see an error similar to what
I explained before that says I did not free the memory of the FramePair
structure correctly. Here a copy paste of the error shown in valgrind when
calling configure at the second time:
==1343== Thread 10:
==1343== Invalid free() / delete / delete[] / realloc()
==1343== at 0x4C2A4BC: operator delete(void*) (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==1343== by 0x6ACFC4F:
RTT::extras::ReadOnlyPointer<base::samples::frame::FramePair>::reset(base::samples::frame::FramePair*)
(ReadOnlyPointer.hpp:154)
==1343== by 0x6ACD956: camera_bb2::Task::configureHook() (Task.cpp:38)
==1343== by 0x6E21D92: RTT::base::TaskCore::configure() (in
/media/data/robs/dev/install/lib/liborocos-rtt-gnulinux.so.2.6.0)
==1343== by 0x6AB1C6A: camera_bb2::TaskBase::configure()
(TaskBase.cpp:161)
==1343== by 0xB852E6F:
_0RL_lcfn_10a79cd5b9c0aa8e_60000000(omniCallDescriptor*, omniServant*) (in
/media/data/robs/dev/install/lib/liborocos-rtt-corba-gnulinux.so.2.6.0)
==1343== by 0xBB92380: omniCallHandle::upcall(omniServant*,
omniCallDescriptor&) (in /usr/lib/libomniORB4.so.1.6)
==1343== by 0xB854C12:
RTT::corba::_impl_CTaskContext::_dispatch(omniCallHandle&) (in
/media/data/robs/dev/install/lib/liborocos-rtt-corba-gnulinux.so.2.6.0)
==1343== by 0xBB842DC: omni::omniOrbPOA::dispatch(omniCallHandle&,
omniLocalIdentity*) (in /usr/lib/libomniORB4.so.1.6)
==1343== by 0xBB69247: omniLocalIdentity::dispatch(omniCallHandle&) (in
/usr/lib/libomniORB4.so.1.6)
==1343== by 0xBBACB91: omni::GIOP_S::handleRequest() (in
/usr/lib/libomniORB4.so.1.6)
==1343== by 0xBBAD9CF: omni::GIOP_S::dispatcher() (in
/usr/lib/libomniORB4.so.1.6)
==1343== Address 0x7feffee90 is on thread 1's stack
Note: at the Task.cpp:38 I am doing
"output_frame_pair.reset(&frame_pair);" in the configure hook.
Martin Azkarate
ESA - European Space Agency
Spanish Trainee, TEC-MMA - Automation and Robotics Section
ESTEC - European Space research and TEchnology Centre
Keplerlaan 1, PO Box 299
NL-2200 AG Noordwijk, The Netherlands
Martin.Azkarate at esa.int | www.esa.int
Tel +31 71 565 3480 | Mob +31 650 625 564
From: Alexander Duda <Alexander.Duda at dfki.de>
To: Martin.Azkarate at esa.int
Cc: "rock-dev at dfki.de >> \"rock-dev at dfki.de\"" <rock-dev at dfki.de>
Date: 15/07/2013 18:32
Subject: Re: [Rock-dev] using FramePair structure to output two
frames together
Sent by: rock-dev-bounces at dfki.de
On 07/15/2013 06:19 PM, Martin.Azkarate at esa.int wrote:
Hello there,
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.
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:
*** glibc detected *** /.../orogen_default__Task: free(): invalid pointer
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?
<code>
bool Task::configureHook()
{
if (! TaskBase::configureHook())
return false;
index_frame=0;
base::Time t;
frame_pair.time = t.now(); //! frame_pair is defined
in Task.hpp as a FramePair structure type.
frame_pair.first.init(_width.value(),_height.value(),_channel_data_depth.value(),_output_format.value());
frame_pair.second.init(_width.value(),_height.value(),_channel_data_depth.value(),_output_format.value());
frame_pair.id = 0;
output_frame_pair.reset(&frame_pair);
if (_undistort.value())
{
undistort_image = true;
stereo_calibration = _calibration_parameters;
}
return true;
}
void Task::updateHook()
{
TaskBase::updateHook();
if (_frame_in.read(input_frame)==RTT::NewData)
{
Frame* left = new Frame(input_frame->size.width,
input_frame->size.height, 8, input_frame->frame_mode);
Frame* right = new Frame(input_frame->size.width,
input_frame->size.height, 8, input_frame->frame_mode);
deInterlace(*input_frame,*left,*right);
FramePair* frame_pair_ptr=output_frame_pair.write_access();
if (undistort_image)
{
frame_helper.setCalibrationParameter(stereo_calibration.camLeft);
frame_helper.convert(*left, frame_pair_ptr->first, 0, 0,
frame_helper::INTER_LINEAR, true);
frame_helper.setCalibrationParameter(stereo_calibration.camRight);
frame_helper.convert(*right, frame_pair_ptr->second, 0, 0,
frame_helper::INTER_LINEAR ,true);
}
else
{
frame_helper.convert(*left, frame_pair_ptr->first, 0, 0,
frame_helper::INTER_LINEAR, false);
frame_helper.convert(*right, frame_pair_ptr->second, 0, 0,
frame_helper::INTER_LINEAR, false);
}
frame_pair_ptr->id=index_frame++;
frame_pair_ptr->time = input_frame->time;
output_frame_pair.reset(frame_pair_ptr);
_frame_out.write(output_frame_pair);
}
}
void Task::cleanupHook()
{
TaskBase::cleanupHook();
/// I tried deleting frame_pair and similar things here...
}
</code>
Any ideas about what to put in the cleanupHook or class destructor to
avoid the error at exit?
This should not happen. Use valgrind to find invalid memory access or
multiple deletion of the same object.
Greets Alex
Thanks again for your support,
Martin Azkarate
ESA - European Space Agency
Spanish Trainee, TEC-MMA - Automation and Robotics Section
ESTEC - European Space research and TEchnology Centre
Keplerlaan 1, PO Box 299
NL-2200 AG Noordwijk, The Netherlands
Martin.Azkarate at esa.int | www.esa.int
Tel +31 71 565 3480 | Mob +31 650 625 564
From: Javier Hidalgo Carrió <javier.hidalgo_carrio at dfki.de>
To: Martin.Azkarate at esa.int
Cc: rock-dev at dfki.de
Date: 15/07/2013 09:39
Subject: Re: [Rock-dev] using FramePair structure to output two
frames together
Sent by: rock-dev-bounces at dfki.de
Hello Martin,
Since you have a segmentation fault (Signal 11). Did you debug the code
with gdb looking to the backtrace?
Here it is explained how to do it:
http://rock.opendfki.de/wiki/WikiStart/Troubleshooting/DebuggingTechniques
Nevertheless,:
FramePair* frame_pair;
frame_pair->time=input_frame->time;
To which object is frame_pair pointing to?
Regards,
Javier.
On 07/12/2013 05:14 PM, Martin.Azkarate at esa.int wrote:
Hello,
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:
void Task::updateHook()
{
TaskBase::updateHook();
if (_frame_in.read(input_frame)==RTT::NewData)
{
Frame* left = new Frame(input_frame->size.width,
input_frame->size.height, 8, input_frame->frame_mode);
Frame* right = new Frame(input_frame->size.width,
input_frame->size.height, 8, input_frame->frame_mode);
deInterlace(*input_frame,*left,*right);
Frame* left_gray = new Frame(left->size.width, left->size.height, 8,
MODE_GRAYSCALE);
Frame* right_gray = new Frame(right->size.width, right->size.height,
8, MODE_GRAYSCALE);
frame_helper.convertColor(*left,*left_gray);
frame_helper.convertColor(*right,*right_gray);
frame_left.reset(left_gray);
frame_right.reset(right_gray);
_frame_left.write(frame_left);
_frame_right.write(frame_right);
}
}
void Task::deInterlace(const base::samples::frame::Frame &input,
base::samples::frame::Frame &left, base::samples::frame::Frame &right)
{
//! 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.
//! So in "one pixel" of 16bits of the input frame there are "two
pixels" of 8bits one of each left and right frames.
uint32_t width=(input.size.width*2);
uint32_t height=input.size.height;
int i = (width*height)-1;
int j = ((width*height)>>1)-1;
while (i >= 0) {
right.image[j] = input.image[i--];
left.image[j--] = input.image[i--];
}
left.copyImageIndependantAttributes(input);
right.copyImageIndependantAttributes(input);
}
input_frame, frame_left and frame_right are ReadOnlyPointers of type Frame
defined in Task.hpp. Rest of the Hooks are empty/default.
Question: 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)
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).
Changing the last part of the updateHook to the following:
void Task::updateHook()
{
TaskBase::updateHook();
if (_frame_in.read(input_frame)==RTT::NewData)
{
Frame* left = new Frame(input_frame->size.width,
input_frame->size.height, 8, input_frame->frame_mode);
Frame* right = new Frame(input_frame->size.width,
input_frame->size.height, 8, input_frame->frame_mode);
deInterlace(*input_frame,*left,*right);
Frame* left_gray = new Frame(left->size.width, left->size.height, 8,
MODE_GRAYSCALE);
Frame* right_gray = new Frame(right->size.width, right->size.height,
8, MODE_GRAYSCALE);
frame_helper.convertColor(*left,*left_gray);
frame_helper.convertColor(*right,*right_gray);
FramePair* frame_pair;
frame_pair->id=index_frame++; //! index_frame is defined in Task.hpp
and initialized to 0 in configureHook.
frame_pair->time = input_frame->time;
frame_pair->first = *left_gray;
frame_pair->second = *right_gray;
output_frame_pair.reset(frame_pair); //! output_frame_pair is also a
ReadOnlyPointer in Task.hpp
_frame_out.write(output_frame_pair);
}
}
gives me the following error when I run it: Orocos[WARN]: deployment
[myTaskContext] unexpectedly terminated with signal 11
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:
void Task::updateHook()
{
TaskBase::updateHook();
if (_frame_in.read(input_frame)==RTT::NewData)
{
FramePair* frame_pair;
frame_pair->time=input_frame->time;
frame_pair->id=index_frame++;
frame_pair->first.init(1024,768,8,MODE_GRAYSCALE);
frame_pair->second.init(1024,768,8,MODE_GRAYSCALE);
output_frame_pair.reset(frame_pair);
_frame_out.write(output_frame_pair);
}
}
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.
I make it even simpler:
void Task::updateHook()
{
TaskBase::updateHook();
if (_frame_in.read(input_frame)==RTT::NewData)
{
FramePair* frame_pair;
frame_pair->time=input_frame->time;
frame_pair->id=index_frame++;
output_frame_pair.reset(frame_pair);
_frame_out.write(output_frame_pair);
}
}
I get the same error when exiting the updateHook.
Question: 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?
Thank you very much for your attention,
Martin
Martin Azkarate
ESA - European Space Agency
Spanish Trainee, TEC-MMA - Automation and Robotics Section
ESTEC - European Space research and TEchnology Centre
Keplerlaan 1, PO Box 299
NL-2200 AG Noordwijk, The Netherlands
Martin.Azkarate at esa.int | www.esa.int
Tel +31 71 565 3480 | Mob +31 650 625 564
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.
_______________________________________________
Rock-dev mailing list
Rock-dev at dfki.de
http://www.dfki.de/mailman/cgi-bin/listinfo/rock-dev
_______________________________________________
Rock-dev mailing list
Rock-dev at dfki.de
http://www.dfki.de/mailman/cgi-bin/listinfo/rock-dev
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.
_______________________________________________
Rock-dev mailing list
Rock-dev at dfki.de
http://www.dfki.de/mailman/cgi-bin/listinfo/rock-dev
--
Dipl.-Ing. Alexander Duda
Unterwasserrobotik
DFKI Bremen
Robotics Innovation Center
Robert-Hooke-Straße 5
28359 Bremen, Germany
Phone: +49 (0)421 178-456620
Fax: +49 (0)421 178-454150
E-Mail: alexander.duda at dfki.de
Weitere Informationen: http://www.dfki.de/robotik
-----------------------------------------------------------------------
Deutsches Forschungszentrum fuer Kuenstliche Intelligenz GmbH
Firmensitz: Trippstadter Straße 122, D-67663 Kaiserslautern
Geschaeftsfuehrung: Prof. Dr. Dr. h.c. mult. Wolfgang Wahlster
(Vorsitzender) Dr. Walter Olthoff
Vorsitzender des Aufsichtsrats: Prof. Dr. h.c. Hans A. Aukes
Amtsgericht Kaiserslautern, HRB 2313
Sitz der Gesellschaft: Kaiserslautern (HRB 2313)
USt-Id.Nr.: DE 148646973
Steuernummer: 19/673/0060/3
_______________________________________________
Rock-dev mailing list
Rock-dev at dfki.de
http://www.dfki.de/mailman/cgi-bin/listinfo/rock-dev
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.dfki.de/pipermail/rock-dev/attachments/20130715/342d2d58/attachment-0001.htm
More information about the Rock-dev
mailing list