aboutsummaryrefslogtreecommitdiffstats
path: root/recipes-support/opencv/opencv/OpenCV_DNN_examples.patch
blob: 0e83e9941fa444d3f6c9edde5281b8da03251129 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
From 3c4daafb54f961e376104a461ca7ec114ff0331a Mon Sep 17 00:00:00 2001
From: Ludek Slosarcik <ludek.slosarcik@nxp.com>
Date: Fri, 14 Feb 2020 15:46:50 +0100
Subject: [PATCH] opencv_dnn: added video device for 2 examples, and change text labels

Signed-off-by: Ludek Slosarcik <ludek.slosarcik@nxp.com>

Upstream-Status: Pending
---
 samples/cpp/logistic_regression.cpp |  2 +-
 samples/dnn/classification.cpp      |  7 ++++---
 samples/dnn/object_detection.cpp    | 10 +++++-----
 samples/dnn/segmentation.cpp        |  2 +-
 samples/dnn/text_detection.cpp      |  5 +++--
 5 files changed, 14 insertions(+), 12 deletions(-)

Index: git/samples/cpp/logistic_regression.cpp
===================================================================
--- git.orig/samples/cpp/logistic_regression.cpp
+++ git/samples/cpp/logistic_regression.cpp
@@ -28,7 +28,7 @@ static float calculateAccuracyPercent(co
 
 int main()
 {
-    const String filename = samples::findFile("data01.xml");
+    const String filename = samples::findFile("../data/data01.xml");
     cout << "**********************************************************************" << endl;
     cout << filename
          << " contains digits 0 and 1 of 20 samples each, collected on an Android device" << endl;
Index: git/samples/dnn/classification.cpp
===================================================================
--- git.orig/samples/dnn/classification.cpp
+++ git/samples/dnn/classification.cpp
@@ -11,6 +11,7 @@ std::string keys =
     "{ help  h          | | Print help message. }"
     "{ @alias           | | An alias name of model to extract preprocessing parameters from models.yml file. }"
     "{ zoo              | models.yml | An optional path to file with preprocessing parameters }"
+    "{ device           | 0 | camera device number. }"
     "{ input i          | | Path to input image or video file. Skip this argument to capture frames from a camera.}"
     "{ initial_width    | 0 | Preprocess input image by initial resizing to a specific width.}"
     "{ initial_height   | 0 | Preprocess input image by initial resizing to a specific height.}"
@@ -102,7 +103,7 @@ int main(int argc, char** argv)
     if (parser.has("input"))
         cap.open(parser.get<String>("input"));
     else
-        cap.open(0);
+        cap.open(parser.get<int>("device"));
     //! [Open a video file or an image file or a camera stream]
 
     // Process frames.
@@ -151,13 +152,13 @@ int main(int argc, char** argv)
         double freq = getTickFrequency() / 1000;
         double t = net.getPerfProfile(layersTimes) / freq;
         std::string label = format("Inference time: %.2f ms", t);
-        putText(frame, label, Point(0, 15), FONT_HERSHEY_SIMPLEX, 0.5, Scalar(0, 255, 0));
+        putText(frame, label, Point(0, 20), FONT_HERSHEY_SIMPLEX, 0.8, Scalar(0, 0, 255), 2, 8, false);
 
         // Print predicted class.
         label = format("%s: %.4f", (classes.empty() ? format("Class #%d", classId).c_str() :
                                                       classes[classId].c_str()),
                                    confidence);
-        putText(frame, label, Point(0, 40), FONT_HERSHEY_SIMPLEX, 0.5, Scalar(0, 255, 0));
+        putText(frame, label, Point(0, 45), FONT_HERSHEY_SIMPLEX, 0.8, Scalar(0, 0, 255), 2, 8, false);
 
         imshow(kWinName, frame);
     }
Index: git/samples/dnn/object_detection.cpp
===================================================================
--- git.orig/samples/dnn/object_detection.cpp
+++ git/samples/dnn/object_detection.cpp
@@ -251,13 +251,13 @@ int main(int argc, char** argv)
         if (predictionsQueue.counter > 1)
         {
             std::string label = format("Camera: %.2f FPS", framesQueue.getFPS());
-            putText(frame, label, Point(0, 15), FONT_HERSHEY_SIMPLEX, 0.5, Scalar(0, 255, 0));
+            putText(frame, label, Point(0, 20), FONT_HERSHEY_SIMPLEX, 0.8, Scalar(0, 0, 255), 2, 8, false);
 
             label = format("Network: %.2f FPS", predictionsQueue.getFPS());
-            putText(frame, label, Point(0, 30), FONT_HERSHEY_SIMPLEX, 0.5, Scalar(0, 255, 0));
+            putText(frame, label, Point(0, 45), FONT_HERSHEY_SIMPLEX, 0.8, Scalar(0, 0, 255), 2, 8, false);
 
             label = format("Skipped frames: %d", framesQueue.counter - predictionsQueue.counter);
-            putText(frame, label, Point(0, 45), FONT_HERSHEY_SIMPLEX, 0.5, Scalar(0, 255, 0));
+            putText(frame, label, Point(0, 70), FONT_HERSHEY_SIMPLEX, 0.8, Scalar(0, 0, 255), 2, 8, false);
         }
         imshow(kWinName, frame);
     }
@@ -293,7 +293,7 @@ int main(int argc, char** argv)
         double freq = getTickFrequency() / 1000;
         double t = net.getPerfProfile(layersTimes) / freq;
         std::string label = format("Inference time: %.2f ms", t);
-        putText(frame, label, Point(0, 15), FONT_HERSHEY_SIMPLEX, 0.5, Scalar(0, 255, 0));
+        putText(frame, label, Point(0, 20), FONT_HERSHEY_SIMPLEX, 0.8, Scalar(0, 0, 255), 2, 8, false);
 
         imshow(kWinName, frame);
     }
@@ -462,7 +462,7 @@ void drawPred(int classId, float conf, i
     top = max(top, labelSize.height);
     rectangle(frame, Point(left, top - labelSize.height),
               Point(left + labelSize.width, top + baseLine), Scalar::all(255), FILLED);
-    putText(frame, label, Point(left, top), FONT_HERSHEY_SIMPLEX, 0.5, Scalar());
+    putText(frame, label, Point(left, top), FONT_HERSHEY_SIMPLEX, 0.8, Scalar());
 }
 
 void callback(int pos, void*)
Index: git/samples/dnn/segmentation.cpp
===================================================================
--- git.orig/samples/dnn/segmentation.cpp
+++ git/samples/dnn/segmentation.cpp
@@ -157,7 +157,7 @@ int main(int argc, char** argv)
         double freq = getTickFrequency() / 1000;
         double t = net.getPerfProfile(layersTimes) / freq;
         std::string label = format("Inference time: %.2f ms", t);
-        putText(frame, label, Point(0, 15), FONT_HERSHEY_SIMPLEX, 0.5, Scalar(0, 255, 0));
+        putText(frame, label, Point(0, 20), FONT_HERSHEY_SIMPLEX, 0.8, Scalar(0, 0, 255), 2, 8, false);
 
         imshow(kWinName, frame);
         if (!classes.empty())
Index: git/samples/dnn/text_detection.cpp
===================================================================
--- git.orig/samples/dnn/text_detection.cpp
+++ git/samples/dnn/text_detection.cpp
@@ -30,6 +30,7 @@ using namespace cv::dnn;
 const char* keys =
     "{ help  h              | | Print help message. }"
     "{ input i              | | Path to input image or video file. Skip this argument to capture frames from a camera.}"
+    "{ device               | 0 | camera device number. }"
     "{ detModel dmp         | | Path to a binary .pb file contains trained detector network.}"
     "{ width                | 320 | Preprocess input image by resizing to a specific width. It should be multiple by 32. }"
     "{ height               | 320 | Preprocess input image by resizing to a specific height. It should be multiple by 32. }"
@@ -106,7 +107,7 @@ int main(int argc, char** argv)
 
     // Open a video file or an image file or a camera stream.
     VideoCapture cap;
-    bool openSuccess = parser.has("input") ? cap.open(parser.get<String>("input")) : cap.open(0);
+    bool openSuccess = parser.has("input") ? cap.open(parser.get<String>("input")) : cap.open(parser.get<int>("device"));
     CV_Assert(openSuccess);
 
     static const std::string kWinName = "EAST: An Efficient and Accurate Scene Text Detector";