- refactored resolution

git-svn-id: http://moon:8086/svn/software/trunk/projects/opencv@334 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
2016-10-22 13:14:30 +00:00
parent 176b58d9cc
commit 8981a95af6
4 changed files with 30 additions and 29 deletions
+5 -4
View File
@@ -91,6 +91,7 @@ class MyRgbProcess(RgbProcess):
if not self.isVisible:
print ("Visible")
self.isVisible = True
print(maxLoc)
img1_objects = cv2.rectangle(img1_objects,rect[0],rect[1],(255,0,0),1)
errorX = float(x)-self.res[0]/2
errorY = float(y)-self.res[1]/2
@@ -126,8 +127,8 @@ if with_ev3:
# Connect to brick
with ev3.EV3() as brick:
videoSource = VideoSource(videoFile, (width,height,3), framerate)
proc = MyRgbProcess('MyRgbProcess', (height, width, 3), 4, brick=brick)
videoSource = VideoSource(videoFile, (width, height,3), framerate)
proc = MyRgbProcess('MyRgbProcess', (width, height, 3), 4, brick=brick)
videoSource.processorAdd(proc)
videoSource.start()
@@ -136,8 +137,8 @@ if with_ev3:
videoSource.stop()
proc.stop()
else:
videoSource = VideoSource(videoFile, (width,height,3), framerate)
proc = MyRgbProcess('MyRgbProcess', (height, width, 3), 4)
videoSource = VideoSource(videoFile, (width, height,3), framerate)
proc = MyRgbProcess('MyRgbProcess', (width, height, 3), 4)
videoSource.processorAdd(proc)
videoSource.start()
+13 -13
View File
@@ -60,10 +60,10 @@ class Fifo(object):
return data
class RgbProcess(Fifo):
def __init__(self, name='RgbProcess', resolution=(320, 240, 3), numEntries=2, next=None):
super(RgbProcess, self).__init__((numEntries, ) + resolution)
def __init__(self, name='RgbProcess', res=(320, 240, 3), numEntries=2, next=None):
super(RgbProcess, self).__init__((numEntries, res[1], res[0], res[2]))
self.name = name
self.res = resolution
self.res = res
self.next = next
self.thread = Thread(target=self.run)
self.cancel = False
@@ -136,9 +136,9 @@ class RgbProcess(Fifo):
print(self.name + ": FPS = " + str(self.frames/self.fps.elapsed()))
class RgbProcessorAdapter(object):
def __init__(self, resolution=(320, 240, 3)):
self.resolution = resolution
self.frameSize = resolution[0]*resolution[1]*resolution[2]
def __init__(self, res=(320, 240, 3)):
self.res = res
self.frameSize = res[0]*res[1]*res[2]
self.size = 0
self.fps = None
self.processors = []
@@ -161,7 +161,7 @@ class RgbProcessorAdapter(object):
self.fps = FPS().start()
res = (self.resolution[0], self.resolution[1])
res = (self.res[0], self.res[1])
if self.needRgbConversion:
rgbData = array.bytes_to_rgb(data, res)
@@ -190,8 +190,8 @@ if ("__main__" == __name__):
# Unit test with to threaded processors
class MyRgbProcess1(RgbProcess):
def __init__(self, name, resolution=(320, 240, 3), numEntries=2, next=None):
super(MyRgbProcess1, self).__init__(name, resolution, numEntries, next)
def __init__(self, name, res=(320, 240, 3), numEntries=2, next=None):
super(MyRgbProcess1, self).__init__(name, res, numEntries, next)
def onProcess(self):
data = self.read(1.0)
@@ -206,8 +206,8 @@ if ("__main__" == __name__):
self.next.write(cv2.cvtColor(gray_blurred,cv2.COLOR_GRAY2BGR))
class MyRgbProcess2(RgbProcess):
def __init__(self, name, resolution=(320, 240, 3), numEntries=2, next=None):
super(MyRgbProcess2, self).__init__(name, resolution, numEntries, next)
def __init__(self, name, res=(320, 240, 3), numEntries=2, next=None):
super(MyRgbProcess2, self).__init__(name, res, numEntries, next)
def onProcess(self):
data = self.read(1.0)
@@ -224,8 +224,8 @@ if ("__main__" == __name__):
camera.resolution = (320, 240)
camera.framerate = 60
frameDim = (camera.resolution[0], camera.resolution[1], 3)
myProcessor2 = MyRgbProcess2('Process 2', (240, 320, 3), 4)
myProcessor1 = MyRgbProcess1('Process 1', (240, 320, 3), 4, myProcessor2)
myProcessor2 = MyRgbProcess2('Process 2', (320, 240, 3), 4)
myProcessor1 = MyRgbProcess1('Process 1', (320, 240, 3), 4, myProcessor2)
myRgbProcessorAdapter = RgbProcessorAdapter(frameDim)
myRgbProcessorAdapter.processorAdd(myProcessor1)
camera.start_recording(myRgbProcessorAdapter, format="bgr")
+6 -6
View File
@@ -6,17 +6,17 @@ from picamera import PiCamera
from piCameraPipeline.PiCameraPipeline import RgbProcessorAdapter
class VideoSource(RgbProcessorAdapter):
def __init__(self, fileName, resolution, framerate):
super(VideoSource, self).__init__(resolution)
def __init__(self, fileName, res, framerate):
super(VideoSource, self).__init__(res)
self.fileName = fileName
self.resolution = resolution
self.res = res
self.framerate = framerate
self.thread = None
self.camera = None
self.cancel = False
if fileName == 'piCamera':
self.camera = PiCamera()
self.camera.resolution = (self.resolution[0], self.resolution[1])
self.camera.resolution = (self.res[0], self.res[1])
self.camera.framerate = self.framerate
else:
self.needRgbConversion = False
@@ -45,14 +45,14 @@ class VideoSource(RgbProcessorAdapter):
cap_w = cap.get(cv2.CAP_PROP_FRAME_WIDTH)
cap_h = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
needResize = False
if self.resolution[0] != cap_w or self.resolution[1] != cap_h:
if self.res[0] != cap_w or self.res[1] != cap_h:
needResize = True
while not self.cancel:
ret, frame = cap.read()
if ret:
if needResize:
self.write(imutils.resize(frame, width=self.resolution[0], height=self.resolution[1]))
self.write(imutils.resize(frame, width=self.res[0], height=self.res[1]))
else:
self.write(frame)
else:
+6 -6
View File
@@ -10,8 +10,8 @@ if ("__main__" == __name__):
# Unit test with to threaded processors
class MyRgbProcess1(RgbProcess):
def __init__(self, name, resolution=(320, 240, 3), numEntries=2, next=None):
super(MyRgbProcess1, self).__init__(name, resolution, numEntries, next)
def __init__(self, name, res=(320, 240, 3), numEntries=2, next=None):
super(MyRgbProcess1, self).__init__(name, res, numEntries, next)
def onProcess(self):
data = self.read(1.0)
@@ -26,8 +26,8 @@ if ("__main__" == __name__):
self.next.write(cv2.cvtColor(gray_blurred,cv2.COLOR_GRAY2BGR))
class MyRgbProcess2(RgbProcess):
def __init__(self, name, resolution=(320, 240, 3), numEntries=2, next=None):
super(MyRgbProcess2, self).__init__(name, resolution, numEntries, next)
def __init__(self, name, res=(320, 240, 3), numEntries=2, next=None):
super(MyRgbProcess2, self).__init__(name, res, numEntries, next)
def onProcess(self):
data = self.read(1.0)
@@ -44,8 +44,8 @@ if ("__main__" == __name__):
camera.resolution = (320, 240)
camera.framerate = 60
frameDim = (camera.resolution[0], camera.resolution[1], 3)
myProcessor2 = MyRgbProcess2('Process 2', (240, 320, 3), 4)
myProcessor1 = MyRgbProcess1('Process 1', (240, 320, 3), 4, myProcessor2)
myProcessor2 = MyRgbProcess2('Process 2', (320, 240, 3), 4)
myProcessor1 = MyRgbProcess1('Process 1', (320, 240, 3), 4, myProcessor2)
myRgbProcessorAdapter = RgbProcessorAdapter(frameDim)
myRgbProcessorAdapter.processorAdd(myProcessor1)
camera.start_recording(myRgbProcessorAdapter, format="bgr")