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