本文整理汇总了Python中png.from_array方法的典型用法代码示例。如果您正苦于以下问题:Python png.from_array方法的具体用法?Python png.from_array怎么用?Python png.from_array使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类png
的用法示例。
在下文中一共展示了png.from_array方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _generate_time_steps
# 需要导入模块: import png [as 别名]
# 或者: from png import from_array [as 别名]
def _generate_time_steps(self, trajectory_list):
"""Transforms time step observations to frames of a video."""
for time_step in gym_env_problem.GymEnvProblem._generate_time_steps(
self, trajectory_list):
# Convert the rendered observations from numpy to png format.
frame_np = np.array(time_step.pop(env_problem.OBSERVATION_FIELD))
frame_np = frame_np.reshape(
[self.frame_height, self.frame_width, self.num_channels])
# TODO(msaffar) Add support for non RGB rendered environments
frame = png.from_array(frame_np, "RGB", info={"bitdepth": 8})
frame_buffer = six.BytesIO()
frame.save(frame_buffer)
# Put the encoded frame back.
time_step[_IMAGE_ENCODED_FIELD] = [frame_buffer.getvalue()]
time_step[_IMAGE_FORMAT_FIELD] = [_FORMAT]
time_step[_IMAGE_HEIGHT_FIELD] = [self.frame_height]
time_step[_IMAGE_WIDTH_FIELD] = [self.frame_width]
# Add the frame number
time_step[_FRAME_NUMBER_FIELD] = time_step[env_problem.TIMESTEP_FIELD]
yield time_step
示例2: main
# 需要导入模块: import png [as 别名]
# 或者: from png import from_array [as 别名]
def main():
if len(sys.argv) != 2:
print "python %s <filename>" % sys.argv[0]
sys.exit(1)
try:
filename = sys.argv[1]
with open(filename, 'rb') as f:
saved_state = pickle.load(f)
bitmap = saved_state['bitmap']
except:
print "[!] Could not load bitmap"
sys.exit(1)
# Get rough code coverage value
coverage = get_coverage(bitmap)
print "[*] Code coverage (basic block calls): %.2f" % coverage
if HAS_PYPNG:
# Create PNG image from bitmap values
p = populate_array(bitmap)
img = png.from_array(p, 'RGB')
img.save('status_graph.png')
print "[*] Created PNG file"
示例3: main
# 需要导入模块: import png [as 别名]
# 或者: from png import from_array [as 别名]
def main(wb):
wb.open()
regs = wb.regs
# # #
print("dumping framebuffer memory...")
dump = []
for n in range(DUMP_SIZE//(WORDS_PER_PACKET*4)):
data = wb.read(SDRAM_BASE + n*WORDS_PER_PACKET*4, WORDS_PER_PACKET)
for pixel in data:
dump += extract_rgb(pixel)
dump = [dump[x:x+LINE_SIZE] for x in range(0, len(dump), LINE_SIZE)]
print("dumping to png file...")
png.from_array(dump, "RGB").save("dump.png")
# # #
wb.close()