JeVois  1.20
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
PythonTutorial3.py
Go to the documentation of this file.
1 import libjevois as jevois
2 
3 ## Simple test of programming JeVois modules in Python
4 #
5 # This module by default simply draws a cricle and a text message onto the grabbed video frames.
6 #
7 # Feel free to edit it and try something else. Note that this module does not import OpenCV, see the PythonOpenCV for a
8 # minimal JeVois module written in Python that uses OpenCV.
9 #
10 # @author Laurent Itti
11 #
12 # @displayname Python Tutorial 3
13 # @videomapping YUYV 640 480 15.0 YUYV 640 480 15.0 JeVois PythonTutorial3
14 # @email itti\@usc.edu
15 # @address University of Southern California, HNB-07A, 3641 Watt Way, Los Angeles, CA 90089-2520, USA
16 # @copyright Copyright (C) 2017 by Laurent Itti, iLab and the University of Southern California
17 # @mainurl http://jevois.org
18 # @supporturl http://jevois.org/doc
19 # @otherurl http://iLab.usc.edu
20 # @license GPL v3
21 # @distribution Unrestricted
22 # @restrictions None
23 # @ingroup modules
25  # ###################################################################################################
26  ## Constructor
27  def __init__(self):
28  jevois.LINFO("PythonTest Constructor")
29  jevois.LINFO(dir(jevois))
30  self.frame = 0 # a simple frame counter used to demonstrate sendSerial()
31 
32  # ###################################################################################################
33  ## Process function with no USB output
34  def processNoUSB(self, inframe):
35  jevois.LFATAL("process no usb not implemented")
36 
37  # ###################################################################################################
38  ## Process function with USB output
39  def process(self, inframe, outframe):
40  jevois.LINFO("process with usb")
41 
42  # Get the next camera image (may block until it is captured):
43  inimg = inframe.get()
44  jevois.LINFO("Input image is {} {}x{}".format(jevois.fccstr(inimg.fmt), inimg.width, inimg.height))
45 
46  # Get the next available USB output image:
47  outimg = outframe.get()
48  jevois.LINFO("Output image is {} {}x{}".format(jevois.fccstr(outimg.fmt), outimg.width, outimg.height))
49 
50  # Example of getting pixel data from the input and copying to the output:
51  jevois.paste(inimg, outimg, 0, 0)
52 
53  # We are done with the input image:
54  inframe.done()
55 
56  # Example of in-place processing:
57  jevois.hFlipYUYV(outimg)
58 
59  # Example of simple drawings:
60  jevois.drawCircle(outimg, int(outimg.width/2), int(outimg.height/2), int(outimg.height/2.2), 2, 0x80ff)
61  jevois.writeText(outimg, "Hi from Python!", 20, 20, 0x80ff, jevois.Font.Font10x20)
62 
63  # We are done with the output, ready to send it to host over USB:
64  outframe.send()
65 
66  # Send a string over serial (e.g., to an Arduino). Remember to tell the JeVois Engine to display those messages,
67  # as they are turned off by default. For example: 'setpar serout All' in the JeVois console:
68  jevois.sendSerial("DONE frame {}".format(self.frame));
69  self.frame += 1
70 
71  # ###################################################################################################
72  ## Parse a serial command forwarded to us by the JeVois Engine, return a string
73  def parseSerial(self, str):
74  jevois.LINFO("parseserial received command [{}]".format(str))
75  if str == "hello":
76  return self.hello()
77  return "ERR Unsupported command"
78 
79  # ###################################################################################################
80  ## Return a string that describes the custom commands we support, for the JeVois help message
81  def supportedCommands(self):
82  # use \n seperator if your module supports several commands
83  return "hello - print hello using python"
84 
85  # ###################################################################################################
86  ## Internal method that gets invoked as a custom command
87  def hello(self):
88  return "Hello from python!"
89 
PythonTutorial3.PythonTTutorial3.parseSerial
def parseSerial(self, str)
Parse a serial command forwarded to us by the JeVois Engine, return a string.
Definition: PythonTutorial3.py:73
PythonTutorial3.PythonTTutorial3.processNoUSB
def processNoUSB(self, inframe)
Process function with no USB output.
Definition: PythonTutorial3.py:34
PythonTutorial3.PythonTTutorial3
Simple test of programming JeVois modules in Python.
Definition: PythonTutorial3.py:24
PythonTutorial3.PythonTTutorial3.hello
def hello(self)
Internal method that gets invoked as a custom command.
Definition: PythonTutorial3.py:87
PythonTutorial3.PythonTTutorial3.__init__
def __init__(self)
Constructor.
Definition: PythonTutorial3.py:27
jevois::fccstr
std::string fccstr(unsigned int fcc)
Convert a V4L2 four-cc code (V4L2_PIX_FMT_...) to a 4-char string.
Definition: Utils.C:45
PythonTutorial3.PythonTTutorial3.supportedCommands
def supportedCommands(self)
Return a string that describes the custom commands we support, for the JeVois help message.
Definition: PythonTutorial3.py:81
PythonTutorial3.PythonTTutorial3.process
def process(self, inframe, outframe)
Process function with USB output.
Definition: PythonTutorial3.py:39
PythonTutorial3.PythonTTutorial3.frame
frame
Definition: PythonTutorial3.py:30