JeVois
1.17
JeVois Smart Embedded Machine Vision Toolkit
|
Share this page: |
|
|
|
 |
 |
|
Go to the documentation of this file.
18 #include <boost/python.hpp>
37 #define PY_ARRAY_UNIQUE_SYMBOL pbcvt_ARRAY_API
42 #define JEVOIS_PYTHON_FUNC(funcname) \
43 boost::python::def(#funcname, jevois::funcname)
46 #define JEVOIS_PYTHON_RAWIMAGE_FUNC(funcname) \
47 boost::python::def(#funcname, jevois::rawimage::funcname)
50 #define JEVOIS_PYTHON_RAWIMAGE_ENUM_VAL(val) value(#val, jevois::rawimage::val)
53 #define JEVOIS_PYTHON_ENUM_VAL(val) value(#val, jevois::python::val)
56 #define JEVOIS_PYTHON_CONSTANT(cst) boost::python::scope().attr(#cst) = cst;
74 Py_SetProgramName(Py_DecodeLocale(
"",
nullptr));
98 void pythonSendSerial(std::string
const & str)
104 size_t pythonFrameNum()
110 void pythonWriteCamRegister(
unsigned short reg,
unsigned short val)
114 if (!cam)
LFATAL(
"Not using a Camera for video input");
115 cam->writeRegister(reg, val);
118 unsigned short pythonReadCamRegister(
unsigned short reg)
122 if (!cam)
LFATAL(
"Not using a Camera for video input");
123 return cam->readRegister(reg);
126 void pythonWriteIMUregister(
unsigned short reg,
unsigned short val)
130 if (!imu)
LFATAL(
"No IMU driver loaded");
131 imu->writeRegister(reg, val);
134 unsigned short pythonReadIMUregister(
unsigned short reg)
138 if (!imu)
LFATAL(
"No IMU driver loaded");
139 return imu->readRegister(reg);
142 void pythonWriteDMPregister(
unsigned short reg,
unsigned short val)
146 if (!imu)
LFATAL(
"No IMU driver loaded");
147 imu->writeDMPregister(reg, val);
150 unsigned short pythonReadDMPregister(
unsigned short reg)
154 if (!imu)
LFATAL(
"No IMU driver loaded");
155 return imu->readDMPregister(reg);
158 #ifdef JEVOIS_LDEBUG_ENABLE
159 void pythonLDEBUG(std::string
const & logmsg) {
LDEBUG(logmsg); }
161 void pythonLDEBUG(std::string
const & JEVOIS_UNUSED_PARAM(logmsg)) { }
163 void pythonLINFO(std::string
const & logmsg) {
LINFO(logmsg); }
164 void pythonLERROR(std::string
const & logmsg) {
LERROR(logmsg); }
165 void pythonLFATAL(std::string
const & logmsg) {
LFATAL(logmsg); }
183 BOOST_PYTHON_MODULE(libjevoispro)
185 BOOST_PYTHON_MODULE(libjevois)
189 boost::python::to_python_converter<cv::Mat, pbcvt::matToNDArrayBoostConverter>();
193 boost::python::def(
"sendSerial", pythonSendSerial);
194 boost::python::def(
"frameNum", pythonFrameNum);
195 boost::python::def(
"writeCamRegister", pythonWriteCamRegister);
196 boost::python::def(
"readCamRegister", pythonReadCamRegister);
197 boost::python::def(
"writeIMUregister", pythonWriteIMUregister);
198 boost::python::def(
"readIMUregister", pythonReadIMUregister);
199 boost::python::def(
"writeDMPregister", pythonWriteDMPregister);
200 boost::python::def(
"readDMPregister", pythonReadDMPregister);
208 boost::python::def(
"LDEBUG", pythonLDEBUG);
209 boost::python::def(
"LINFO", pythonLINFO);
210 boost::python::def(
"LERROR", pythonLERROR);
211 boost::python::def(
"LFATAL", pythonLFATAL);
227 void (*
imgToStd2)(
float & x,
float & y,
unsigned int const width,
unsigned int const height,
float const eps) =
229 boost::python::def(
"imgToStd",
imgToStd1);
230 boost::python::def(
"imgToStd",
imgToStd2);
233 void (*
stdToImg2)(
float & x,
float & y,
unsigned int const width,
unsigned int const height,
float const eps) =
235 boost::python::def(
"stdToImg",
stdToImg1);
236 boost::python::def(
"stdToImg",
stdToImg2);
244 boost::python::class_<jevois::RawImage>(
"RawImage")
260 boost::python::enum_<jevois::python::YUYV>(
"YUYV")
261 .JEVOIS_PYTHON_ENUM_VAL(
Black)
263 .JEVOIS_PYTHON_ENUM_VAL(
MedGrey)
265 .JEVOIS_PYTHON_ENUM_VAL(
White)
270 .JEVOIS_PYTHON_ENUM_VAL(
MedTeal)
276 .JEVOIS_PYTHON_ENUM_VAL(
MedPink)
288 boost::python::class_<jevois::InputFramePython>(
"InputFrame")
290 boost::python::return_value_policy<boost::python::reference_existing_object>())
292 boost::python::return_value_policy<boost::python::reference_existing_object>())
295 boost::python::return_value_policy<boost::python::reference_existing_object>())
297 boost::python::return_value_policy<boost::python::reference_existing_object>())
299 boost::python::return_value_policy<boost::python::reference_existing_object>())
301 boost::python::return_value_policy<boost::python::reference_existing_object>())
319 boost::python::class_<jevois::OutputFramePython>(
"OutputFrame")
321 boost::python::return_value_policy<boost::python::reference_existing_object>())
362 void (*drawRect2)(
jevois::RawImage & img,
int x,
int y,
unsigned int w,
unsigned int h,
unsigned int col) =
364 boost::python::def(
"drawRect", drawRect1);
365 boost::python::def(
"drawRect", drawRect2);
368 boost::python::enum_<jevois::rawimage::Font>(
"Font")
369 .JEVOIS_PYTHON_RAWIMAGE_ENUM_VAL(
Font5x7)
370 .JEVOIS_PYTHON_RAWIMAGE_ENUM_VAL(
Font6x10)
371 .JEVOIS_PYTHON_RAWIMAGE_ENUM_VAL(
Font7x13)
374 .JEVOIS_PYTHON_RAWIMAGE_ENUM_VAL(
Font10x20)
375 .JEVOIS_PYTHON_RAWIMAGE_ENUM_VAL(
Font11x22)
376 .JEVOIS_PYTHON_RAWIMAGE_ENUM_VAL(
Font12x22)
377 .JEVOIS_PYTHON_RAWIMAGE_ENUM_VAL(
Font14x26)
378 .JEVOIS_PYTHON_RAWIMAGE_ENUM_VAL(
Font15x28)
379 .JEVOIS_PYTHON_RAWIMAGE_ENUM_VAL(
Font16x29)
380 .JEVOIS_PYTHON_RAWIMAGE_ENUM_VAL(
Font20x38);
382 void (*writeText1)(
jevois::RawImage & img, std::string
const & txt,
int x,
int y,
384 boost::python::def(
"writeText", writeText1);
402 boost::python::class_<jevois::Timer>(
"Timer", boost::python::init<char const *, size_t, int>())
404 .def(
"stop", timer_stop, boost::python::return_value_policy<boost::python::copy_const_reference>());
407 boost::python::class_<jevois::Profiler>(
"Profiler", boost::python::init<char const *, size_t, int>())
410 .def(
"stop", &
jevois::Profiler::stop, boost::python::return_value_policy<boost::python::copy_const_reference>());
419 boost::python::class_<ImVec2>(
"ImVec2");
420 boost::python::class_<ImColor>(
"ImColor");
422 boost::python::class_<jevois::GUIhelperPython>(
"GUIhelper")
void convertBayerToYUYV(RawImage const &src, RawImage &dst)
Convert from Bayer to YUYV, only used internally by Camera class.
unsigned int whiteColor(unsigned int fcc)
Return a value that corresponds to white for the given video format.
void sendScaledCvGRAY(cv::Mat const &img) const
Shorthand to send a GRAY cv::Mat after scaling/converting it to the current output format.
void drawDisk(RawImage &img, int x, int y, unsigned int rad, unsigned int col)
Draw a disk in a YUYV image.
void convertCvRGBAtoCvYUYV(cv::Mat const &src, cv::Mat &dst)
OpenCV does not provide conversion from RGBA to YUYV in cvtColor(), so this function provides it.
void imgToStdY(float &y, unsigned int const height, float const eps=0.1F)
Transform Y coordinate in-place from camera to standardized, using given image width and height.
void iinfo(jevois::InputFramePython const &inframe, std::string const &fpscpu, unsigned short winw=0, unsigned short winh=0)
Display processing and video info at bottom of screen.
unsigned int bytesperpix() const
Helper function to get the number of bytes/pixel given the RawImage pixel format.
void clear()
Clear the pixels to all black.
void convertCvRGBtoCvYUYV(cv::Mat const &src, cv::Mat &dst)
OpenCV does not provide conversion from RGB to YUYV in cvtColor(), so this function provides it.
void stdToImgSize(float &x, float &y, unsigned int const width, unsigned int const height, float const eps=0.1F)
Transform size in-place from standardized to image, using a RawImage to establish image size.
#define LDEBUG(msg)
Convenience macro for users to print out console or syslog messages, DEBUG level.
void(* stdToImg1)(float &x, float &y, jevois::RawImage const &camimg, float const eps)
Converter from Python numpy NDarray to cv::Mat.
void sendCv1(cv::Mat const &img, int quality) const
Shorthand to send a cv::Mat after scaling/converting it to the current output format.
boost::python::tuple drawImage1(char const *name, cv::Mat const &img, bool rgb, bool noalias=false, bool isoverlay=false)
Draw an OpenCV image, copying pixel data to an OpenGL texture.
cv::Mat rescaleCv(cv::Mat const &img, cv::Size const &newdims)
Rescale an OpenCV image, choosing the right kind of interpolation.
void convertCvRGBtoRawImage(cv::Mat const &src, RawImage &dst, int quality)
Convert a RGB cv::Mat to RawImage with already-allocated pixels and pixel type.
unsigned int cvBytesPerPix(unsigned int cvtype)
Return the number of bytes per pixel for a given OpenCV pixel type.
void flushcache()
Flush the caches, may sometimes be useful when running the camera in turbo mode.
const RawImage & get() const
Get the next captured camera image.
void drawPoly(std::vector< cv::Point > const &pts, ImU32 col=IM_COL32(128, 255, 128, 255), bool filled=true)
Draw polygon over an image.
std::string getSysInfoMem()
Get memory info.
void checkpoint(char const *description)
Note the time for a particular event.
std::string cvtypestr(unsigned int cvtype)
Convert cv::Mat::type() code to to a string (e.g., CV_8UC1, CV_32SC3, etc)
void itext(char const *txt, ImU32 const &col=IM_COL32_BLACK_TRANS, int line=-1)
Draw some overlay text on top of an image.
void send() const
Indicate that user processing is done with the image previously obtained via get()
unsigned int bytesize() const
Helper function to get the total number of bytes in the RawImage, i.e., width * height * bytesperpix(...
cv::Mat convertToCvRGB(RawImage const &src)
Convert RawImage to OpenCV doing color conversion from any RawImage source pixel to OpenCV RGB byte.
std::shared_ptr< Camera > camera() const
Get a pointer to our Camera (may be null, especially if not using a camera but, eg,...
ImVec2 iline(int line=-1, char const *name=nullptr)
Get coordinates of the start of a given line of text to be drawn as overlay on top of an image.
Font
Available fonts for writeText()
void(* stdToImg2)(float &x, float &y, unsigned int const width, unsigned int const height, float const eps)
A raw image as coming from a V4L2 Camera and/or being sent out to a USB Gadget.
void imgToStdSize(float &w, float &h, unsigned int const width, unsigned int const height, float const eps=0.1F)
Transform size in-place from camera to standardized, using given image width and height.
void sendScaledCvRGBA1(cv::Mat const &img, int quality) const
Shorthand to send a RGBA cv::Mat after scaling/converting it to the current output format.
void drawCircle(RawImage &img, int x, int y, unsigned int rad, unsigned int thick, unsigned int col)
Draw a circle in a YUYV image.
void start()
Start a time measurement period.
unsigned int blackColor(unsigned int fcc)
Return a value that corresponds to black for the given video format.
cv::Mat convertToCvBGR(RawImage const &src)
Convert RawImage to OpenCV doing color conversion from any RawImage source pixel to OpenCV BGR byte.
void drawPoly1(std::vector< cv::Point2f > const &pts, ImU32 col=IM_COL32(128, 255, 128, 255), bool filled=true)
Draw polygon over an image.
float fps
Programmed frames/s as given by current video mapping, may not be actual.
bool valid() const
Check whether the image has a valid pixel buffer.
bool frameStarted() const
Helper to indicate that startFrame() was called, and thus endFrame() should be called.
void endFrame()
Finish current frame and render it.
#define LERROR(msg)
Convenience macro for users to print out console or syslog messages, ERROR level.
cv::Mat convertToCvGray(RawImage const &src)
Convert RawImage to OpenCV doing color conversion from any RawImage source pixel to OpenCV gray byte.
void invalidate()
Invalidate the image by zero'ing out the pointer to pixel buffer and the dims and format.
void imgToStdX(float &x, unsigned int const width, float const eps=0.1F)
Transform X coordinate in-place from camera to standardized, using given image width and height.
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.
void sendScaledCvRGB1(cv::Mat const &img, int quality) const
Shorthand to send a RGB cv::Mat after scaling/converting it to the current output format.
void drawText(float x, float y, char const *txt, ImU32 col=IM_COL32(128, 255, 128, 255))
Draw text over an image.
std::string getSysInfoVersion()
Get O.S. version info.
void roipaste(RawImage const &src, int x, int y, unsigned int w, unsigned int h, RawImage &dest, int dx, int dy)
Paste an ROI from an image to within another of same pixel type.
unsigned int width
Image width in pixels.
const std::string & stop()
Same as the other signature of stop() except does not provide seconds, for python bindings.
void releaseImage2(char const *name)
Release an image, second video stream.
void writeText(RawImage &img, std::string const &txt, int x, int y, unsigned int col, Font font=Font6x10)
Write some text in an image.
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 getSysInfoCPU()
Get CPU info: frequency, thermal, load.
boost::python::tuple startFrame()
Start a new rendering frame.
void sendCvGRAY1(cv::Mat const &img, int quality) const
Shorthand to send a GRAY cv::Mat after converting it to the current output format.
std::string system(std::string const &cmd, bool errtoo=true)
Execute a command and grab stdout output to a string.
void stdToImg(float &x, float &y, RawImage const &camimg, float const eps=0.1F)
Transform coordinates in-place from standardized to image, using a RawImage to establish image size.
void sendCvRGBA(cv::Mat const &img) const
Shorthand to send a RGBA cv::Mat after converting it to the current output format.
void sendCvRGB1(cv::Mat const &img, int quality) const
Shorthand to send a RGB cv::Mat after converting it to the current output format.
unsigned int v4l2BytesPerPix(unsigned int fcc)
Return the number of bytes per pixel for a given V4L2_PIX_FMT_...
void reportAndIgnoreException(std::string const &prefix="")
Report current exception in a modal dialog, then ignore it.
boost::python::tuple drawImage(char const *name, RawImage const &img, bool noalias=false, bool isoverlay=false)
Draw a RawImage, copying pixel data to an OpenGL texture.
ImVec2 i2ds1(float x, float y, char const *name=nullptr)
Convert a 2D size from within a rendered image to on-screen.
#define JEVOIS_PYTHON_CONSTANT(cst)
void drawPoly2(cv::Mat const &pts, ImU32 col=IM_COL32(128, 255, 128, 255), bool filled=true)
Draw polygon over an image.
Engine * engineForPythonModule
ImVec2 i2d1(float x, float y, char const *name=nullptr)
Convert coordinates of a point from within a rendered image to on-screen.
std::string fccstr(unsigned int fcc)
Convert a V4L2 four-cc code (V4L2_PIX_FMT_...) to a 4-char string.
JeVois processing engine - gets images from camera sensor, processes them, and sends results over USB...
void drawFilledRect(RawImage &img, int x, int y, unsigned int w, unsigned int h, unsigned int col)
Draw a filled rectangle in a YUYV image.
void sendScaledCvGRAY1(cv::Mat const &img, int quality) const
Shorthand to send a GRAY cv::Mat after scaling/converting it to the current output format.
void sendScaledCvRGBA(cv::Mat const &img) const
Shorthand to send a RGBA cv::Mat after scaling/converting it to the current output format.
void hFlipYUYV(RawImage &img)
Flip a YUYV RawImage horizontally while preserving color information.
void convertCvRGBAtoRawImage(cv::Mat const &src, RawImage &dst, int quality)
Convert an RGBA cv::Mat to RawImage with already-allocated pixels and pixel type.
#define LFATAL(msg)
Convenience macro for users to print out console or syslog messages, FATAL level.
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 unpackCvRGBAtoGrayRawImage(cv::Mat const &src, RawImage &dst)
Split an RGBA cv::Mat into a 4x taller grey RawImage with already-allocated pixels.
#define JEVOIS_PYTHON_FUNC(funcname)
ImVec2 i2ds(ImVec2 p, char const *name=nullptr)
Convert a 2D size from within a rendered image to on-screen.
void sendScaledCvRGB(cv::Mat const &img) const
Shorthand to send a RGB cv::Mat after scaling/converting it to the current output format.
std::shared_ptr< IMU > imu() const
Get a pointer to our IMU (may be null)
void sendCvRGB(cv::Mat const &img) const
Shorthand to send a RGB cv::Mat after converting it to the current output format.
unsigned int height
Image height in pixels.
void start()
Start a time measurement period.
void imgToStd(float &x, float &y, RawImage const &camimg, float const eps=0.1F)
Transform coordinates in-place from camera to standardized, using a RawImage to establish image size.
void drawRect(float x1, float y1, float x2, float y2, ImU32 col=IM_COL32(128, 255, 128, 255), bool filled=true)
Draw rectangular box over an image.
bool coordsOk(int x, int y) const
Helper function to check that coords are within image bounds.
void sendScaledCvBGR1(cv::Mat const &img, int quality) const
Shorthand to send a BGR cv::Mat after scaling/converting it to the current output format.
cv::Mat cvImage(RawImage const &src)
Create an OpenCV image from the existing RawImage data, sharing the pixel memory rather than copying ...
void releaseImage(char const *name)
Release an image.
void sendCvRGBA1(cv::Mat const &img, int quality) const
Shorthand to send a RGBA cv::Mat after converting it to the current output format.
void sendCvBGR(cv::Mat const &img) const
Shorthand to send a BGR cv::Mat after converting it to the current output format.
#define JEVOIS_PYTHON_RAWIMAGE_FUNC(funcname)
void paste(RawImage const &src, RawImage &dest, int dx, int dy)
Paste an image within another of same pixel type.
size_t frameNum() const
Get frame number.
void drawRect(RawImage &img, int x, int y, unsigned int w, unsigned int h, unsigned int thick, unsigned int col)
Draw a rectangle in a YUYV image.
unsigned int fmt
Pixel format as a V4L2_PIX_FMT_XXX.
unsigned int v4l2ImageSize(unsigned int fcc, unsigned int width, unsigned int height)
Return the image size in bytes for a given V4L2_PIX_FMT_..., width, height.
void(* imgToStd1)(float &x, float &y, jevois::RawImage const &camimg, float const eps)
void drawLine(float x1, float y1, float x2, float y2, ImU32 col=IM_COL32(128, 255, 128, 255))
Draw line over an image.
void stop()
End a time measurement period, report time spent for each checkpoint if reporting interval is reached...
cv::Mat convertToCvRGBA(RawImage const &src)
Convert RawImage to OpenCV doing color conversion from any RawImage source pixel to OpenCV RGB-A byte...
boost::python::tuple drawInputFrame(char const *name, InputFramePython const &frame, bool noalias=false, bool casync=false)
Draw the input video frame from the camera using zero-copy.
void sendSerial(std::string const &str, bool islog=false)
Send a string to all serial ports.
ImVec2 i2d(ImVec2 p, char const *name=nullptr)
Convert coordinates of a point from within a rendered image to on-screen.
void convertCvBGRtoCvYUYV(cv::Mat const &src, cv::Mat &dst)
OpenCV does not provide conversion from BGR to YUYV in cvtColor(), so this function provides it.
void drawCircle(float x, float y, float r, ImU32 col=IM_COL32(128, 255, 128, 255), bool filled=true)
Draw circle over an image.
void drawLine(RawImage &img, int x1, int y1, int x2, int y2, unsigned int thick, unsigned int col)
Draw a line in a YUYV image.
boost::python::tuple drawInputFrame2(char const *name, InputFramePython const &frame, bool noalias=false, bool casync=false)
Draw the second (scaled) input video frame from the camera using zero-copy.
void sendCv(cv::Mat const &img) const
Shorthand to send a cv::Mat after scaling/converting it to the current output format.
unsigned int strfcc(std::string const &str)
Convert a JeVois video format string to V4L2 four-cc code (V4L2_PIX_FMT_...)
void pasteGreyToYUYV(cv::Mat const &src, RawImage &dest, int dx, int dy)
Paste a grey byte image into a YUYV image.
#define LINFO(msg)
Convenience macro for users to print out console or syslog messages, INFO level.
void convertGreyToYUYV(RawImage const &src, RawImage &dst)
Convert from Grey (monochrome) to YUYV, only used internally by Camera class.
void reportAndRethrowException(std::string const &prefix="")
Report current exception in a modal dialog, then re-throw it.
void(* imgToStd2)(float &x, float &y, unsigned int const width, unsigned int const height, float const eps)
void byteSwap(RawImage &img)
Swap pairs of bytes in a RawImage.
void convertCvGRAYtoCvYUYV(cv::Mat const &src, cv::Mat &dst)
OpenCV does not provide conversion from GRAY to YUYV in cvtColor(), so this function provides it.
void reportError(std::string const &err)
Report an error in an overlay window.
void sendCvGRAY(cv::Mat const &img) const
Shorthand to send a GRAY cv::Mat after converting it to the current output format.
void sendScaledCvBGR(cv::Mat const &img) const
Shorthand to send a BGR cv::Mat after scaling/converting it to the current output format.
void sendCvBGR1(cv::Mat const &img, int quality) const
Shorthand to send a BGR cv::Mat after converting it to the current output format.