23#include <opencv2/imgproc/imgproc.hpp>
27 itsGadget(gad), itsDidGet(false), itsDidSend(false), itsImagePtrForException(excimg)
34 if (itsGadget.get() ==
nullptr)
return;
37 if (itsDidGet ==
false)
return;
42 if (itsImagePtrForException)
44 if (itsDidSend ==
false) { *itsImagePtrForException = itsImage; }
50 if (itsDidSend ==
false)
try { itsGadget->send(itsImage); }
catch (...) { }
57 itsGadget->get(itsImage);
65 itsGadget->send(itsImage);
67 if (itsImagePtrForException) itsImagePtrForException->
invalidate();
75 case CV_8UC3: sendScaledCvBGR(img, quality);
break;
76 case CV_8UC1: sendScaledCvGRAY(img, quality);
break;
77 case CV_8UC4: sendScaledCvRGBA(img, quality);
break;
78 default:
LFATAL(
"cv::Mat of type " <<
cvtypestr(img.type()) <<
" not supported.");
RawImage const & get() const
Get a pre-allocated image so that we can fill the pixel data and later send out over USB using send()
OutputFrame(OutputFrame &&other)=default
Move constructor.
void sendScaledCvGRAY(cv::Mat const &img, int quality=75) const
Shorthand to send a GRAY cv::Mat after converting it to the current output format.
void sendCvBGR(cv::Mat const &img, int quality=75) const
Shorthand to send a BGR cv::Mat after converting it to the current output format.
void sendScaledCvRGBA(cv::Mat const &img, int quality=75) const
Shorthand to send a RGBA cv::Mat after converting it to the current output format.
void sendScaledCvRGB(cv::Mat const &img, int quality=75) const
Shorthand to send a RGB cv::Mat after converting it to the current output format.
void sendCv(cv::Mat const &img, int quality=75) const
Shorthand to send a cv::Mat after converting / scaling it to the current output format.
void sendCvGRAY(cv::Mat const &img, int quality=75) const
Shorthand to send a GRAY cv::Mat after converting it to the current output format.
~OutputFrame()
Destructor, returns the buffers to the driver as needed.
void sendScaledCvBGR(cv::Mat const &img, int quality=75) const
Shorthand to send a BGR cv::Mat after converting it to the current output format.
void sendCvRGB(cv::Mat const &img, int quality=75) const
Shorthand to send a RGB cv::Mat after converting it to the current output format.
void sendCvRGBA(cv::Mat const &img, int quality=75) const
Shorthand to send a RGBA cv::Mat after converting it to the current output format.
void send() const
Send an image out over USB to the host computer.
A raw image as coming from a V4L2 Camera and/or being sent out to a USB Gadget.
void invalidate()
Invalidate the image by zero'ing out the pointer to pixel buffer and the dims and format.
unsigned int width
Image width in pixels.
unsigned int height
Image height in pixels.
#define LFATAL(msg)
Convenience macro for users to print out console or syslog messages, FATAL level.
void convertCvRGBAtoRawImage(cv::Mat const &src, RawImage &dst, int quality)
Convert an RGBA cv::Mat to RawImage with already-allocated pixels and pixel type.
cv::Mat rescaleCv(cv::Mat const &img, cv::Size const &newdims)
Rescale an OpenCV image, choosing the right kind of interpolation.
void convertCvBGRtoRawImage(cv::Mat const &src, RawImage &dst, int quality)
Convert a BGR cv::Mat to RawImage with already-allocated pixels and pixel type.
void convertCvRGBtoRawImage(cv::Mat const &src, RawImage &dst, int quality)
Convert a RGB cv::Mat to RawImage with already-allocated pixels and pixel type.
void convertCvGRAYtoRawImage(cv::Mat const &src, RawImage &dst, int quality)
Convert a Gray cv::Mat to RawImage with already-allocated pixels and pixel type.
std::string cvtypestr(unsigned int cvtype)
Convert cv::Mat::type() code to to a string (e.g., CV_8UC1, CV_32SC3, etc)