21#include <opencv2/core/core.hpp>
26#include <ovxlib/vsi_nn_pub.h>
32 class PreProcessorForPython;
34 namespace preprocessor
46 "or 0.0 to extract an unscaled UINT8 blob, typically for use with quantized networks",
47 2.0F / 255.0F, ParamCateg);
51 "order as the network's input",
52 cv::Scalar(127.5F, 127.5F, 127.5F), ParamCateg);
56 "factor are applied. This is rarely used. Same RGB/BGR order as the network's input",
57 cv::Scalar(1.0F, 1.0F, 1.0F), ParamCateg);
61 "with same aspect ratio as the network's input tensor, and then rescale it to that "
62 "tensor's width and height (hence with cropping but no distortion). Otherwise, use "
63 "the whole image and rescale it to the network's input width and height with some "
64 "possible stretching.",
73 "class defined in the file must match the file name without the "
86 "from camera to network input dims",
87 InterpMode::Nearest, InterpMode_Values, ParamCateg);
91 "Any additional inputs required by the network would have to be specified using "
92 "Network parameter extraintensors",
109 public jevois::Parameter<preprocessor::rgb, preprocessor::showin, preprocessor::details>
133 std::vector<cv::Mat>
const &
blobs()
const;
136 cv::Size
blobsize(
size_t num)
const;
141 void b2i(
float & x,
float & y,
size_t blobnum = 0);
146 void b2i(
float & x,
float & y, cv::Size
const & bsiz,
bool letterboxed);
149 void b2is(
float & sx,
float & sy,
size_t blobnum = 0);
152 void b2is(
float & sx,
float & sy, cv::Size
const & bsiz,
bool letterboxed);
166 void i2b(
float & x,
float & y,
size_t blobnum = 0);
172 void i2b(
float & x,
float & y, cv::Size
const & bsiz,
bool letterboxed);
181 virtual std::vector<cv::Mat>
process(cv::Mat
const & img,
bool isrgb,
182 std::vector<vsi_nn_tensor_attr_t>
const & attrs,
183 std::vector<cv::Rect> & crops) = 0;
190 std::vector<vsi_nn_tensor_attr_t> itsAttrs;
191 std::vector<cv::Mat> itsBlobs;
192 std::vector<cv::Rect> itsCrops;
194 cv::Size itsImageSize;
195 unsigned int itsImageFmt;
198 std::shared_ptr<PreProcessorForPython> itsPP;
A component of a model hierarchy.
Helper class to assist modules in creating graphical and GUI elements.
A raw image as coming from a V4L2 Camera and/or being sent out to a USB Gadget.
Base class for a module that supports standardized serial messages.
JEVOIS_DECLARE_PARAMETER(numin, size_t, "Number of input blobs to generate from the received video image. " "Any additional inputs required by the network would have to be specified using " "Network parameter extraintensors", 1, ParamCateg)
Parameter.
JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(pypre, std::string, "Full path of the python pre-processor file. Name of " "class defined in the file must match the file name without the " "trailing '.py'", "", ParamCateg)
Parameter.
Pre-Processor for neural network pipeline.
JEVOIS_DECLARE_PARAMETER(rgb, bool, "When true, model works with RGB input images instead BGR ones", true, ParamCateg)
Parameter.
std::shared_ptr< PreProcessorForPython > getPreProcForPy() const
Get a pointer to our python-friendly interface.
cv::Rect getUnscaledCropRect(size_t blobnum=0)
Get unscaled crop rectangle in image coordinates.
void i2b(float &x, float &y, size_t blobnum=0)
Convert coordinates from image to blob.
JEVOIS_DECLARE_PARAMETER(showin, bool, "Show outline of cropped image fed to network", true, ParamCateg)
Parameter.
virtual void freeze(bool doit)=0
Freeze/unfreeze parameters that users should not change while running.
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.
JEVOIS_DECLARE_PARAMETER(scale, float, "Value scaling factor applied to input pixels after mean subtraction, " "or 0.0 to extract an unscaled UINT8 blob, typically for use with quantized networks", 2.0F/255.0F, ParamCateg)
Parameter.
JEVOIS_DEFINE_ENUM_CLASS(InterpMode,(Nearest)(Linear)(Cubic)(Area)(Lanczos4))
Enum for image resizing modes.
virtual void report(jevois::StdModule *mod, jevois::RawImage *outimg=nullptr, jevois::OptGUIhelper *helper=nullptr, bool overlay=true, bool idle=false)=0
Report what happened in last process() to console/output video/GUI.
JEVOIS_DECLARE_PARAMETER(mean, cv::Scalar, "Mean values subtracted from input image, in the same RGB/BGR " "order as the network's input", cv::Scalar(127.5F, 127.5F, 127.5F), ParamCateg)
Parameter.
virtual std::vector< cv::Mat > process(cv::Mat const &img, bool isrgb, std::vector< vsi_nn_tensor_attr_t > const &attrs, std::vector< cv::Rect > &crops)=0
Extract blobs from input image.
JEVOIS_DECLARE_PARAMETER(details, bool, "Show more details about the pre-processing steps", false, ParamCateg)
Parameter.
JEVOIS_DECLARE_PARAMETER(interp, InterpMode, "Image interpolation to use when resizing the input image " "from camera to network input dims", InterpMode::Nearest, InterpMode_Values, ParamCateg)
Parameter.
JEVOIS_DECLARE_PARAMETER(letterbox, bool, "When true, extract the largest possible box from the input image " "with same aspect ratio as the network's input tensor, and then rescale it to that " "tensor's width and height (hence with cropping but no distortion). Otherwise, use " "the whole image and rescale it to the network's input width and height with some " "possible stretching.", false, ParamCateg)
Parameter.
std::vector< cv::Mat > process(jevois::RawImage const &img, std::vector< vsi_nn_tensor_attr_t > const &attrs)
Extract blobs from input image.
JEVOIS_DECLARE_PARAMETER(stdev, cv::Scalar, "Input image is divided by stdev after mean subtraction and scale " "factor are applied. This is rarely used. Same RGB/BGR order as the network's input", cv::Scalar(1.0F, 1.0F, 1.0F), ParamCateg)
Parameter.
std::vector< cv::Mat > const & blobs() const
Access the last computed blobs (or empty if process() has not yet been called)
cv::Size const & imagesize() const
Access the last processed image size.
void b2is(float &sx, float &sy, size_t blobnum=0)
Convert box size from blob back to original image.
virtual ~PreProcessor()
Destructor.
void b2i(float &x, float &y, size_t blobnum=0)
Convert coordinates from blob back to original image.
cv::Size blobsize(size_t num) const
Access the width and height of a given blob, accounting for NCHW or NHWC.
Main namespace for all JeVois classes and functions.
A category to which multiple ParameterDef definitions can belong.