本文整理汇总了Python中numpy.getbuffer函数的典型用法代码示例。如果您正苦于以下问题:Python getbuffer函数的具体用法?Python getbuffer怎么用?Python getbuffer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getbuffer函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: notify
def notify(self, data):
# publish the data remotely
if self.pipe and len(self._remote_listeners) > 0:
# TODO: is there any way to know how many recipients of the pipe?
# If possible, we would detect it's 0, because some listener closed
# without unsubscribing, and we would kick it out.
# => use zmq_socket_monitor() to detect connection/disconnection and
# update the count of subscribers, or detect when a remote_listener
# is gone (if there is a way to associate it)
# TODO thread-safe for self.pipe ?
dformat = {"dtype": str(data.dtype), "shape": data.shape}
self.pipe.send_pyobj(dformat, zmq.SNDMORE)
self.pipe.send_pyobj(data.metadata, zmq.SNDMORE)
try:
if not data.flags["C_CONTIGUOUS"]:
# if not in C order, it will be received incorrectly
# TODO: if it's just rotated, send the info to reconstruct it
# and avoid the memory copy
raise TypeError("Need C ordered array")
self.pipe.send(numpy.getbuffer(data), copy=False)
except TypeError:
# not all buffers can be sent zero-copy (e.g., has strides)
# try harder by copying (which removes the strides)
logging.debug("Failed to send data with zero-copy")
data = numpy.require(data, requirements=["C_CONTIGUOUS"])
self.pipe.send(numpy.getbuffer(data), copy=False)
# publish locally
DataFlowBase.notify(self, data)
示例2: togglepatternZoomIn
def togglepatternZoomIn():
global togsw,o,curpat,col,ovl,gui,alphaValue,ycenter,zoomcount
# if overlay is inactive, ignore button:
if togsw == 0:
print "Pattern button pressed, but ignored --- Crosshair not visible."
zoom_in()
ycenter = ycenter + zoomcount
# if overlay is active, drop it, change pattern, then show it again
else:
if guivisible == 0:
zoom_in()
# reinitialize array:
ovl = np.zeros((height, width, 3), dtype=np.uint8)
patternswitcherZoomIn(ovl,0)
if 'o' in globals():
camera.remove_overlay(o)
o = camera.add_overlay(np.getbuffer(ovl), layer=3, alpha=alphaValue)
else:
# reinitialize array
zoom_in()
gui = np.zeros((height, width, 3), dtype=np.uint8)
creategui(gui)
patternswitcherZoomIn(gui,1)
if 'o' in globals():
camera.remove_overlay(o)
o = camera.add_overlay(np.getbuffer(gui), layer=3, alpha=alphaValue)
return
示例3: togglecolor
def togglecolor(channel):
global togsw,o,curcol,col,ovl,gui,alphaValue
# step up the color to next in list
curcol = colorcycle(colors,curcol)
# map colorname to RGB value for new color
col = colormap(curcol)
# if overlay is inactive, ignore button:
if togsw == 0:
print "Color button pressed, but ignored --- Crosshair not visible."
# if overlay is active, drop it, change color, then show it again
else:
print "Set new color: " + str(curcol) + " RGB: " + str(col)
if guivisible == 0:
# reinitialize array:
ovl = np.zeros((height, width, 3), dtype=np.uint8)
patternswitch(ovl,0)
if 'o' in globals():
camera.remove_overlay(o)
o = camera.add_overlay(np.getbuffer(ovl), layer=3, alpha=alphaValue)
else:
# reinitialize array
gui = np.zeros((height, width, 3), dtype=np.uint8)
creategui(gui)
patternswitch(gui,1)
if 'o' in globals():
camera.remove_overlay(o)
o = camera.add_overlay(np.getbuffer(gui), layer=3, alpha=alphaValue)
return
示例4: togglepatternZoomOut
def togglepatternZoomOut():
global togsw,o,curpat,col,ovl,gui,alphaValue
# if overlay is inactive, ignore button:
if togsw == 0:
zoom_out()
ycenter = int(ycenter - int(math.fabs(zoomcount - 14))/2)
if zoomcount == 0:
ycenter = cdefaults.get('ycenter')
print "Pattern button pressed, but ignored --- Crosshair not visible."
# if overlay is active, drop it, change pattern, then show it again
else:
if guivisible == 0:
zoom_out()
# reinitialize array:
ovl = np.zeros((height, width, 3), dtype=np.uint8)
patternswitcherZoomOut(ovl,0)
if 'o' in globals():
camera.remove_overlay(o)
o = camera.add_overlay(np.getbuffer(ovl), layer=3, alpha=alphaValue)
else:
zoom_out()
# reinitialize array
gui = np.zeros((height, width, 3), dtype=np.uint8)
creategui(gui)
patternswitcherZoomOut(gui,1)
if 'o' in globals():
camera.remove_overlay(o)
o = camera.add_overlay(np.getbuffer(gui), layer=3, alpha=alphaValue)
return
示例5: main
def main(flip_v = False, alpha = 128, device = "/dev/spidev0.0"):
with picamera.PiCamera() as camera:
#camera.resolution = (640, 480)
camera.resolution = (80, 60)
camera.framerate = 12
camera.vflip = flip_v
camera.start_preview()
camera.fullscreen = False
# Add the overlay directly into layer 3 with transparency;
# we can omit the size parameter of add_overlay as the
# size is the same as the camera's resolution
o = camera.add_overlay(np.getbuffer(a), size=(320,240), layer=3, alpha=int(alpha), crop=(0,0,80,60), vflip=flip_v)
try:
time.sleep(0.2) # give the overlay buffers a chance to initialize
with Lepton(device) as l:
while True:
time.sleep(1) #slow down
tmpfile = "tmp.jpg"
image = capture(flip_v = False)
cv2.imwrite(tmpfile, image)
#Added by sco
img = detect(tmpfile)
#a[:lepton_buf.shape[0], :lepton_buf.shape[1], :] = lepton_buf
if img is not None:
a[:img.shape[0], :img.shape[1], :] = img
o.update(np.getbuffer(a))
except Exception:
traceback.print_exc()
finally:
camera.remove_overlay(o)
示例6: togglepattern2
def togglepattern2(channel):
global togsw,o,curpat2,col,ovl,gui,alphaValue
# if overlay is inactive, ignore button:
if togsw == 0:
print "Pattern button pressed, but ignored --- Crosshair not visible."
# if overlay is active, drop it, change pattern, then show it again
else:
curpat2 += 1
print "Set new pattern: " + str(curpat2)
if curpat2 > patterns.maxpat: # this number must be adjusted to number of available patterns!
curpat2 = 1
if guivisible == 0:
# reinitialize array:
ovl = np.zeros((height, width, 3), dtype=np.uint8)
patternswitcher(ovl,0)
if 'o' in globals():
camera.remove_overlay(o)
o = camera.add_overlay(np.getbuffer(ovl), layer=3, alpha=alphaValue)
else:
# reinitialize array
gui = np.zeros((height, width, 3), dtype=np.uint8)
creategui(gui)
patternswitcher(gui,1)
if 'o' in globals():
camera.remove_overlay(o)
o = camera.add_overlay(np.getbuffer(gui), layer=3, alpha=alphaValue)
return
示例7: _testBitcast
def _testBitcast(self, x, datatype, shape):
with self.test_session():
tf_ans = tf.bitcast(x, datatype)
out = tf_ans.eval()
buff_after = np.getbuffer(out)
buff_before = np.getbuffer(x)
self.assertEqual(buff_before, buff_after)
self.assertEqual(tf_ans.get_shape(), shape)
示例8: npHalfArrayToOIIOFloatPixels
def npHalfArrayToOIIOFloatPixels(width, height, channels, npPixels):
if oiio.VERSION < 10800:
# Read half-float pixels into a numpy float pixel array
oiioFloatsArray = np.frombuffer(np.getbuffer(np.float16(npPixels)), dtype=np.float32)
else:
# Read half-float pixels into a numpy float pixel array
oiioFloatsArray = np.frombuffer(np.getbuffer(np.float16(npPixels)), dtype=np.uint16)
return oiioFloatsArray
示例9: __init__
def __init__(self, array, struct_arr_ptr):
print "copying data to device"
self.data = cuda.to_device(array)
self.shape, self.dtype = array.shape, array.dtype
cuda.memcpy_htod(int(struct_arr_ptr),
numpy.getbuffer(numpy.int32(len(array[0]))))
cuda.memcpy_htod(int(struct_arr_ptr) + 8,
numpy.getbuffer(numpy.intp(int(self.data))))
示例10: oiioFloatPixelsToNPHalfArray
def oiioFloatPixelsToNPHalfArray(width, height, channels, oiioFloats):
if oiio.VERSION < 10800:
# Read float pixels into a numpy half-float pixel array
npPixels = np.frombuffer(np.getbuffer(np.float32(oiioFloats)), dtype=np.float16)
else:
# Convert uint16 values into a numpy half-float pixel array
npPixels = np.frombuffer(np.getbuffer(np.uint16(oiioFloats)), dtype=np.float16)
return npPixels
示例11: fset
def fset(self, inst, value):
nprow = getattr(inst, 'NumpyArrayTable__'+self.name)
#~ print 'fset',self.name, nprow, value
if nprow is None:
nprow = self.NumpyArrayTableClass()
setattr(inst, 'NumpyArrayTable__'+self.name, nprow)
if value is None:
if hasattr(inst, self.name+'_array') :
delattr(inst, self.name+'_array')
nprow.shape = None
nprow.dtype = None
nprow.blob = None
nprow.units = None
nprow.compress = None
return
if self.arraytype == np.ndarray:
assert (type(value) == np.ndarray) or (type(value) == np.memmap) , 'Value is not np.array or np.memmap but {}'.format(type(value))
if self.arraytype == pq.Quantity:
assert type(value) == pq.Quantity , '{} {} {} value is not pq.Quantity'.format(inst.__class__.__name__, self.name, value)
shape = ('{},'*value.ndim)[:-1].format(*value.shape)
if shape.endswith(',') : shape = shape[:-1]
nprow.shape = shape
nprow.dtype = value.dtype.str
if self.compress == 'blosc':
blob = blosc.compress(value.tostring(), typesize = value.dtype.itemsize, clevel= 9)
else:
if not value.flags['C_CONTIGUOUS']:
buf = np.getbuffer(np.array(value, copy = True))
else:
buf = np.getbuffer(value)
if self.compress == 'zlib':
blob = zlib.compress(buf)
elif self.compress == 'lz4':
blob = lz4.compress(buf)
elif self.compress == 'snappy':
blob = snappy.compress(buf)
else :
blob = buf
nprow.compress = self.compress
nprow.blob = blob
if self.arraytype == pq.Quantity:
nprow.units = value.dimensionality.string
setattr(inst, self.name+'_array', value)
示例12: __init__
def __init__(self, array, struct_arr_ptr):
self.data = cuda.to_device(array)
self.shape, self.dtype = array.shape, array.dtype
"""
numpy.getbuffer() needed due to lack of new-style buffer interface for
scalar numpy arrays as of numpy version 1.9.1
see: https://github.com/inducer/pycuda/pull/60
"""
cuda.memcpy_htod(int(struct_arr_ptr),
numpy.getbuffer(numpy.int32(array.size)))
cuda.memcpy_htod(int(struct_arr_ptr) + 8,
numpy.getbuffer(numpy.uintp(int(self.data))))
示例13: toggleonoff
def toggleonoff(channel):
global togsw,o,alphaValue
if togsw == 1:
print "Toggle Crosshair OFF"
camera.remove_overlay(o)
togsw = 0
else:
print "Toggle Crosshair ON"
if guivisible == 0:
o = camera.add_overlay(np.getbuffer(ovl), layer=3, alpha=alphaValue)
else:
o = camera.add_overlay(np.getbuffer(gui), layer=3, alpha=alphaValue)
togsw = 1
return
示例14: Pack_Data
def Pack_Data(uniq_id,paraDict,matrix,key,timeStr,radius):
offset=32
store_size=offset+58+len(matrix)
send_back=bytearray(store_size)
#增加编码
send_back[0:offset]=struct.pack('32s',uniq_id)
#站点编号
send_back[offset+0:offset+5]=key
#站点经度
send_back[offset+5:offset+9]=struct.pack('i',int(paraDict['stalon']*1000))
#站点纬度
send_back[offset+9:offset+13]=struct.pack('i',int(paraDict['stalat']*1000))
#站点高度
send_back[offset+13:offset+17]=struct.pack('i',int(paraDict['staheight']*1000))
#数据块左上角经度
send_back[offset+17:offset+21]=struct.pack('i',int(paraDict['xstartlon']*1000))
#数据块左上角纬度
send_back[offset+21:offset+25]=struct.pack('i',int(paraDict['ystartlat']*1000))
#数据块宽度
send_back[offset+25:offset+29]=struct.pack('i',int(paraDict['xsize']))
#数据块高度
send_back[offset+29:offset+33]=struct.pack('i',int(paraDict['ysize']))
#x方向分辨率
send_back[offset+33:offset+37]=struct.pack('i',int(paraDict['xres']*20))
#y方向分辨率
send_back[offset+37:offset+41]=struct.pack('i',int(paraDict['yres']*20))
#时间世界时,12位,到分钟
send_back[offset+41:offset+53]=struct.pack('12s',str(timeStr))
#写入半径
send_back[offset+53:offset+57]=struct.pack('i',int(radius))
#最后一个字符
send_back[offset+57:offset+58]=struct.pack('c','0')
send_back[offset+58:]=np.getbuffer(matrix)
return send_back
示例15: write_SEGY
def write_SEGY(outfile, file_header, text, traces):
with open(outfile, 'wb') as out:
out.write(encode_text(text))
out.write(SEGY_HEADER.wrap(file_header))
for header, data in traces:
out.write(TRACE_HEADER.wrap(header))
out.write(np.getbuffer(data.byteswap()))