# HG changeset patch # User František Kučera # Date 1619288579 -7200 # Node ID 8eb799bf1d3964b9064080af5f98882d1e4b0b85 # Parent d846da24dd35a8e4b83fb1f66e9777187a139810 streamlet examples: QR: return also the polygon points diff -r d846da24dd35 -r 8eb799bf1d39 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 polygon; }; std::vector 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(); }