JeVois  1.20
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
tutorial2.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 // Simple module to convert between any supported camera grab formats and USB output formats
8 {
9  public:
10  // Default base class constructor ok
12 
13  // Virtual destructor for safe inheritance
14  virtual ~TutorialConvert() { }
15 
16  // Processing function
17  virtual void process(jevois::InputFrame && inframe, jevois::OutputFrame && outframe) override
18  {
19  // Wait for next available camera image:
20  jevois::RawImage inimg = inframe.get();
21 
22  // Convert it to BGR24:
23  cv::Mat imgbgr = jevois::rawimage::convertToCvBGR(inimg);
24 
25  // Let camera know we are done processing the input image:
26  inframe.done();
27 
28  // Wait for an image from our gadget driver into which we will put our results:
29  jevois::RawImage outimg = outframe.get();
30 
31  // Require that output has same dims as input, allow any output format:
32  outimg.require("output", inimg.width, inimg.height, outimg.fmt);
33 
34  // TutorialConvert from BGR to desired output format:
36 
37  // Send the output image with our processing results to the host over USB:
38  outframe.send();
39  }
40 };
41 
42 // Allow the module to be loaded as a shared object (.so) file:
JEVOIS_REGISTER_MODULE
JEVOIS_REGISTER_MODULE(TutorialConvert)
jevois::OutputFrame
Exception-safe wrapper around a raw image to be sent over USB.
Definition: OutputFrame.H:52
Module.H
RawImageOps.H
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::rawimage::convertToCvBGR
cv::Mat convertToCvBGR(RawImage const &src)
Convert RawImage to OpenCV doing color conversion from any RawImage source pixel to OpenCV BGR byte.
Definition: RawImageOps.C:282
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
TutorialConvert::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: tutorial2.C:17
jevois::rawimage::convertCvBGRtoRawImage
void convertCvBGRtoRawImage(cv::Mat const &src, RawImage &dst, int quality)
Convert a BGR cv::Mat to RawImage with already-allocated pixels and pixel type.
Definition: RawImageOps.C:1266
jevois::Module
Virtual base class for a vision processing module.
Definition: Module.H:104
TutorialConvert
Definition: tutorial2.C:7
jevois::RawImage::height
unsigned int height
Image height in pixels.
Definition: RawImage.H:146
jevois::InputFrame
Exception-safe wrapper around a raw camera input frame.
Definition: InputFrame.H:50
jevois::RawImage::fmt
unsigned int fmt
Pixel format as a V4L2_PIX_FMT_XXX.
Definition: RawImage.H:147
TutorialConvert::~TutorialConvert
virtual ~TutorialConvert()
Definition: tutorial2.C:14
jevois::Component::Module
friend class Module
Definition: Component.H:519