本文整理汇总了Python中PIL.Image.fromstring方法的典型用法代码示例。如果您正苦于以下问题:Python Image.fromstring方法的具体用法?Python Image.fromstring怎么用?Python Image.fromstring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PIL.Image
的用法示例。
在下文中一共展示了Image.fromstring方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: screen_game
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import fromstring [as 别名]
def screen_game(region, save_to=None):
x, y, width, height = region
try:
raw = root.get_image(x, y, width, height, X.ZPixmap, 0xffffffff)
if hasattr(Image, 'frombytes'):
# for Pillow
screenshot = Image.frombytes('RGB', (width, height), raw.data, 'raw', 'BGRX')
else:
# for PIL
screenshot = Image.fromstring('RGB', (width, height), raw.data, 'raw', 'BGRX')
if save_to is not None:
screenshot.save(save_to + '.png')
except:
filename = save_to + '.png' if save_to is not None else None
screenshot = pyautogui.screenshot(filename, region)
return screenshot
# Return pixel color of given x, y coordinates
示例2: dots
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import fromstring [as 别名]
def dots(self):
dotsF = numpy.zeros((156,208))
dotsI = dotsF.astype('uint8')
k = 10
for i in range(0,155,1):
for j in range(k,206,15):
# print i,j
dotsI[i,j] = 255
k = k - 4
if k < 0: k = k + 15
return dotsI
# display it to see if it matches the Seek black dot hex pattern
# zz = Image.fromstring("I", (208,156), dotsI, "raw", "I;8")
# toimage(zz).show()
# print dotsI
#####################################################################
示例3: _test
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import fromstring [as 别名]
def _test():
import EasyDialogs
try:
from PIL import Image
except ImportError:
Image = None
import MacOS
Qt.EnterMovies()
path = EasyDialogs.AskFileForOpen(message='Video to convert')
if not path: sys.exit(0)
rdr = reader(path)
if not rdr:
sys.exit(1)
dstdir = EasyDialogs.AskFileForSave(message='Name for output folder')
if not dstdir: sys.exit(0)
num = 0
os.mkdir(dstdir)
videofmt = rdr.GetVideoFormat()
imgfmt = videofmt.getformat()
imgw, imgh = videofmt.getsize()
timestamp, data = rdr.ReadVideo()
while data:
fname = 'frame%04.4d.jpg'%num
num = num+1
pname = os.path.join(dstdir, fname)
if not Image: print 'Not',
print 'Writing %s, size %dx%d, %d bytes'%(fname, imgw, imgh, len(data))
if Image:
img = Image.fromstring("RGBA", (imgw, imgh), data)
img.save(pname, 'JPEG')
timestamp, data = rdr.ReadVideo()
MacOS.SetCreatorAndType(pname, 'ogle', 'JPEG')
if num > 20:
print 'stopping at 20 frames so your disk does not fill up:-)'
break
print 'Total frames:', num
示例4: test_fromstring
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import fromstring [as 别名]
def test_fromstring(self):
self.assertRaises(NotImplementedError, Image.fromstring)
示例5: test_not_implemented
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import fromstring [as 别名]
def test_not_implemented(self):
self.assertRaises(NotImplementedError, Image.fromstring)
示例6: _fingerprint
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import fromstring [as 别名]
def _fingerprint(data, frame, size):
# python 2
data_str = "".join(chr(p) for p in data)
im = Image.fromstring("L", (frame.w, frame.h), data_str, "raw", "L", 0, 1)
im = im.resize(size, resample=Image.BILINEAR)
return list(im.getdata())
示例7: save
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import fromstring [as 别名]
def save(filename, width, height, fmt, pixels, flipped=False):
image = PILImage.fromstring(fmt.upper(), (width, height), pixels)
if flipped:
image = image.transpose(PILImage.FLIP_TOP_BOTTOM)
image.save(filename)
return True
# register
示例8: preprocess_captcha_part
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import fromstring [as 别名]
def preprocess_captcha_part(file):
letter_algo = []
letters = split_captcha(file)
for i in range (len(letters)):
#letter = Image.fromstring("L", cv.GetSize(letters[i]), letters[i].tostring())
letter = Image.open(letters[i])
letter_algo.append(letter.point(lambda i: (i/255.)))
return letters
示例9: take_pic
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import fromstring [as 别名]
def take_pic():
video = v4l2capture.Video_device("/dev/video0")
size_x, size_y = video.set_format(1280, 1024)
video.create_buffers(1)
video.queue_all_buffers()
video.start()
select.select((video,), (), ())
image_data = video.read()
video.close()
image = Image.fromstring("RGB", (size_x, size_y), image_data)
in_mem_file = io.BytesIO()
logger.info("In_men_file pre saved size {}".format(len(in_mem_file.getvalue())))
image.save(in_mem_file, "JPEG")
logger.info("In_men_filepost saved size {}".format(len(in_mem_file.getvalue())))
return in_mem_file
示例10: getImage
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import fromstring [as 别名]
def getImage(self):
buffer, width, height = self.dev.getbuffer()
if buffer:
im = Image.fromstring('RGB', (width, height), buffer, 'raw', 'BGR', 0, -1)
return im
示例11: get_image
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import fromstring [as 别名]
def get_image():
global im2arrF
while True:
# Send read frame request
send_msg(0x41, 0x53, 0, 0, '\xC0\x7E\x00\x00')
try:
ret9 = dev.read(0x81, 0x3F60, 1000)
ret9 += dev.read(0x81, 0x3F60, 1000)
ret9 += dev.read(0x81, 0x3F60, 1000)
ret9 += dev.read(0x81, 0x3F60, 1000)
except usb.USBError as e:
sys.exit()
# Let's see what type of frame it is
# 1 is a Normal frame, 3 is a Calibration frame
# 6 may be a pre-calibration frame
# 5, 10 other... who knows.
status = ret9[20]
#print ('%5d'*21 ) % tuple([ret9[x] for x in range(21)])
if status == 1:
# Convert the raw calibration data to a string array
calimg = Image.fromstring("I", (208,156), ret9, "raw", "I;16")
# Convert the string array to an unsigned numpy int16 array
im2arr = numpy.asarray(calimg)
im2arrF = im2arr.astype('uint16')
if status == 3:
# Convert the raw calibration data to a string array
img = Image.fromstring("I", (208,156), ret9, "raw", "I;16")
# Convert the string array to an unsigned numpy int16 array
im1arr = numpy.asarray(img)
im1arrF = im1arr.astype('uint16')
# Subtract the calibration array from the image array and add an offset
additionF = (im1arrF-im2arrF)+ 800
# convert to an image and display with imagemagick
disp_img = toimage(additionF)
#disp_img.show()
return disp_img