Commit d12a249b0ed7f11d1771644c8ea2f338501a2117
1 parent
c08a0136
added br-select and br-print, fixed json formatting
Showing
8 changed files
with
128 additions
and
12 deletions
app/CMakeLists.txt
app/br-crawl/br-crawl.cpp
| ... | ... | @@ -72,7 +72,7 @@ static void crawl(QFileInfo url, int currentDepth = 0) |
| 72 | 72 | } else if (url.isFile()) { |
| 73 | 73 | const QString suffix = url.suffix(); |
| 74 | 74 | if ((suffix == "bmp") || (suffix == "jpg") || (suffix == "jpeg") || (suffix == "png") || (suffix == "tiff")) { |
| 75 | - printf(json ? "{ URL = \"file://%s\" }\n" : "file://%s\n", qPrintable(url.canonicalFilePath())); | |
| 75 | + printf(json ? "{ \"URL\" : \"file://%s\" }\n" : "file://%s\n", qPrintable(url.canonicalFilePath())); | |
| 76 | 76 | fflush(stdout); |
| 77 | 77 | currentImages++; |
| 78 | 78 | } | ... | ... |
app/br-download/br-download.cpp
| ... | ... | @@ -111,11 +111,18 @@ int main(int argc, char *argv[]) |
| 111 | 111 | QFile file; |
| 112 | 112 | file.open(stdin, QFile::ReadOnly); |
| 113 | 113 | while (!file.atEnd()) { |
| 114 | - const QByteArray line = file.readLine(); | |
| 115 | - process(json ? QJsonDocument::fromJson(line).object().value("URL").toString() | |
| 116 | - : QString::fromLocal8Bit(line), | |
| 117 | - json ? line.simplified() : QByteArray(), | |
| 114 | + const QByteArray line = file.readLine().simplified(); | |
| 115 | + if (line.isEmpty()) | |
| 116 | + continue; | |
| 117 | + | |
| 118 | + QJsonParseError error; | |
| 119 | + process(json ? QJsonDocument::fromJson(line, &error).object().value("URL").toString() | |
| 120 | + : QString::fromLatin1(line), | |
| 121 | + json ? line : QByteArray(), | |
| 118 | 122 | nam); |
| 123 | + | |
| 124 | + if (error.error != QJsonParseError::NoError) | |
| 125 | + qDebug() << error.errorString(); | |
| 119 | 126 | } |
| 120 | 127 | } |
| 121 | 128 | ... | ... |
app/br-print/CMakeLists.txt
0 → 100644
app/br-print/br-print.cpp
0 → 100644
| 1 | +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | |
| 2 | + * Copyright 2014 Noblis * | |
| 3 | + * * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); * | |
| 5 | + * you may not use this file except in compliance with the License. * | |
| 6 | + * You may obtain a copy of the License at * | |
| 7 | + * * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 * | |
| 9 | + * * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software * | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, * | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * | |
| 13 | + * See the License for the specific language governing permissions and * | |
| 14 | + * limitations under the License. * | |
| 15 | + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | |
| 16 | + | |
| 17 | +#include <cstdlib> | |
| 18 | +#include <cstring> | |
| 19 | +#include <openbr/universal_template.h> | |
| 20 | + | |
| 21 | +static void help() | |
| 22 | +{ | |
| 23 | + printf("br-print [args]\n" | |
| 24 | + "================\n" | |
| 25 | + "* __stdin__ - Templates\n" | |
| 26 | + "* __stdout__ - Template _data_\n" | |
| 27 | + "\n" | |
| 28 | + "_br-print_ extracts template data.\n"); | |
| 29 | +} | |
| 30 | + | |
| 31 | +static void print_utemplate(br_const_utemplate utemplate, br_callback_context) | |
| 32 | +{ | |
| 33 | + fwrite(utemplate->data, 1, utemplate->size, stdout); | |
| 34 | + printf("\n"); | |
| 35 | +} | |
| 36 | + | |
| 37 | +int main(int argc, char *argv[]) | |
| 38 | +{ | |
| 39 | + for (int i=1; i<argc; i++) | |
| 40 | + if (!strcmp(argv[i], "-help")) { help(); exit(EXIT_SUCCESS); } | |
| 41 | + | |
| 42 | + br_iterate_utemplates_file(stdin, print_utemplate, NULL); | |
| 43 | + return EXIT_SUCCESS; | |
| 44 | +} | ... | ... |
app/br-search/br-search.cpp
| ... | ... | @@ -90,20 +90,21 @@ struct SearchResults |
| 90 | 90 | { |
| 91 | 91 | sort_heap(topTargets.begin(), topTargets.end()); |
| 92 | 92 | |
| 93 | - cout << "{ \"AlgorithmID\"=" << query->algorithmID; | |
| 94 | - cout << ", \"QueryImageID\"="; | |
| 93 | + cout << "{ \"AlgorithmID\":\"" << query->algorithmID; | |
| 94 | + cout << "\", \"QueryImageID\":\""; | |
| 95 | 95 | writeMD5asHex(query->imageID); |
| 96 | - cout << ", \"QueryTemplateID\"="; | |
| 96 | + cout << "\", \"QueryTemplateID\":\""; | |
| 97 | 97 | writeMD5asHex(query->templateID); |
| 98 | + cout << "\""; | |
| 98 | 99 | printMetadata(query); |
| 99 | - cout << ", \"Targets\"=[ "; | |
| 100 | + cout << ", \"Targets\":[ "; | |
| 100 | 101 | for (int i=topTargets.size()-1; i>=0; i--) { |
| 101 | 102 | Target &target = topTargets[i]; |
| 102 | - cout << "{ \"ImageID\"="; | |
| 103 | + cout << "{ \"ImageID\":\""; | |
| 103 | 104 | writeMD5asHex(target.second->imageID); |
| 104 | - cout << ", \"TemplateID\"="; | |
| 105 | + cout << "\", \"TemplateID\":\""; | |
| 105 | 106 | writeMD5asHex(target.second->templateID); |
| 106 | - cout << ", \"Score\"=" << target.first; | |
| 107 | + cout << "\", \"Score\":" << target.first; | |
| 107 | 108 | printMetadata(target.second); |
| 108 | 109 | cout << " }"; |
| 109 | 110 | if (i > 0) | ... | ... |
app/br-select/CMakeLists.txt
0 → 100644
app/br-select/br-select.cpp
0 → 100644
| 1 | +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | |
| 2 | + * Copyright 2014 Noblis * | |
| 3 | + * * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); * | |
| 5 | + * you may not use this file except in compliance with the License. * | |
| 6 | + * You may obtain a copy of the License at * | |
| 7 | + * * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 * | |
| 9 | + * * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software * | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, * | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * | |
| 13 | + * See the License for the specific language governing permissions and * | |
| 14 | + * limitations under the License. * | |
| 15 | + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | |
| 16 | + | |
| 17 | +#include <cstdlib> | |
| 18 | +#include <cstring> | |
| 19 | +#include <openbr/universal_template.h> | |
| 20 | + | |
| 21 | +static void help() | |
| 22 | +{ | |
| 23 | + printf("br-select [args]\n" | |
| 24 | + "================\n" | |
| 25 | + "* __stdin__ - Templates\n" | |
| 26 | + "* __stdout__ - Templates\n" | |
| 27 | + "\n" | |
| 28 | + "_br-select_ filters templates templates.\n" | |
| 29 | + "\n" | |
| 30 | + "Optional Arguments\n" | |
| 31 | + "------------------\n" | |
| 32 | + "* -algorithmID <int> - Allow a specific algorithmID\n"); | |
| 33 | +} | |
| 34 | + | |
| 35 | +static int *algorithmID = NULL; | |
| 36 | + | |
| 37 | +static void select_utemplate(br_const_utemplate utemplate, br_callback_context) | |
| 38 | +{ | |
| 39 | + if (algorithmID && utemplate->algorithmID != *algorithmID) | |
| 40 | + return; | |
| 41 | + | |
| 42 | + br_append_utemplate(stdout, utemplate); | |
| 43 | +} | |
| 44 | + | |
| 45 | +int main(int argc, char *argv[]) | |
| 46 | +{ | |
| 47 | + for (int i=1; i<argc; i++) { | |
| 48 | + if (!strcmp(argv[i], "-help")) { help(); exit(EXIT_SUCCESS); } | |
| 49 | + else if (!strcmp(argv[i], "-algorithmID")) algorithmID = new int(atoi(argv[++i])); | |
| 50 | + } | |
| 51 | + | |
| 52 | + br_iterate_utemplates_file(stdin, select_utemplate, NULL); | |
| 53 | + return EXIT_SUCCESS; | |
| 54 | +} | ... | ... |