JeVois  1.21
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
Loading...
Searching...
No Matches
InputFrame.C
Go to the documentation of this file.
1// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2//
3// JeVois Smart Embedded Machine Vision Toolkit - Copyright (C) 2016 by Laurent Itti, the University of Southern
4// California (USC), and iLab at USC. See http://iLab.usc.edu and http://jevois.org for information about this project.
5//
6// This file is part of the JeVois Smart Embedded Machine Vision Toolkit. This program is free software; you can
7// redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
8// Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
10// License for more details. You should have received a copy of the GNU General Public License along with this program;
11// if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
12//
13// Contact information: Laurent Itti - 3641 Watt Way, HNB-07A - Los Angeles, CA 90089-2520 - USA.
14// Tel: +1 213 740 3527 - itti@pollux.usc.edu - http://iLab.usc.edu - http://jevois.org
15// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16/*! \file */
17
19
22#include <jevois/Util/Utils.H>
23#include <opencv2/imgproc/imgproc.hpp>
24
25// ####################################################################################################
26jevois::InputFrame::InputFrame(std::shared_ptr<jevois::VideoInput> const & cam, bool turbo) :
27 itsCamera(cam), itsTurbo(turbo)
28{ }
29
30// ####################################################################################################
32{
33 // If itsCamera is invalidated, we have been moved to another object, so do not do anything here:
34 if (itsCamera.get() == nullptr) return;
35
36 // If we did not get(), do it now to avoid choking the camera:
37 if (itsDidGet == false) try { get(); } catch (...) { }
38
39 // If we did get() but not done(), signal done now:
40 if (itsDidGet && itsDidDone == false) try { itsCamera->done(itsImage); } catch (...) { }
41
42 // If we did not get2() and we are CropScale, do a get2() now:
43 if (itsCamera->hasScaledImage() && itsDidGet2 == false) try { get2(); } catch (...) { }
44
45 // If we did get2() but not done2(), signal done now:
46 if (itsDidGet2 && itsDidDone2 == false) try { itsCamera->done2(itsImage2); } catch (...) { }
47}
48
49// ####################################################################################################
50jevois::RawImage const & jevois::InputFrame::get(bool casync) const
51{
52 if (itsDidGet == false)
53 {
54 itsCamera->get(itsImage);
55 itsDidGet = true;
56 if (casync && itsTurbo) itsImage.buf->sync();
57 }
58 return itsImage;
59}
60// ####################################################################################################
62{
63 return itsCamera->hasScaledImage();
64}
65
66// ####################################################################################################
68{
69 if (itsDidGet2 == false)
70 {
71 itsCamera->get2(itsImage2);
72 itsDidGet2 = true;
73 if (casync && itsTurbo) itsImage2.buf->sync();
74 }
75 return itsImage2;
76}
77
78// ####################################################################################################
80{
81 if (hasScaledImage()) return get2(casync);
82 return get(casync);
83}
84
85// ####################################################################################################
86int jevois::InputFrame::getDmaFd(bool casync) const
87{
88 get(casync);
89 itsDmaFd = itsImage.buf->dmaFd();
90 return itsDmaFd;
91}
92
93// ####################################################################################################
94int jevois::InputFrame::getDmaFd2(bool casync) const
95{
96 get2(casync);
97 itsDmaFd2 = itsImage2.buf->dmaFd();
98 return itsDmaFd2;
99}
100
101// ####################################################################################################
103{
104 itsCamera->done(itsImage);
105 itsDidDone = true;
106}
107
108// ####################################################################################################
110{
111 itsCamera->done2(itsImage2);
112 itsDidDone2 = true;
113}
114
115// ####################################################################################################
116cv::Mat jevois::InputFrame::getCvGRAY(bool casync) const
117{
118 jevois::RawImage const & rawimg = get(casync);
119 cv::Mat cvimg = jevois::rawimage::convertToCvGray(rawimg);
120 done();
121 return cvimg;
122}
123
124// ####################################################################################################
125cv::Mat jevois::InputFrame::getCvBGR(bool casync) const
126{
127 jevois::RawImage const & rawimg = get(casync);
128 cv::Mat cvimg = jevois::rawimage::convertToCvBGR(rawimg);
129 done();
130 return cvimg;
131}
132
133// ####################################################################################################
134cv::Mat jevois::InputFrame::getCvRGB(bool casync) const
135{
136 jevois::RawImage const & rawimg = get(casync);
137 cv::Mat cvimg = jevois::rawimage::convertToCvRGB(rawimg);
138 done();
139 return cvimg;
140}
141
142// ####################################################################################################
143cv::Mat jevois::InputFrame::getCvRGBA(bool casync) const
144{
145 jevois::RawImage const & rawimg = get(casync);
146 cv::Mat cvimg = jevois::rawimage::convertToCvRGBA(rawimg);
147 done();
148 return cvimg;
149}
150
151// ####################################################################################################
152cv::Mat jevois::InputFrame::getCvGRAYp(bool casync) const
153{
154 jevois::RawImage const & rawimg = getp(casync);
155 cv::Mat cvimg = jevois::rawimage::convertToCvGray(rawimg);
156 done();
157 return cvimg;
158}
159
160// ####################################################################################################
161cv::Mat jevois::InputFrame::getCvBGRp(bool casync) const
162{
163 jevois::RawImage const & rawimg = getp(casync);
164 cv::Mat cvimg = jevois::rawimage::convertToCvBGR(rawimg);
165 done();
166 return cvimg;
167}
168
169// ####################################################################################################
170cv::Mat jevois::InputFrame::getCvRGBp(bool casync) const
171{
172 jevois::RawImage const & rawimg = getp(casync);
173 cv::Mat cvimg = jevois::rawimage::convertToCvRGB(rawimg);
174 done();
175 return cvimg;
176}
177
178// ####################################################################################################
179cv::Mat jevois::InputFrame::getCvRGBAp(bool casync) const
180{
181 jevois::RawImage const & rawimg = getp(casync);
182 cv::Mat cvimg = jevois::rawimage::convertToCvRGBA(rawimg);
183 done();
184 return cvimg;
185}
186
cv::Mat getCvGRAYp(bool casync=false) const
Shorthand to get the input image for processing as a GRAY cv::Mat and release the raw buffer.
Definition InputFrame.C:152
cv::Mat getCvBGR(bool casync=false) const
Shorthand to get the input image as a BGR cv::Mat and release the raw buffer.
Definition InputFrame.C:125
RawImage const & get(bool casync=false) const
Get the next captured camera image.
Definition InputFrame.C:50
RawImage const & getp(bool casync=false) const
Get the next captured camera image that is intended for processing.
Definition InputFrame.C:79
cv::Mat getCvGRAY(bool casync=false) const
Shorthand to get the input image as a GRAY cv::Mat and release the raw buffer.
Definition InputFrame.C:116
void done() const
Indicate that user processing is done with the image previously obtained via get()
Definition InputFrame.C:102
void done2() const
Indicate that user processing is done with the ISP-scaled image previously obtained via get2()
Definition InputFrame.C:109
int getDmaFd(bool casync=false) const
Get the DMA-BUF file descriptor of the camera frame.
Definition InputFrame.C:86
InputFrame(InputFrame &&other)=default
Move constructor.
~InputFrame()
Destructor, returns the buffers to the driver as needed.
Definition InputFrame.C:31
RawImage const & get2(bool casync=false) const
Get the next captured camera image, ISP-scaled second frame.
Definition InputFrame.C:67
int getDmaFd2(bool casync=false) const
Get the DMA-BUF file descriptor of the ISP-scaled second camera frame.
Definition InputFrame.C:94
bool hasScaledImage() const
Check whether a second input image scaled by the JeVoisPro Platform ISP is available.
Definition InputFrame.C:61
cv::Mat getCvRGBA(bool casync=false) const
Shorthand to get the input image as a RGBA cv::Mat and release the raw buffer.
Definition InputFrame.C:143
cv::Mat getCvRGBp(bool casync=false) const
Shorthand to get the input image for processing as a RGB cv::Mat and release the raw buffer.
Definition InputFrame.C:170
cv::Mat getCvRGBAp(bool casync=false) const
Shorthand to get the input image for processing as a RGBA cv::Mat and release the raw buffer.
Definition InputFrame.C:179
cv::Mat getCvBGRp(bool casync=false) const
Shorthand to get the input image for processing as a BGR cv::Mat and release the raw buffer.
Definition InputFrame.C:161
cv::Mat getCvRGB(bool casync=false) const
Shorthand to get the input image as a RGB cv::Mat and release the raw buffer.
Definition InputFrame.C:134
A raw image as coming from a V4L2 Camera and/or being sent out to a USB Gadget.
Definition RawImage.H:111
std::shared_ptr< VideoBuf > buf
The pixel data buffer.
Definition RawImage.H:149
cv::Mat convertToCvRGBA(RawImage const &src)
Convert RawImage to OpenCV doing color conversion from any RawImage source pixel to OpenCV RGB-A byte...
cv::Mat convertToCvGray(RawImage const &src)
Convert RawImage to OpenCV doing color conversion from any RawImage source pixel to OpenCV gray byte.
cv::Mat convertToCvRGB(RawImage const &src)
Convert RawImage to OpenCV doing color conversion from any RawImage source pixel to OpenCV RGB byte.
cv::Mat convertToCvBGR(RawImage const &src)
Convert RawImage to OpenCV doing color conversion from any RawImage source pixel to OpenCV BGR byte.