Commit ff0faec57142eb03a5bcc956e640ad7741c28286

Authored by Josh Klontz
1 parent 586222fa

deprecated br-download in favor of DownloadTransform

app/CMakeLists.txt
@@ -6,7 +6,6 @@ add_subdirectory(examples) @@ -6,7 +6,6 @@ add_subdirectory(examples)
6 6
7 # Build additional OpenBR utilities 7 # Build additional OpenBR utilities
8 if(NOT ${BR_EMBEDDED}) 8 if(NOT ${BR_EMBEDDED})
9 - add_subdirectory(br-download)  
10 add_subdirectory(br-crawl) 9 add_subdirectory(br-crawl)
11 add_subdirectory(br-gui) 10 add_subdirectory(br-gui)
12 add_subdirectory(br-search) 11 add_subdirectory(br-search)
app/br-download/CMakeLists.txt deleted
1 -add_executable(br-download br-download.cpp ${BR_RESOURCES})  
2 -target_link_libraries(br-download openbr ${BR_THIRDPARTY_LIBS})  
3 -qt5_use_modules(br-download ${QT_DEPENDENCIES})  
4 -install(TARGETS br-download RUNTIME DESTINATION bin)  
app/br-download/br-download.cpp deleted
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 <QtCore>  
18 -#include <QtNetwork>  
19 -#include <opencv2/highgui/highgui.hpp>  
20 -#include <cstdio>  
21 -#include <cstring>  
22 -#include <string>  
23 -#include <openbr/universal_template.h>  
24 -  
25 -using namespace cv;  
26 -using namespace std;  
27 -  
28 -static void help()  
29 -{  
30 - printf("br-download [URL] [args]\n"  
31 - "========================\n"  
32 - "* __stdin__ - URLs/JSON\n"  
33 - "* __stdout__ - Templates (raw data)\n"  
34 - "\n"  
35 - "_br-download_ retrieves and verifies the contents of an image URL.\n"  
36 - "If no URL is provided, download reads newline-separated image URLs from _stdin_.\n"  
37 - "Download writes templates containing the contents of the URL to _stdout_.\n"  
38 - "\n"  
39 - "Download is expected to filter out URLs that are not valid images.\n"  
40 - "Download may do this by checking the file header or decoding the file.\n"  
41 - "\n"  
42 - "Optional Arguments\n"  
43 - "------------------\n"  
44 - "* -help - Print usage information.\n"  
45 - "* -json - Input JSON instead of URLs.\n"  
46 - "* -permissive - Do not attempt to verify the contents of an image URL (verify otherwise).\n");  
47 -}  
48 -  
49 -static bool json = false;  
50 -static bool permissive = false;  
51 -static bool url_provided = false;  
52 -  
53 -static void process(QString url, const QByteArray &metadata, QNetworkAccessManager &nam)  
54 -{  
55 - url = url.simplified();  
56 - if (url.isEmpty())  
57 - return;  
58 -  
59 - if (url.startsWith("file://"))  
60 - url = url.mid(7);  
61 -  
62 - QIODevice *device = NULL;  
63 - if (QFileInfo(url).exists()) {  
64 - device = new QFile(url);  
65 - device->open(QIODevice::ReadOnly);  
66 - } else {  
67 - QNetworkReply *reply = nam.get(QNetworkRequest(url));  
68 - while (!reply->isFinished())  
69 - QCoreApplication::processEvents();  
70 -  
71 - if (reply->error() != QNetworkReply::NoError) {  
72 - qDebug() << reply->errorString() << url;  
73 - reply->deleteLater();  
74 - } else {  
75 - device = reply;  
76 - }  
77 - }  
78 -  
79 - if (!device)  
80 - return;  
81 -  
82 - const QByteArray data = device->readAll();  
83 - delete device;  
84 - device = NULL;  
85 -  
86 - if (!permissive && imdecode(Mat(1, data.size(), CV_8UC1, (void*)data.data()), IMREAD_ANYDEPTH | IMREAD_ANYCOLOR).empty())  
87 - return;  
88 -  
89 - const QByteArray hash = QCryptographicHash::hash(data, QCryptographicHash::Md5);  
90 - br_append_utemplate_contents(stdout, reinterpret_cast<const unsigned char*>(hash.data()), reinterpret_cast<const unsigned char*>(hash.data()), 3, data.size(), reinterpret_cast<const unsigned char*>(data.data()));  
91 -  
92 - if (!metadata.isEmpty()) {  
93 - const QByteArray metadataHash = QCryptographicHash::hash(metadata, QCryptographicHash::Md5);  
94 - br_append_utemplate_contents(stdout, reinterpret_cast<const unsigned char*>(hash.data()), reinterpret_cast<const unsigned char*>(metadataHash.data()), 2, metadata.size() + 1 /* include null terminator */, reinterpret_cast<const unsigned char*>(metadata.data()));  
95 - }  
96 -}  
97 -  
98 -int main(int argc, char *argv[])  
99 -{  
100 - QCoreApplication application(argc, argv);  
101 - QNetworkAccessManager nam;  
102 -  
103 - for (int i=1; i<argc; i++) {  
104 - if (!strcmp(argv[i], "-help" )) { help(); exit(EXIT_SUCCESS); }  
105 - else if (!strcmp(argv[i], "-json" )) json = true;  
106 - else if (!strcmp(argv[i], "-permissive")) permissive = true;  
107 - else { url_provided = true; process(argv[i], QByteArray(), nam); }  
108 - }  
109 -  
110 - if (!url_provided) {  
111 - QFile file;  
112 - file.open(stdin, QFile::ReadOnly);  
113 - while (!file.atEnd()) {  
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(),  
122 - nam);  
123 -  
124 - if (json && (error.error != QJsonParseError::NoError))  
125 - qDebug() << error.errorString();  
126 - }  
127 - }  
128 -  
129 - return EXIT_SUCCESS;  
130 -}