JeVoisBase  1.20
JeVois Smart Embedded Machine Vision Toolkit Base Modules
Share this page:
PythonOpenCV.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 import cv2
5 import numpy as np
6 
7 ## Simple example of image processing using OpenCV in Python on JeVois
8 #
9 # This module by default simply converts the input image to a grayscale OpenCV image, and then applies the Canny
10 # edge detection algorithm. Try to edit it to do something else (note that the videomapping associated with this
11 # module has grayscale image outputs, so that is what you should output).
12 #
13 # See http://jevois.org/tutorials for tutorials on getting started with programming JeVois in Python without having
14 # to install any development software on your host computer.
15 #
16 # @author Laurent Itti
17 #
18 # @displayname Python OpenCV
19 # @videomapping GRAY 640 480 20.0 YUYV 640 480 20.0 JeVois PythonOpenCV
20 # @email itti\@usc.edu
21 # @address University of Southern California, HNB-07A, 3641 Watt Way, Los Angeles, CA 90089-2520, USA
22 # @copyright Copyright (C) 2017 by Laurent Itti, iLab and the University of Southern California
23 # @mainurl http://jevois.org
24 # @supporturl http://jevois.org/doc
25 # @otherurl http://iLab.usc.edu
26 # @license GPL v3
27 # @distribution Unrestricted
28 # @restrictions None
29 # @ingroup modules
31  # ###################################################################################################
32  ## Constructor
33  def __init__(self):
34  # Instantiate a JeVois Timer to measure our processing framerate:
35  self.timer = jevois.Timer("canny", 100, jevois.LOG_INFO)
36 
37  # ###################################################################################################
38  ## Process function with no USB output
39  #def processNoUSB(self, inframe):
40  # jevois.LFATAL("process with no USB output not implemented yet in this module")
41 
42  # ###################################################################################################
43  ## Process function with USB output
44  def process(self, inframe, outframe):
45  # Get the next camera image (may block until it is captured) and convert it to OpenCV GRAY:
46  inimggray = inframe.getCvGRAY()
47 
48  # Start measuring image processing time (NOTE: does not account for input conversion time):
49  self.timer.start()
50 
51  # Detect edges using the Canny algorithm from OpenCV:
52  edges = cv2.Canny(inimggray, 100, 200, apertureSize = 3)
53 
54  # Write frames/s info from our timer into the edge map (NOTE: does not account for output conversion time):
55  fps = self.timer.stop()
56  height, width = edges.shape
57  cv2.putText(edges, fps, (3, height - 6), cv2.FONT_HERSHEY_SIMPLEX, 0.5, 255, 1, cv2.LINE_AA)
58 
59  # Convert our GRAY output image to video output format and send to host over USB:
60  outframe.sendCvGRAY(edges)
61 
62  # ###################################################################################################
63  ## Parse a serial command forwarded to us by the JeVois Engine, return a string
64  #def parseSerial(self, str):
65  # return "ERR: Unsupported command"
66 
67  # ###################################################################################################
68  ## Return a string that describes the custom commands we support, for the JeVois help message
69  #def supportedCommands(self):
70  # return ""
PythonOpenCV.PythonOpenCV
Simple example of image processing using OpenCV in Python on JeVois.
Definition: PythonOpenCV.py:30
PythonOpenCV.PythonOpenCV.timer
timer
Definition: PythonOpenCV.py:35
PythonOpenCV.PythonOpenCV.process
def process(self, inframe, outframe)
Process function with no USB output def processNoUSB(self, inframe): jevois.LFATAL("process with no U...
Definition: PythonOpenCV.py:44
PythonOpenCV.PythonOpenCV.__init__
def __init__(self)
Constructor.
Definition: PythonOpenCV.py:33
jevois::Timer