40 {
return itsImageSize; }
45 if (num >= itsAttrs.size())
LFATAL(
"Invalid blob number " << num <<
", only have " << itsAttrs.size() <<
" blobs");
52 if (blobnum >= itsCrops.size())
53 LFATAL(
"Invalid blob number " << blobnum <<
", only have " << itsCrops.size() <<
" crops");
55 cv::Rect
const & r = itsCrops[blobnum];
56 b2i(x, y, blobsize(blobnum), (r.x != 0 || r.y != 0));
62 if (bsiz.width == 0 || bsiz.height == 0)
LFATAL(
"Cannot handle zero blob width or height");
67 float const fac = std::min(itsImageSize.width /
float(bsiz.width), itsImageSize.height /
float(bsiz.height));
68 float const cropw = fac * bsiz.width + 0.4999F;
69 float const croph = fac * bsiz.height + 0.4999F;
70 x = (itsImageSize.width - cropw) * 0.5
F + x * fac;
71 y = (itsImageSize.height - croph) * 0.5
F + y * fac;
75 x *= itsImageSize.width / float(bsiz.width);
76 y *= itsImageSize.height / float(bsiz.height);
83 if (num >= itsCrops.size())
LFATAL(
"Invalid blob number " << num <<
", only have " << itsCrops.size() <<
" blobs");
90 cv::Rect
const & r = getUnscaledCropRect(num);
91 tlx = r.x; tly = r.y; brx = r.x + r.width; bry = r.y + r.height;
97 if (blobnum >= itsCrops.size())
98 LFATAL(
"Invalid blob number " << blobnum <<
", only have " << itsCrops.size() <<
" crops");
100 cv::Rect
const & r = itsCrops[blobnum];
101 i2b(x, y, blobsize(blobnum), (r.x != 0 || r.y != 0));
107 if (itsImageSize.width == 0 || itsImageSize.height == 0)
LFATAL(
"Cannot handle zero image width or height");
108 if (bsiz.width == 0 || bsiz.height == 0)
LFATAL(
"Cannot handle zero blob width or height");
113 float const fac = std::min(itsImageSize.width /
float(bsiz.width), itsImageSize.height /
float(bsiz.height));
114 float const cropw = fac * bsiz.width + 0.4999F;
115 float const croph = fac * bsiz.height + 0.4999F;
116 x = (x - (itsImageSize.width - cropw) * 0.5
F) / fac;
117 y = (y - (itsImageSize.height - croph) * 0.5
F) / fac;
121 x *= float(bsiz.width) / itsImageSize.width;
122 y *= float(bsiz.height) / itsImageSize.height;
132 std::vector<vsi_nn_tensor_attr_t>
const & attrs)
135 itsImageSize.width = img.
width; itsImageSize.height = img.
height; itsImageFmt = img.
fmt;
136 itsCrops.clear(); itsBlobs.clear();
138 if (itsAttrs.empty()) itsAttrs = attrs;
139 if (itsAttrs.empty())
LFATAL(
"Cannot work with no input tensors");
142 if (img.
fmt == V4L2_PIX_FMT_RGB24)
144 else if (img.
fmt == V4L2_PIX_FMT_BGR24)
160 if (helper && idle ==
false && ImGui::CollapsingHeader(
"Pre-Processing", ImGuiTreeNodeFlags_DefaultOpen))
162 ImGui::BulletText(
"Input image: %dx%d %s", itsImageSize.width, itsImageSize.height,
165 if (itsImageFmt != V4L2_PIX_FMT_RGB24 && itsImageFmt != V4L2_PIX_FMT_BGR24)
167 if (
rgb::get()) ImGui::BulletText(
"Convert to RGB");
168 else ImGui::BulletText(
"Convert to BGR");
172 report(mod, outimg, helper, overlay, idle);
177 if (helper ==
nullptr) report(mod, outimg, helper, overlay, idle);
184 for (cv::Rect
const & r : itsCrops)
185 ImGui::GetBackgroundDrawList()->AddRect(helper->
i2d(r.x, r.y),
186 helper->
i2d(r.x + r.width, r.y + r.height), 0x80808080, 0, 0, 5);
190 for (cv::Rect
const & r : itsCrops)
199 for (cv::Mat
const & blob : itsBlobs)
201 cv::Rect
const & r = itsCrops[idx];
202 bool const stretch = (r.x == 0 && r.y == 0);
204 ImGui::BulletText(
"Crop %d: %dx%d @ %d,%d %s", idx, r.width, r.height, r.x, r.y,
205 stretch ?
"" :
"(letterbox)");
207 stretch ?
"(stretch)" :
"(uniform)");