JeVoisBase  1.22
JeVois Smart Embedded Machine Vision Toolkit Base Modules
Share this page:
Loading...
Searching...
No Matches
PythonOpenCV.py
Go to the documentation of this file.
1import pyjevois
2if pyjevois.pro: import libjevoispro as jevois
3else: import libjevois as jevois
4import cv2
5import 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 ## Process function with GUI output on JeVois-Pro
64 def processGUI(self, inframe, helper):
65 # Start a new display frame, gets its size and also whether mouse/keyboard are idle:
66 idle, winw, winh = helper.startFrame()
67
68 # Draw full-resolution input frame from camera:
69 x, y, w, h = helper.drawInputFrame("c", inframe, False, False)
70 helper.itext('JeVois-Pro AprilTag detection')
71
72 # Get the next camera image as grayscale and lower resolution for processing (may block until it is captured):
73 ingray = inframe.getCvGRAYp()
74
75 # Start measuring image processing time (NOTE: does not account for input conversion time):
76 self.timer.start()
77
78 # Detect edges using the Canny algorithm from OpenCV:
79 edges = cv2.Canny(inimggray, 100, 200, apertureSize = 3)
80
81 # Draw edges as a transparent overlay using OpenGL. Here, our mask is just the edges replicated 4 times for the
82 # R, G, B, Alpha color channels:
83 mask = cv2.merge( [ edges, edges, edges, edges ] )
84 helper.drawImage("edges", mask, True, x, y, w, h, False, True);
85
86 # Write frames/s info from our timer:
87 fps = self.timer.stop()
88 helper.iinfo(inframe, fps, winw, winh);
89
90 # End of frame:
91 helper.endFrame()
92
93 # ###################################################################################################
94 ## Parse a serial command forwarded to us by the JeVois Engine, return a string
95 #def parseSerial(self, str):
96 # return "ERR: Unsupported command"
97
98 # ###################################################################################################
99 ## Return a string that describes the custom commands we support, for the JeVois help message
100 #def supportedCommands(self):
101 # return ""
Simple example of image processing using OpenCV in Python on JeVois.
processGUI(self, inframe, helper)
Process function with GUI output on JeVois-Pro.
process(self, inframe, outframe)
Process function with no USB output def processNoUSB(self, inframe): jevois.LFATAL("process with no U...
__init__(self)
Constructor.