Skip to content

Commit

Permalink
speedup captureFrame by passing in cv2image object, so I don't need t…
Browse files Browse the repository at this point in the history
…o rotate np matrix
  • Loading branch information
John Sun committed Apr 7, 2014
1 parent e996289 commit c136cca
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions SimpleCV/Camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -3765,7 +3765,7 @@ def _captureFrame(self, timeout = 2000):
f = self._getFrame()

rgbcv2type = cv2.COLOR_BAYER_RG2RGB
colorSpace = ColorSpace.RGB
colorSpace = ColorSpace.BGR
if self.pixelformat == 'Mono8':
rgbcv2type = cv2.COLOR_BAYER_RG2RGB
colorSpace = ColorSpace.GRAY
Expand All @@ -3779,17 +3779,16 @@ def _captureFrame(self, timeout = 2000):
except Exception, e:
print "Exception waiting for frame: %s: %s" % (e, traceback.format_exc())
raise(e)

moreUsefulImgData = np.ndarray(buffer = f.getBufferByteData(),
dtype = np.uint8,
shape = (f.height, f.width, 1))

imgData = f.getBufferByteData()
moreUsefulImgData = np.ndarray(buffer = imgData,
dtype = np.uint8,
shape = (f.height, f.width, 1))

rgb = cv2.cvtColor(moreUsefulImgData, rgbcv2type)
c.endCapture()

# Have to rotate it by 90 degrees and flip when returning it as an "Image"
rgb = np.flipud(np.rot90(rgb))
return Image(rgb, colorSpace=colorSpace)
return Image(rgb, colorSpace=colorSpace, cv2image=imgData)

except Exception, e:
print "Exception acquiring frame: %s: %s" % (e, traceback.format_exc())
Expand Down

0 comments on commit c136cca

Please sign in to comment.