Commit d12a249b0ed7f11d1771644c8ea2f338501a2117

Authored by Josh Klontz
1 parent c08a0136

added br-select and br-print, fixed json formatting

app/CMakeLists.txt
@@ -10,5 +10,7 @@ if(NOT ${BR_EMBEDDED}) @@ -10,5 +10,7 @@ if(NOT ${BR_EMBEDDED})
10 add_subdirectory(br-crawl) 10 add_subdirectory(br-crawl)
11 add_subdirectory(br-enroll) 11 add_subdirectory(br-enroll)
12 add_subdirectory(br-gui) 12 add_subdirectory(br-gui)
  13 + add_subdirectory(br-print)
13 add_subdirectory(br-search) 14 add_subdirectory(br-search)
  15 + add_subdirectory(br-select)
14 endif() 16 endif()
app/br-crawl/br-crawl.cpp
@@ -72,7 +72,7 @@ static void crawl(QFileInfo url, int currentDepth = 0) @@ -72,7 +72,7 @@ static void crawl(QFileInfo url, int currentDepth = 0)
72 } else if (url.isFile()) { 72 } else if (url.isFile()) {
73 const QString suffix = url.suffix(); 73 const QString suffix = url.suffix();
74 if ((suffix == "bmp") || (suffix == "jpg") || (suffix == "jpeg") || (suffix == "png") || (suffix == "tiff")) { 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 fflush(stdout); 76 fflush(stdout);
77 currentImages++; 77 currentImages++;
78 } 78 }
app/br-download/br-download.cpp
@@ -111,11 +111,18 @@ int main(int argc, char *argv[]) @@ -111,11 +111,18 @@ int main(int argc, char *argv[])
111 QFile file; 111 QFile file;
112 file.open(stdin, QFile::ReadOnly); 112 file.open(stdin, QFile::ReadOnly);
113 while (!file.atEnd()) { 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 nam); 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
  1 +add_executable(br-print br-print.cpp ${BR_RESOURCES})
  2 +target_link_libraries(br-print openbr ${BR_THIRDPARTY_LIBS})
  3 +qt5_use_modules(br-print ${QT_DEPENDENCIES})
  4 +install(TARGETS br-print RUNTIME DESTINATION bin)
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,20 +90,21 @@ struct SearchResults
90 { 90 {
91 sort_heap(topTargets.begin(), topTargets.end()); 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 writeMD5asHex(query->imageID); 95 writeMD5asHex(query->imageID);
96 - cout << ", \"QueryTemplateID\"="; 96 + cout << "\", \"QueryTemplateID\":\"";
97 writeMD5asHex(query->templateID); 97 writeMD5asHex(query->templateID);
  98 + cout << "\"";
98 printMetadata(query); 99 printMetadata(query);
99 - cout << ", \"Targets\"=[ "; 100 + cout << ", \"Targets\":[ ";
100 for (int i=topTargets.size()-1; i>=0; i--) { 101 for (int i=topTargets.size()-1; i>=0; i--) {
101 Target &target = topTargets[i]; 102 Target &target = topTargets[i];
102 - cout << "{ \"ImageID\"="; 103 + cout << "{ \"ImageID\":\"";
103 writeMD5asHex(target.second->imageID); 104 writeMD5asHex(target.second->imageID);
104 - cout << ", \"TemplateID\"="; 105 + cout << "\", \"TemplateID\":\"";
105 writeMD5asHex(target.second->templateID); 106 writeMD5asHex(target.second->templateID);
106 - cout << ", \"Score\"=" << target.first; 107 + cout << "\", \"Score\":" << target.first;
107 printMetadata(target.second); 108 printMetadata(target.second);
108 cout << " }"; 109 cout << " }";
109 if (i > 0) 110 if (i > 0)
app/br-select/CMakeLists.txt 0 → 100644
  1 +add_executable(br-select br-select.cpp ${BR_RESOURCES})
  2 +target_link_libraries(br-select openbr ${BR_THIRDPARTY_LIBS})
  3 +qt5_use_modules(br-select ${QT_DEPENDENCIES})
  4 +install(TARGETS br-select RUNTIME DESTINATION bin)
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 +}