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