[boost::gil] Type conversion in Generic Image Library
Hello, I'm a newbie in this library and I feel a little bit lost. I have the following problem: I currently have an image of the type ` boost::gil::rgb8c_view_t`. I need to pass it to a function (from a code I don't mantain) with this prototype: void function(const boost::gil::rgb8c_view_t& input, const int index, const boost::gil::rgb8c_view_t::view_t &output) I have created an output image by using the following syntax: boost::gil::rgb8c_view_t::view_t output(input._dynamic_cast<boost::gil::rgb8c_view_t::view_t>()); At this point, the compiler accepts the image output as input for the function. However, I need the image back to the `boost::gil::rgb8c_view_t` type. The question is: - Is it a correct way to allocate the image output? - How do I transform it back to the type boost::gil::rgb8c_view_t? Thank you in advance, Néstor
Hi Néstor, Nestor Morales Hernández wrote:
I currently have an image of the type ` boost::gil::rgb8c_view_t`. I need to pass it to a function (from a code I don't mantain) with this prototype:
void function(const boost::gil::rgb8c_view_t& input, const int index, const boost::gil::rgb8c_view_t::view_t &output)
I have created an output image by using the following syntax:
boost::gil::rgb8c_view_t::view_t output(input._dynamic_cast<boost::gil::rgb8c_view_t::view_t>());
At this point, the compiler accepts the image output as input for the function. However, I need the image back to the `boost::gil::rgb8c_view_t` type. The question is:
- Is it a correct way to allocate the image output? - How do I transform it back to the type boost::gil::rgb8c_view_t?
I'm having trouble parsing your syntax here. It looks like input is not really an rgb8c_view_t, rather its an any_image type. If it were the gil-specified typedef, there wouldn't be a _dynamic_cast member. Likewise output appears to be the same, with a nested view_t typedef. Are you saying that function is the prototype over which you have no control? It seems odd that it would have an output view which has immutable pixels (due to the 'c' in rgb8c) and which could not itself be swapped out for a different view (due to the fact that it's a view passed by const reference). I'm hoping there's been some mistake in copying pieces of your code into this email, otherwise there's only bad solutions to what you describe. HTH, Nate
Ok, I tried to change typedefs to make things more clear, but I guess I have had a mess. I will try to explain it again: I am trying to use the class CpuPreprocessor publicly available here: https://bitbucket.org/rodrigob/doppia/src/8b784ff23eeab329d02ebe2eb1bc4775e2... To do so, I create a shared pointer pointing to an object of the class: shared_ptr<CpuPreprocessor> homography_rectifier_p; homography_rectifier_p.reset(new CpuPreprocessor(video_input_p->get_left_image().dimensions(), video_input_p->get_stereo_calibration(), options)); Then, I try to execute the `run` method of the class CpuPreprocessor, which has the prototype: void run(const AbstractPreprocessor::input_image_view_t& input, const int camera_index, const AbstractPreprocessor::output_image_view_t &output); // I get the input images AbstractStereoMatcher::input_image_view_t input_left_view(video_input_p->get_left_image()), input_right_view(video_input_p->get_right_image()); // And then I try to put them as input of the run function, doing the same process followed in https://bitbucket.org/rodrigob/doppia/src/8b784ff23eeab329d02ebe2eb1bc4775e2... AbstractVideoInput::input_image_t rectified_left_view(input_left_view._dynamic_cast<AbstractVideoInput::input_image_t>()), rectified_right_view(input_right_view._dynamic_cast<AbstractVideoInput::input_image_t>()); homography_rectifier_p->run(input_left_view, 0, boost::gil::view(rectified_left_view)); // The ouput of the compiler is the following: /home/nestor/Dropbox/KULeuven/projects/doppia/src/applications/stixel_world_improved/StixelWorldApplication.cpp:296:102: required from here /home/nestor/Dropbox/KULeuven/projects/doppia/libs/boost/gil/image_view.hpp:101:143: error: ‘const class boost::gil::any_image_view<boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<const boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t> > >*> > >, boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<const boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t> > >*> > >, boost::mpl::vector0<mpl_::na>, 0>, 0> >’ has no member named ‘pixels’ make[2]: *** [CMakeFiles/stixel_world.dir/StixelWorldApplication.cpp.o] Error 1 // Finally, the typedefs for the types of the variables used in this post are the following: //From https://bitbucket.org/rodrigob/doppia/src/8b784ff23eeab329d02ebe2eb1bc4775e2... typedef AbstractVideoInput::input_image_view_t input_image_view_t; typedef AbstractVideoInput::input_image_t::view_t output_image_view_t; typedef AbstractVideoInput::input_image_view_t::point_t dimensions_t; //From https://bitbucket.org/rodrigob/doppia/src/8b784ff23eeab329d02ebe2eb1bc4775e2... /// input image are either rgb8 or gray8 typedef boost::mpl::vector<boost::gil::gray8_image_t, boost::gil::rgb8_image_t> input_images_t; // FIXME some applications may need float instead of bits8 typedef boost::gil::gray8_image_t disparity_map_t; //From https://bitbucket.org/rodrigob/doppia/src/8b784ff23eeab329d02ebe2eb1bc4775e2... typedef boost::gil::rgb8_image_t input_image_t; typedef boost::gil::rgb8c_view_t input_image_view_t; typedef input_image_view_t::point_t dimensions_t; I hope somebody can help me with that. As I said, I'm new on using Boost Generic Image Library and it is driving me crazy. Thank you in advance, best regards. Néstor 2013/8/1 Nathan Crookston <nathan.crookston@gmail.com>
Hi Néstor,
Nestor Morales Hernández wrote:
I currently have an image of the type ` boost::gil::rgb8c_view_t`. I need to pass it to a function (from a code I don't mantain) with this prototype:
void function(const boost::gil::rgb8c_view_t& input, const int index, const boost::gil::rgb8c_view_t::view_t &output)
I have created an output image by using the following syntax:
boost::gil::rgb8c_view_t::view_t output(input._dynamic_cast<boost::gil::rgb8c_view_t::view_t>());
At this point, the compiler accepts the image output as input for the function. However, I need the image back to the `boost::gil::rgb8c_view_t` type. The question is:
- Is it a correct way to allocate the image output? - How do I transform it back to the type boost::gil::rgb8c_view_t?
I'm having trouble parsing your syntax here. It looks like input is not really an rgb8c_view_t, rather its an any_image type. If it were the gil-specified typedef, there wouldn't be a _dynamic_cast member. Likewise output appears to be the same, with a nested view_t typedef.
Are you saying that function is the prototype over which you have no control? It seems odd that it would have an output view which has immutable pixels (due to the 'c' in rgb8c) and which could not itself be swapped out for a different view (due to the fact that it's a view passed by const reference).
I'm hoping there's been some mistake in copying pieces of your code into this email, otherwise there's only bad solutions to what you describe.
HTH, Nate
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Néstor Morales Hernández Departamento ISAATC, Universidad de La Laguna e-mail: nestor@isaatc.ull.es Phone: (+34) 922 318 287
Hi Néstor, Nestor Morales Hernández wrote:
// I get the input images AbstractStereoMatcher::input_image_view_t input_left_view(video_input_p->get_left_image()), input_right_view(video_input_p->get_right_image());
AbstractVideoInput::input_image_t
rectified_left_view(input_left_view._dynamic_cast<AbstractVideoInput::input_image_t>()),
rectified_right_view(input_right_view._dynamic_cast<AbstractVideoInput::input_image_t>());
homography_rectifier_p->run(input_left_view, 0, boost::gil::view(rectified_left_view));
Note that AbstractStereoMatcher::input_image_view_t and
AbstractVideoInput::input_image_t are different types. The former is an any_image_view of const data, while the latter is an rgb8_image_t.
// The ouput of the compiler is the following: /home/nestor/Dropbox/KULeuven/projects/doppia/src/applications/stixel_world_improved/StixelWorldApplication.cpp:296:102: required from here /home/nestor/Dropbox/KULeuven/projects/doppia/libs/boost/gil/image_view.hpp:101:143: error: ‘const class boost::gil::any_image_view<boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<const boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t> > >*> > >, boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<const boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t> > >*> > >, boost::mpl::vector0<mpl_::na>, 0>, 0> >’ has no member named ‘pixels’ make[2]: *** [CMakeFiles/stixel_world.dir/StixelWorldApplication.cpp.o] Error 1
You can edit the message down to this: StixelWorldApplication.cpp:296 error: ‘const class boost::gil::any_image_view</*unintelligible template gobbledygook*/>’ has no member named ‘pixels’ Which is true. It looks like you're passing input_left_view, of any_image_view type, into run, which expects rgb8c_view_t. Perhaps you need to use rectified_left_view (which isn't really a view) in conjunction with gil::view() (which will retrieve a view from the image).
I hope somebody can help me with that. As I said, I'm new on using Boost Generic Image Library and it is driving me crazy.
I can sympathize -- it's pretty easy to do basic things with GIL, and GIL allows you to do very complex things elegantly, but there can be a steep learning curve in between. HTH, Nate
Hi Nestor, I think I have overlooked your original message. Sorry for that. On Mon, Jul 29, 2013 at 5:19 AM, Nestor Morales Hernández < nestor@isaatc.ull.es> wrote:
Hello,
I'm a newbie in this library and I feel a little bit lost. I have the following problem:
I currently have an image of the type ` boost::gil::rgb8c_view_t`. I need to pass it to a function (from a code I don't mantain) with this prototype:
I'm assuming you know the difference between a rgb8_image_t and rgb8_view_t. If not let me know.
void function(const boost::gil::rgb8c_view_t& input, const int index, const boost::gil::rgb8c_view_t::view_t &output)
I have created an output image by using the following syntax:
boost::gil::rgb8c_view_t::view_t output(input._dynamic_cast<boost::gil::rgb8c_view_t::view_t>());
There is no view_t in rgb8c_view_t. Just use rgb8c_view_t. Also, do you know why you use a gil::any_image? I mean do you really need that? Regards, Christian
participants (3)
-
Christian Henning
-
Nathan Crookston
-
Nestor Morales Hernández