Thursday, 15 January 2015

c++ - use boost::boyer_moore with boost::gil -



c++ - use boost::boyer_moore with boost::gil -

i want search little image big one, algorithm is:

search first line if first line matches, compare rest

i want utilize boost::algorithm::boyer_moore line searching, works fine std::string:

#include <string> using namespace std; #include "boost/algorithm/searching/boyer_moore.hpp" using namespace boost::algorithm; int main() { string s; boyer_moore<string::iterator> bm(s.begin(), s.end()); // compiles }

the code compiles, 1 not:

#include "boost/mpl/vector.hpp" using namespace boost; #include "boost/gil/gil_all.hpp" using namespace boost::gil; #include "boost/algorithm/searching/boyer_moore.hpp" using namespace boost::algorithm; int main() { typedef rgba8_image_t image_t; typedef image_t::view_t view_t; view_t vw; boyer_moore<view_t::x_iterator> bm(vw.row_begin(0), vw.row_end(0)); // compile error }

both of them iterators, what's wrong sec one?

thanks.

according docs algorithm uses auxiliary info construction called skip_table. default (when value_type of iterator not char or unsigned char) table uses tr1::unordered_map, , requires gil::pixel hash-able. have 2 options: either alter default skip_table specializing bm_traits iterator (this sadly undocumented), or create gil::pixel hash-able. latter can create std::size_t hash_value(pixel<channelvalue,layout> const& val) within namespace boost::gil. next compiles g++ 4.9.0 , visual studio 2013 (and nothing):

#include <boost/functional/hash.hpp> //added #include <boost/mpl/vector.hpp> #include <boost/gil/gil_all.hpp> #include <boost/algorithm/searching/boyer_moore.hpp> using namespace boost; using namespace boost::gil; using namespace boost::algorithm; namespace boost { namespace gil { template <typename channelvalue, typename layout> std::size_t hash_value(pixel<channelvalue, layout> const& b) { std::size_t seed = 0; (int c = 0; c<num_channels<pixel<channelvalue, layout> >::value; ++c) hash_combine(seed, b[c]); homecoming seed; } } } namespace std { //added template <typename channelvalue, typename layout> struct hash<boost::gil::pixel<channelvalue,layout> > { size_t operator ()(boost::gil::pixel<channelvalue, layout> const& value) const { homecoming hash_value(value); } }; } int main() { typedef rgba8_image_t image_t; typedef image_t::view_t view_t; view_t vw; boyer_moore<view_t::x_iterator> bm(vw.row_begin(0), vw.row_end(0)); // compile error }

c++ boost boost-gil boyer-moore

No comments:

Post a Comment