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