Skip to content

Commit

Permalink
Updated Python content to comply with PEP8 (via autopep8)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen Tramer committed Jul 1, 2019
1 parent 08dfd56 commit 5b8b269
Show file tree
Hide file tree
Showing 14 changed files with 398 additions and 317 deletions.
81 changes: 45 additions & 36 deletions modules/CameraCapture/app/AnnotationParser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#To make python 2 and python 3 compatible code
# To make python 2 and python 3 compatible code
from __future__ import absolute_import

#Returns rectangle boundaries in the CV2 format (topLeftX, topLeftY, bottomRightX, bottomRightY) given by a processing service
# Returns rectangle boundaries in the CV2 format (topLeftX, topLeftY, bottomRightX, bottomRightY) given by a processing service


class AnnotationParser:
def getCV2RectanglesFromProcessingService1(self, response):
try:
Expand All @@ -10,53 +12,60 @@ def getCV2RectanglesFromProcessingService1(self, response):
for decoration in item:
if "box" in decoration.lower():
rectList = item[decoration].split(",")
top = int(rectList[0])
left = int(rectList[1])
width = int(rectList[2])
height = int(rectList[3])
top = int(rectList[0])
left = int(rectList[1])
width = int(rectList[2])
height = int(rectList[3])
for decorationProperty in item[decoration]:
if "top" in decorationProperty.lower():
top = int(item[decoration][decorationProperty])
if "left" in decorationProperty.lower():
left = int(item[decoration][decorationProperty])
left = int(item[decoration]
[decorationProperty])
if "width" in decorationProperty.lower():
width = int(item[decoration][decorationProperty])
width = int(item[decoration]
[decorationProperty])
if "height" in decorationProperty.lower():
height = int(item[decoration][decorationProperty])
height = int(item[decoration]
[decorationProperty])
if top is not None and left is not None and width is not None and height is not None:
topLeftX = left
topLeftY = top
bottomRightX = left + width
bottomRightY = top + height
listOfCV2Rectangles.append([topLeftX, topLeftY, bottomRightX, bottomRightY])
listOfCV2Rectangles.append(
[topLeftX, topLeftY, bottomRightX, bottomRightY])
return listOfCV2Rectangles
except:
#Ignoring exceptions for now so that video can be read and analyzed without post-processing in case of errors
# Ignoring exceptions for now so that video can be read and analyzed without post-processing in case of errors
pass

def getCV2RectanglesFromProcessingService2(self, response):
try:
listOfCV2Rectangles = []
for item in response:
for decoration in item:
if "rect" in decoration.lower():
for decorationProperty in item[decoration]:
if "top" in decorationProperty.lower():
top = int(item[decoration][decorationProperty])
if "left" in decorationProperty.lower():
left = int(item[decoration][decorationProperty])
if "width" in decorationProperty.lower():
width = int(item[decoration][decorationProperty])
if "height" in decorationProperty.lower():
height = int(item[decoration][decorationProperty])
if top is not None and left is not None and width is not None and height is not None:
topLeftX = left
topLeftY = top
bottomRightX = left + width
bottomRightY = top + height
listOfCV2Rectangles.append([topLeftX, topLeftY, bottomRightX, bottomRightY])
return listOfCV2Rectangles
except:
#Ignoring exceptions for now so that video can be read and analyzed without post-processing in case of errors
pass

try:
listOfCV2Rectangles = []
for item in response:
for decoration in item:
if "rect" in decoration.lower():
for decorationProperty in item[decoration]:
if "top" in decorationProperty.lower():
top = int(item[decoration][decorationProperty])
if "left" in decorationProperty.lower():
left = int(item[decoration]
[decorationProperty])
if "width" in decorationProperty.lower():
width = int(item[decoration]
[decorationProperty])
if "height" in decorationProperty.lower():
height = int(item[decoration]
[decorationProperty])
if top is not None and left is not None and width is not None and height is not None:
topLeftX = left
topLeftY = top
bottomRightX = left + width
bottomRightY = top + height
listOfCV2Rectangles.append(
[topLeftX, topLeftY, bottomRightX, bottomRightY])
return listOfCV2Rectangles
except:
# Ignoring exceptions for now so that video can be read and analyzed without post-processing in case of errors
pass
Loading

1 comment on commit 5b8b269

@asergaz
Copy link

@asergaz asergaz commented on 5b8b269 Dec 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ebertrams with the changes of this commit I was having this error on Raspberry Pi 3 with stretch:

TypeError: 'module' object is not callable

Tracing back to CameraCapture.py line 134: self.vs = VideoStream(int(self.videoPath)).start()

I needed to use the file from here.

Please sign in to comment.