streamlet examples: QR: return also the polygon points v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sat, 24 Apr 2021 20:22:59 +0200
branchv_0
changeset 88 8eb799bf1d39
parent 87 d846da24dd35
child 89 25a11859975b
streamlet examples: QR: return also the polygon points
streamlet-examples/qr.cpp
--- a/streamlet-examples/qr.cpp	Sat Apr 24 20:12:41 2021 +0200
+++ b/streamlet-examples/qr.cpp	Sat Apr 24 20:22:59 2021 +0200
@@ -27,8 +27,9 @@
 /**
  * This streamlet extracts QR codes from image files.
  * 
- * It provides two attributes:
+ * It provides three attributes:
  *  - qr: first QR code found (if any)
+ *  - qr_count: number of QR codes found
  *  - qr_xml: XML containing all QR cpdes found an additional metadata
  *	
  */
@@ -37,6 +38,12 @@
 
 	const wstring XMLNS = L"tag:globalcode.info,2018:qr:FIXME:final-xmlns"; // FIXME: correct xmlns URI
 
+	class Point {
+	public:
+		int x;
+		int y;
+	};
+
 	class Symbol {
 	public:
 		int id;
@@ -46,6 +53,7 @@
 		int y;
 		int width;
 		int height;
+		std::vector<Point> polygon;
 	};
 
 	std::vector<Symbol> findSymbols(std::wstring fileName) {
@@ -86,6 +94,7 @@
 				minY = minY ? std::min(minY, y) : y;
 				maxX = std::max(maxX, x);
 				maxY = std::max(maxY, y);
+				s.polygon.push_back({x, y});
 			}
 
 			s.x = minX;
@@ -147,11 +156,20 @@
 		for (Symbol s : symbols) {
 			xmlWriter.writeStartElement(L"symbol");
 			xmlWriter.writeTextElement(L"value",{}, s.value);
+			
+			// TODO: well-designed XML schema
+			// TODO: synchronize/share common XML parts with relpipe-in-qr
+			xmlWriter.writeStartElement(L"rectangular-box");
 			xmlWriter.writeTextElement(L"x",{}, std::to_wstring(s.x));
 			xmlWriter.writeTextElement(L"y",{}, std::to_wstring(s.y));
 			xmlWriter.writeTextElement(L"height",{}, std::to_wstring(s.height));
 			xmlWriter.writeTextElement(L"width",{}, std::to_wstring(s.width));
-			// TODO: polygon
+			xmlWriter.writeEndElement();
+
+			xmlWriter.writeStartElement(L"polygon");
+			for (Point p : s.polygon) xmlWriter.writeEmptyElement(L"point",{L"x", std::to_wstring(p.x), L"y", std::to_wstring(p.y)});
+			xmlWriter.writeEndElement();
+
 			xmlWriter.writeEndElement();
 		}