本文整理汇总了Python中numpy.getbuffer函数的典型用法代码示例。如果您正苦于以下问题:Python getbuffer函数的具体用法?Python getbuffer怎么用?Python getbuffer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getbuffer函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:pieleric,项目名称:odemis,代码行数:30,代码来源:_dataflow.py
示例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
开发者ID:matt-desmarais,项目名称:P0Wcrosshair,代码行数:27,代码来源:testingcrosshair.py
示例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
开发者ID:matt-desmarais,项目名称:crosshair,代码行数:28,代码来源:crosshair.py
示例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
开发者ID:matt-desmarais,项目名称:P0Wcrosshair,代码行数:29,代码来源:testingcrosshair.py
示例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)
开发者ID:stevealbertwong,项目名称:pylepton,代码行数:32,代码来源:gimme5_v1.py
示例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
开发者ID:matt-desmarais,项目名称:crosshair,代码行数:27,代码来源:crosshair.py
示例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)
开发者ID:texttheater,项目名称:tensorflow,代码行数:8,代码来源:bitcast_op_test.py
示例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
开发者ID:aforsythe,项目名称:CLF,代码行数:9,代码来源:filterImageWithCLF.py
示例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))))
开发者ID:ttnghia,项目名称:SPH-2,代码行数:10,代码来源:gpu_interface.py
示例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
开发者ID:aforsythe,项目名称:CLF,代码行数:10,代码来源:filterImageWithCLF.py
示例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)
开发者ID:Gjergj,项目名称:OpenElectrophy,代码行数:52,代码来源:sqlmapper.py
示例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))))
开发者ID:FreddieWitherden,项目名称:pycuda,代码行数:13,代码来源:demo_struct.py
示例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
开发者ID:matt-desmarais,项目名称:crosshair,代码行数:14,代码来源:crosshair.py
示例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
开发者ID:onlytailei,项目名称:Optical_Flow,代码行数:34,代码来源:calc_rain.py
示例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()))
开发者ID:shamrin,项目名称:pyxtf,代码行数:7,代码来源:segy.py
示例16: writeFrame
def writeFrame(self, frame, header = None):
if self.write:
#self.streamer.stdin.write(frame.tostring())
if header is not None:
drawHeaderString(frame, header)
self.streamer.stdin.write(np.getbuffer(frame))
self.streamer.stdin.flush()
开发者ID:caomw,项目名称:rgbd-1,代码行数:7,代码来源:videoStreamer.py
示例17: _save_image
def _save_image(im_array, file_name):
"""
Save an image as a file.
The input image as a (3, height, width) array, with values in the range
0..1. The first axis corresponds with the red, green and blue channels.
"""
# Take a copy so we don't mutate the input.
#im_array = im_array.copy()
# PIL expects lines in bottom-to-top order
for chan in range(3):
im_array[chan, :, :] = numpy.flipud(im_array[chan, :, :])
# Clamp values to 0..1
numpy.clip(im_array, 0., 1.0, out=im_array)
# Convert into a 1D array with values in the order expected by PIL.
im_array = numpy.transpose(im_array, (1, 2, 0))
dims = im_array.shape[1], im_array.shape[0]
im_array = im_array.flatten()
# Convert to bytes in the range 0..255
im_array *= 255.
im_array = numpy.uint8(im_array)
# Save the image.
im = PIL.Image.frombuffer("RGB", dims, numpy.getbuffer(im_array))
im.save(file_name)
开发者ID:matthewearl,项目名称:timelapseutils,代码行数:30,代码来源:rawsubtract.py
示例18: run
def run(self):
with h5py.File(self._filepath, 'r') as h5_file:
(internal_path, slicing) = self._request_queue_recv.recv()
# 'None' means stop the process.
while internal_path is not None:
try:
if METHOD == 'shared-array':
read_roi = slice_to_roi( slicing, h5_file[internal_path].shape )
read_roi = numpy.array(read_roi)
read_shape = read_roi[1] - read_roi[0]
num_bytes = h5_file[internal_path].dtype.itemsize * numpy.prod( read_shape )
assert num_bytes <= self.available_bytes, "I don't yet support really big slicings"
read_array = numpy.frombuffer( self.transfer_buffer, dtype=numpy.uint8, count=num_bytes )
read_array.setflags(write=True)
read_array = read_array.view(h5_file[internal_path].dtype).reshape( read_shape )
h5_file[internal_path].read_direct(read_array, slicing)
if METHOD == 'pipe-bytes' or METHOD == 'pipe-array':
read_array = h5_file[internal_path][slicing]
except Exception as ex:
self._result_queue_send.send( ex )
raise
else:
self._result_queue_send.send( (read_array.shape, read_array.dtype) )
if METHOD == 'pipe-array':
self._result_queue_send.send( read_array )
if METHOD == 'pipe-bytes':
self._result_queue_send.send_bytes( numpy.getbuffer(read_array) )
# Wait for the next request
(internal_path, slicing) = self._request_queue_recv.recv()
开发者ID:CVML,项目名称:lazyflow,代码行数:34,代码来源:multiprocessHdf5File.py
示例19: get_overlay
def get_overlay(fifo):
# get the whole FIFO
ir_raw = fifo.read()
# trim to 128 bytes
ir_trimmed = ir_raw[0:128]
# go all numpy on it
ir = np.frombuffer(ir_trimmed, np.uint16)
# set the array shape to the sensor shape (16x4)
ir = ir.reshape((16, 4))[::-1, ::-1]
ir = img_as_float(ir)
# stretch contrast on our heat map
p2, p98 = np.percentile(ir, (2, 98))
ir = exposure.rescale_intensity(ir, in_range=(p2, p98))
# increase even further? (optional)
# ir = exposure.equalize_hist(ir)
# turn our array into pretty colors
cmap = plt.get_cmap('spectral')
rgba_img = cmap(ir)
rgb_img = np.delete(rgba_img, 3, 2)
# align the IR array with the camera
tform = transform.AffineTransform(
scale=SCALE, rotation=ROT, translation=OFFSET)
ir_aligned = transform.warp(
rgb_img, tform.inverse, mode='constant', output_shape=im.shape)
# turn it back into a ubyte so it'll display on the preview overlay
ir_byte = img_as_ubyte(ir_aligned)
# return buffer
return np.getbuffer(ir_byte)
开发者ID:terickson,项目名称:mlxd,代码行数:30,代码来源:mlxview.py
示例20: load
def load(self, gen):
with self._txn(write=True) as txn:
try:
for name, value in gen:
txn.put(name, numpy.getbuffer(value))
except lmdb.BadValsizeError as e:
print name, value.shape, value
开发者ID:davidmr001,项目名称:uncc2014watsonsim,代码行数:7,代码来源:vstore.py
注:本文中的numpy.getbuffer函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论