JeVois
1.17
JeVois Smart Embedded Machine Vision Toolkit
|
Share this page: |
|
|
|
 |
 |
|
Go to the documentation of this file.
34 {
return itsImageSize; }
39 if (num >= itsAttrs.size())
LFATAL(
"Invalid blob number " << num <<
", only have " << itsAttrs.size() <<
" blobs");
46 if (blobnum >= itsCrops.size())
47 LFATAL(
"Invalid blob number " << blobnum <<
", only have " << itsCrops.size() <<
" crops");
49 cv::Rect
const & r = itsCrops[blobnum];
50 b2i(x, y, blobsize(blobnum), (r.x != 0 || r.y != 0));
56 if (bsiz.width == 0 || bsiz.height == 0)
LFATAL(
"Cannot handle zero blob width or height");
61 float const fac = std::min(itsImageSize.width /
float(bsiz.width), itsImageSize.height /
float(bsiz.height));
62 float const cropw = fac * bsiz.width + 0.4999F;
63 float const croph = fac * bsiz.height + 0.4999F;
64 x = (itsImageSize.width - cropw) * 0.5
F + x * fac;
65 y = (itsImageSize.height - croph) * 0.5
F + y * fac;
69 x *= itsImageSize.width / float(bsiz.width);
70 y *= itsImageSize.height / float(bsiz.height);
77 if (num >= itsCrops.size())
LFATAL(
"Invalid blob number " << num <<
", only have " << itsCrops.size() <<
" blobs");
84 cv::Rect
const & r = getUnscaledCropRect(num);
85 tlx = r.x; tly = r.y; brx = r.x + r.width; bry = r.y + r.height;
90 std::vector<vsi_nn_tensor_attr_t>
const & attrs)
93 itsImageSize.width = img.
width; itsImageSize.height = img.
height; itsImageFmt = img.
fmt;
94 itsCrops.clear(); itsBlobs.clear();
96 if (itsAttrs.empty()) itsAttrs = attrs;
97 if (itsAttrs.empty())
LFATAL(
"Cannot work with no input tensors");
100 if (img.
fmt == V4L2_PIX_FMT_RGB24)
102 else if (img.
fmt == V4L2_PIX_FMT_BGR24)
118 if (helper && idle ==
false && ImGui::CollapsingHeader(
"Pre-Processing", ImGuiTreeNodeFlags_DefaultOpen))
120 ImGui::BulletText(
"Input image: %dx%d %s", itsImageSize.width, itsImageSize.height,
123 if (itsImageFmt != V4L2_PIX_FMT_RGB24 && itsImageFmt != V4L2_PIX_FMT_BGR24)
125 if (
rgb::get()) ImGui::BulletText(
"Convert to RGB");
126 else ImGui::BulletText(
"Convert to BGR");
132 report(mod, outimg, helper, overlay, idle);
139 for (cv::Rect
const & r : itsCrops)
140 ImGui::GetBackgroundDrawList()->AddRect(helper->
i2d(r.x, r.y),
141 helper->
i2d(r.x + r.width, r.y + r.height), 0x80808080, 0, 0, 5);
147 for (cv::Rect
const & r : itsCrops)
153 if (helper && idle ==
false)
156 for (cv::Mat
const & blob : itsBlobs)
158 cv::Rect
const & r = itsCrops[idx];
159 bool const stretch = (r.x == 0 && r.y == 0);
161 ImGui::BulletText(
"Crop %d: %dx%d @ %d,%d %s", idx, r.width, r.height, r.x, r.y,
162 stretch ?
"" :
"(letterbox)");
164 stretch ?
"(stretch)" :
"(uniform)");
Data collection mode RAW means that the latest available raw data is returned each time get() is called
cv::Size blobsize(size_t num) const
Access the width and height of a given blob, accounting for NCHW or NHWC.
cv::Rect getUnscaledCropRect(size_t blobnum=0)
Get unscaled crop rectangle in image coordinates.
cv::Mat convertToCvRGB(RawImage const &src)
Convert RawImage to OpenCV doing color conversion from any RawImage source pixel to OpenCV RGB byte.
A raw image as coming from a V4L2 Camera and/or being sent out to a USB Gadget.
ImVec2 i2d(ImVec2 p, char const *name=nullptr)
Convert coordinates of a point from within a rendered image to on-screen.
const std::vector< cv::Mat > & blobs() const
Access the last computed blobs (or empty if process() has not yet been called)
cv::Mat convertToCvBGR(RawImage const &src)
Convert RawImage to OpenCV doing color conversion from any RawImage source pixel to OpenCV BGR byte.
Helper class to assist modules in creating graphical and GUI elements.
unsigned int width
Image width in pixels.
std::string shapestr(cv::Mat const &m)
Get a string of the form: "nD AxBxC... TYPE" from an n-dimensional cv::Mat with data type TYPE.
std::string fccstr(unsigned int fcc)
Convert a V4L2 four-cc code (V4L2_PIX_FMT_...) to a 4-char string.
#define LFATAL(msg)
Convenience macro for users to print out console or syslog messages, FATAL level.
virtual void sendreport(jevois::StdModule *mod, jevois::RawImage *outimg=nullptr, jevois::OptGUIhelper *helper=nullptr, bool overlay=true, bool idle=false)
Report what happened in last process() to console/output video/GUI.
unsigned int height
Image height in pixels.
cv::Mat cvImage(RawImage const &src)
Create an OpenCV image from the existing RawImage data, sharing the pixel memory rather than copying ...
cv::Size attrsize(vsi_nn_tensor_attr_t const &attr)
Get a tensor's size in cv::Size format.
void drawRect(RawImage &img, int x, int y, unsigned int w, unsigned int h, unsigned int thick, unsigned int col)
Draw a rectangle in a YUYV image.
unsigned int fmt
Pixel format as a V4L2_PIX_FMT_XXX.
const cv::Size & imagesize() const
Access the last processed image size.
void b2i(float &x, float &y, size_t blobnum=0)
Convert coordinates from blob back to original image.
std::vector< cv::Mat > process(jevois::RawImage const &img, std::vector< vsi_nn_tensor_attr_t > const &attrs)
Extract blobs from input image.
Base class for a module that supports standardized serial messages.
virtual ~PreProcessor()
Destructor.