C++ 将boost::boyer_moore与boost::gil一起使用
我想从大图像中搜索小图像,我的算法是:C++ 将boost::boyer_moore与boost::gil一起使用,c++,boost,boost-gil,boyer-moore,C++,Boost,Boost Gil,Boyer Moore,我想从大图像中搜索小图像,我的算法是: 搜索第一行 如果第一行匹配,则比较其余行 我想使用boost::algorithm::boyer_moore来进行行搜索,它可以与std::string配合使用: #include <string> using namespace std; #include "boost/algorithm/searching/boyer_moore.hpp" using namespace boost::algorithm; int main() {
#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()); // it compiles
}
#包括
使用名称空间std;
#包括“boost/algorithm/search/boyer_moore.hpp”
使用名称空间boost::算法;
int main(){
字符串s;
boyer_moore bm(s.begin(),s.end());//它编译
}
代码可以编译,但此代码不能:
#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
}
#包括“boost/mpl/vector.hpp”
使用名称空间boost;
#包括“boost/gil/gil_all.hpp”
使用名称空间boost::gil;
#包括“boost/algorithm/search/boyer_moore.hpp”
使用名称空间boost::算法;
int main(){
typedef rgba8_image_t image_t;
typedef image_t::view_t view_t;
大众观点;
boyer_moore bm(vw.row_begin(0),vw.row_end(0));//编译错误
}
它们都是迭代器,第二个有什么问题
谢谢。根据算法,该算法使用一种称为跳过表的辅助数据结构。默认情况下(当迭代器的value\u type
不是字符或无符号字符时),此表使用tr1::无序\u映射
,这要求gil::pixel
可以散列。因此,您有两个选择:要么通过专门化迭代器来更改默认的skip_表(遗憾的是,这没有文档记录),要么使gil::pixel
hash成为可能。对于后者,您可以在名称空间boost::gil
内创建std::size\t hash_值(pixel const&val)
。使用g++4.9.0和Visual Studio 2013(不执行任何操作)执行以下操作:
#包括//已添加
#包括
#包括
#包括
使用名称空间boost;
使用名称空间boost::gil;
使用名称空间boost::算法;
名称空间提升{
名称空间gil
{
模板
标准::大小\u t散列值(像素常量和b)
{
std::size\u t seed=0;
对于(int c=0;cThanks,但是代码仍然没有用vs2010编译,以下是输出:下面是我编辑的代码。它现在也可以用vs2013编译,希望它也能为你工作。适用于vs2013。谢谢。在包含它们之前使用名称空间扭曲包含是非常罕见的,尤其是在TMP密集的库中顺便说一句,标签与Boost.GIL无关。您需要的标签是。您应该更改它,以最大限度地提高您的问题到达库中专家的概率。
#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;
for (int c = 0; c<num_channels<pixel<ChannelValue, Layout> >::value; ++c)
hash_combine(seed, b[c]);
return 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 {
return 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
}