当前位置: 首页>>代码示例>>C++>>正文


C++ ImageEncoder::encode方法代码示例

本文整理汇总了C++中ImageEncoder::encode方法的典型用法代码示例。如果您正苦于以下问题:C++ ImageEncoder::encode方法的具体用法?C++ ImageEncoder::encode怎么用?C++ ImageEncoder::encode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ImageEncoder的用法示例。


在下文中一共展示了ImageEncoder::encode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char const* argv[]) {
    string address;
    string port;
    int threads = 1;
    fs::path db_path;

    namespace po = boost::program_options;
    po::options_description desc("Allowed options");
    desc.add_options()
        ("help,h", "produce help message.")
        ("address", po::value(&address)->default_value("0.0.0.0"), "")
        ("port", po::value(&port)->default_value("18888"), "")
        ("db", po::value(&db_path), "")
        ;

    po::positional_options_description p;
    p.add("db", 1);

    po::variables_map vm;
    po::store(po::command_line_parser(argc, argv).
                     options(desc).positional(p).run(), vm);
    po::notify(vm);

    if (vm.count("help") || db_path.empty()) {
        cout << "Usage:" << endl;
        cout << "\tserver ... <db>" << endl;
        cout << desc;
        cout << endl;
        return 0;
    }

    // Create a multiplexer for handling requests
    served::multiplexer mux;

    picpac::IndexedFileReader db(db_path);
    default_random_engine rng;

    magic_t cookie = magic_open(MAGIC_MIME_TYPE);
    CHECK(cookie);
    magic_load(cookie, NULL);

    // GET /hello
    mux.handle("/l")
        .get(no_throw([&db, &cookie](served::response &res, const served::request &req) {
            rfc3986::Form query(req.url().query());
            rfc3986::Form trans;
            // transfer all applicable image parameters to trans
            // so we can later use that for image display
#define PICPAC_CONFIG_UPDATE(C,P) \
            { auto it = query.find(#P); if (it != query.end()) trans.insert(*it);}
            PICPAC_CONFIG_UPDATE_ALL(0);
#undef PICPAC_CONFIG_UPDATE
            string ext = trans.encode(true);
            int count = query.get<int>("count", 20);
            string anno = query.get<string>("anno", "");
            res << "<html><body><table><tr><th>Image</th></tr>";
            for (unsigned i = 0; i < count; ++i) {
                int id = rand() % db.size();
                res << "<tr><td><img src=\"/image?id="
                    << lexical_cast<string>(id) << ext
                    << "\"></img></td></tr>";
            }
            res << "</table></body></html>";
        }));
    mux.handle("/file")
        .get(no_throw([&db, &cookie](served::response &res, const served::request &req) {
            rfc3986::Form query(req.url().query());
            int id = lexical_cast<int>(query["id"]);
            Record rec;
            db.read(id, &rec);
            string buf = rec.field_string(0);
            char const *mime = magic_buffer(cookie, &buf[0], buf.size());
            res.set_header("Content-Type", mime);
            res.set_body(buf);
        }));
    mux.handle("/image")
        .get(no_throw([&db, &rng](served::response &res, const served::request &req) {
            rfc3986::Form query(req.url().query());
            PICPAC_CONFIG conf;
            conf.anno_color3 = 255;
            conf.anno_copy = true;
            conf.anno_thickness = 2;
            conf.pert_color1 = 20;
            conf.pert_color2 = 20;
            conf.pert_color3 = 20;
            conf.pert_angle = 20;
            conf.pert_min_scale = 0.8;
            conf.pert_max_scale = 1.2;
#define PICPAC_CONFIG_UPDATE(C,P) C.P = query.get<decltype(C.P)>(#P, C.P)
            PICPAC_CONFIG_UPDATE_ALL(conf);
#undef PICPAC_CONFIG_UPDATE
            ImageLoader loader(conf);
            ImageLoader::PerturbVector pv;
            int id = query.get<int>("id", rng() % db.size());
            ImageLoader::Value v;
            loader.sample(rng, &pv);
            loader.load([&db, id](Record *r){db.read(id, r);}, pv, &v);
            ImageEncoder encoder;
            string buf;
            cv::Mat image = v.image;
//.........这里部分代码省略.........
开发者ID:RobeDM,项目名称:picpac,代码行数:101,代码来源:picpac-server.cpp


注:本文中的ImageEncoder::encode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。