本文整理汇总了Python中VideoCapture.Device.getBuffer方法的典型用法代码示例。如果您正苦于以下问题:Python Device.getBuffer方法的具体用法?Python Device.getBuffer怎么用?Python Device.getBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VideoCapture.Device
的用法示例。
在下文中一共展示了Device.getBuffer方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: videoCaptureStart
# 需要导入模块: from VideoCapture import Device [as 别名]
# 或者: from VideoCapture.Device import getBuffer [as 别名]
def videoCaptureStart(fromIP):
cam = Device()
buffers,width,height = cam.getBuffer()
packData(buffers[0:MESSAGE_SIZE], 5, fromIP)
packData(buffers[MESSAGE_SIZE:], 6, fromIP)
while conversationWindow[fromIP]['VIDEO_CAPTURE_FLAG']:
buffers,width,height = cam.getBuffer()
packData(buffers[0:MESSAGE_SIZE], 7, fromIP)
packData(buffers[MESSAGE_SIZE:], 6, fromIP)
packData(buffers, 8, fromIP)
示例2: VCCamera
# 需要导入模块: from VideoCapture import Device [as 别名]
# 或者: from VideoCapture.Device import getBuffer [as 别名]
class VCCamera():
## __init__
#
# @param camera_num (Optional) The camera number, defaults to 0.
# @param xmin (Optional) The x position of the start of the ROI, defaults to 0.
# @param xmax (Optional) The x position of the end of the ROI, defaults to 150.
# @param ymin (Optional) The y position of the start of the ROI, defaults to 0.
# @param ymax (Optional) The y position of the end of the ROI, defaults to 300.
#
def __init__(self, camera_num = 0, xmin = 0, xmax = 150, ymin = 0, ymax = 300):
self.xmin = xmin
self.xmax = xmax
self.ymin = ymin
self.ymax = ymax
self.cam = Device(devnum = camera_num)
## capture
#
# @return The current camera image as a numpy uint8 array.
#
def capture(self):
# These do the same thing, but the second one is much faster..
if 0:
image = self.cam.getImage()
data = numpy.array(image.getdata(), numpy.uint8).reshape(image.size[1], image.size[0], 3)
if 1:
buf = self.cam.getBuffer()
x_size = buf[1]
y_size = buf[2]
data = numpy.fromstring(buf[0], numpy.uint8).reshape(y_size, x_size, 3)
data = data[self.xmin:self.xmax,self.ymin:self.ymax]
data = numpy.average(data, 2)
return data
示例3: CameraVideoCapture
# 需要导入模块: from VideoCapture import Device [as 别名]
# 或者: from VideoCapture.Device import getBuffer [as 别名]
class CameraVideoCapture(CameraBase):
'''Implementation of CameraBase using VideoCapture
:Parameters:
`video_src` : int, default is 0
Index of VideoCapture camera to use (0 mean default camera)
'''
def __init__(self, **kwargs):
# override the default source of video
kwargs.setdefault('video_src', 0)
self._device = None
super(CameraVideoCapture, self).__init__(**kwargs)
self._format = GL_BGR
def init_camera(self):
# create the device
self._device = Device(devnum=self.video_src, showVideoWindow=0)
# set resolution
try:
self._device.setResolution(self.resolution[0], self.resolution[1])
except:
raise Exception('VideoCapture: Resolution not supported')
def update(self):
data, camera_width, camera_height = self._device.getBuffer()
if self._texture is None:
# first update, resize if necessary
self.size = camera_width, camera_height
# and create texture
self._texture = pymt.Texture.create(camera_width, camera_height,
format=GL_BGR)
# update buffer
self._buffer = data
self._copy_to_gpu()
示例4: gui
# 需要导入模块: from VideoCapture import Device [as 别名]
# 或者: from VideoCapture.Device import getBuffer [as 别名]
#.........这里部分代码省略.........
self.recvPicDataAvail=True
if typ=='a':
self.recvAudData=data[1:]
self.recvAudDataAvail=True
except:
debug('error in recvData. current val: {},{},{}'.format(self.prog, self.sndAudDataAvail, self.sndPicDataAvail))
sleep(1)
#w1 , h1 is the current size and w2, h2 is the resize output.
def getPILImage(self, buf, w1, h1, w2, h2, recv=False):
if not recv:
img = Image.fromstring('RGB', (w1,h1), buf, 'raw', 'BGR', 0, -1)
img=img.resize((w2,h2))
img=img.transpose(Image.FLIP_LEFT_RIGHT)
else:
img= Image.fromstring('RGB',(w1,h1), buf, 'raw')
img=img.resize((w2,h2))
return img
def getData(self, typ):
if typ=="pic" and self.recvPicDataAvail:
val=self.recvPicData
self.recvPicDataAvail=False
return val
if typ=="aud" and self.recvAudDataAvail:
val=self.recvAudData
self.recvAudDataAvail=False
return val
def setSendData(self, data, typ):
if typ=="pic":
#Write data only if previous data has been sent i.e sndPicDataAvail is false
if not self.sndPicDataAvail:
self.sndPicData='p'+data
self.sndPicDataAvail=True
if typ=="aud":
if not self.sndAudDataAvail:
self.sndAudData='a'+data
self.sndAudDataAvail=True
def videosnd(self):
while self.prog:
try:
pic,w,h=self.cam.getBuffer()
pic=self.getPILImage(pic,w,h,160,120)
self.setSendData(pic.tostring(), "pic")
sleep(.1)
except:
debug("Error in videosnd")
def videorecv(self):
while self.prog:
try:
while not self.recvPicDataAvail:
sleep(.05)
pic=self.getData("pic")
img=self.getPILImage(pic,160,120,self.width,self.height,True)
photo=ImageTk.PhotoImage(img)
## self.mainCanvas.delete(tk.ALL)
self.mainCanvas.create_image(self.width/2,self.height/2,image=photo)
sleep(.05)
except:
debug("Error in videorecv")
def audiosnd(self):
while self.prog:
try:
data=self.audStream.read(self.chunk)
self.setSendData(data,"aud")
except:
debug("Error in audiosnd")
def audiorecv(self):
while self.prog:
try:
while not self.recvAudDataAvail:
sleep(.05)
data=self.getData("aud")
self.audStream.write(data)
except:
debug("Error in audiorecv")
## stream.write(data)
def showMe(self):
while not self.exitProg:
try:
pic,w,h=self.cam.getBuffer()
img=self.getPILImage(pic,w,h,self.width/4,self.height/4)
photo=ImageTk.PhotoImage(img)
self.mainCanvas.create_image(self.width/8,self.height-self.height/8,image=photo)
sleep(.05)
except:
debug("Error in showMe")
def safeExit(self):
self.exitProg=True
sleep(2)
self.sock.close()
self.root.destroy()
示例5: captureVideo
# 需要导入模块: from VideoCapture import Device [as 别名]
# 或者: from VideoCapture.Device import getBuffer [as 别名]
import ImageTk
import thread
def captureVideo():
global im
while True:
buffers,width,height = cam.getBuffer()
im = PIL_Image.fromstring('RGB', (width, height), buffers, 'raw', 'BGR', 0, -1)
Tkinter.Label(root, image=tkimage).pack()
cam = Device()
#print cam.saveSnapshot('2.jpg')
#print cam.getImage().save('3.jpg')
buffers,width,height = cam.getBuffer()
#im = PIL_Image.fromstring('RGB', (width, height), buffers, 'raw', 'BGR', 0, -1)
#print len(buffers)
#im.save('4.jpg')
print 'done'
root = Tkinter.Tk()
label = Tkinter.Label(root)
label.pack()
img = None
tkimg = [None] # This, or something like it, is necessary because if you do not keep a reference to PhotoImage instances, they get garbage collected.