JeVois  1.20
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
tutorial3.C
Go to the documentation of this file.
1 #include <jevois/Core/Module.H>
3 #include <opencv2/core/core.hpp>
4 #include <opencv2/imgproc/imgproc.hpp>
5 
6 // Parameters for our module:
7 static jevois::ParameterCategory const ParamCateg("Edge Detection Options");
8 
9 JEVOIS_DECLARE_PARAMETER(thresh1, double, "First threshold for hysteresis", 50.0, ParamCateg);
10 JEVOIS_DECLARE_PARAMETER(thresh2, double, "Second threshold for hysteresis", 150.0, ParamCateg);
11 JEVOIS_DECLARE_PARAMETER(aperture, int, "Aperture size for the Sobel operator", 3, jevois::Range<int>(3, 53), ParamCateg);
12 JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(l2grad, bool, "Use more accurate L2 gradient norm if true, L1 if false", false, ParamCateg);
13 
14 // Simple module to detect edges using the Canny algorithm from OpenCV
16  public jevois::Parameter<thresh1, thresh2, aperture, l2grad>
17 {
18  public:
19  // Default base class constructor ok
21 
22  // Virtual destructor for safe inheritance
23  virtual ~TutorialEdgeDetection() { }
24 
25  // Processing function
26  virtual void process(jevois::InputFrame && inframe, jevois::OutputFrame && outframe) override
27  {
28  // Wait for next available camera image:
29  jevois::RawImage inimg = inframe.get();
30 
31  // Convert to OpenCV grayscale:
32  cv::Mat grayimg = jevois::rawimage::convertToCvGray(inimg);
33 
34  // Let camera know we are done processing the input image:
35  inframe.done();
36 
37  // Wait for an image from our gadget driver into which we will put our results. Require that it must have same
38  // image size as the input image, and greyscale pixels:
39  jevois::RawImage outimg = outframe.get();
40  outimg.require("output", inimg.width, inimg.height, V4L2_PIX_FMT_GREY);
41 
42  // Compute Canny edges directly into the output image:
43  cv::Mat edges = jevois::rawimage::cvImage(outimg); // Pixel data of "edges" shared with "outimg", no copy
44  cv::Canny(grayimg, edges, thresh1::get(), thresh2::get(), aperture::get(), l2grad::get());
45 
46  // Send the output image with our processing results to the host over USB:
47  outframe.send();
48  }
49 
50  // Callback function for parameter l2grad
51  void onParamChange(l2grad const & param, bool const & newval) override
52  {
53  LINFO("you changed l2grad to be " + std::to_string(newval));
54  }
55 };
56 
57 // Allow the module to be loaded as a shared object (.so) file:
jevois::imu::get
Data collection mode RAW means that the latest available raw data is returned each time get() is called
jevois::Range
A generic range class.
Definition: Range.H:80
jevois::OutputFrame
Exception-safe wrapper around a raw image to be sent over USB.
Definition: OutputFrame.H:52
Module.H
RawImageOps.H
TutorialEdgeDetection
Definition: tutorial3.C:15
JEVOIS_REGISTER_MODULE
JEVOIS_REGISTER_MODULE(TutorialEdgeDetection)
jevois::RawImage
A raw image as coming from a V4L2 Camera and/or being sent out to a USB Gadget.
Definition: RawImage.H:110
jevois::ParameterCategory
A category to which multiple ParameterDef definitions can belong.
Definition: ParameterDef.H:33
jevois::rawimage::convertToCvGray
cv::Mat convertToCvGray(RawImage const &src)
Convert RawImage to OpenCV doing color conversion from any RawImage source pixel to OpenCV gray byte.
Definition: RawImageOps.C:246
jevois::RawImage::require
void require(char const *info, unsigned int w, unsigned int h, unsigned int f) const
Require a particular image size and format, issue a fatal error message and throw if no match.
Definition: RawImage.C:80
jevois::RawImage::width
unsigned int width
Image width in pixels.
Definition: RawImage.H:145
jevois::Manager::JEVOIS_DECLARE_PARAMETER
JEVOIS_DECLARE_PARAMETER(help, bool, "Print this help message", false, ParamCateg)
Parameter.
jevois::Manager::ParamCateg
static const ParameterCategory ParamCateg("General Options")
Parameter category.
jevois::Module
Virtual base class for a vision processing module.
Definition: Module.H:104
TutorialEdgeDetection::onParamChange
void onParamChange(l2grad const &param, bool const &newval) override
Definition: tutorial3.C:51
TutorialEdgeDetection::~TutorialEdgeDetection
virtual ~TutorialEdgeDetection()
Definition: tutorial3.C:23
jevois::RawImage::height
unsigned int height
Image height in pixels.
Definition: RawImage.H:146
TutorialEdgeDetection::process
virtual void process(jevois::InputFrame &&inframe, jevois::OutputFrame &&outframe) override
Processing function, version that receives a frame from camera and sends a frame out over USB.
Definition: tutorial3.C:26
jevois::to_string
std::string to_string(T const &val)
Convert from type to string.
jevois::InputFrame
Exception-safe wrapper around a raw camera input frame.
Definition: InputFrame.H:50
jevois::rawimage::cvImage
cv::Mat cvImage(RawImage const &src)
Create an OpenCV image from the existing RawImage data, sharing the pixel memory rather than copying ...
Definition: RawImageOps.C:31
jevois::Manager::JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK
JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(loglevel, LogLevel, "Set the minimum log level to display", LogLevel::info, LogLevel_Values, ParamCateg)
Parameter.
LINFO
#define LINFO(msg)
Convenience macro for users to print out console or syslog messages, INFO level.
Definition: Log.H:194
jevois::Component::Module
friend class Module
Definition: Component.H:519