如何将 Pyglet 图像的区域放入 PIL 图像中?
我的应用程序从视频中读取帧(使用 pyglet),提取一个“条带”(即区域 - 全宽,由 1 到 6 条视频线组成),然后将每个条带(附加它)粘贴到图像中,该图像稍后可以写出 *. png 文件。
问题是 Pyglet GL 图像存储在图形内存中,因此尺寸非常有限。 我当前笨拙的解决方法是将未来的 png 图像构建为小图块(即在 pyglet GL 大小限制内),当图块已满时,将其写出到 *png 文件,将其作为 PIL 图像文件读回,然后将平铺图像粘贴/附加到最终的 PIL Image * png 文件。
我认为应该可以将 pyglet-GL strip 转换为 PIL 图像友好格式,并将其直接粘贴/附加到最终的 PIL 图像中,从而不需要图块业务,这会使事情变得非常复杂并且对性能产生影响。
但我找不到如何将条带数据转换为可以粘贴到 PIL 图像中的表单。 见过很多请求以另一种方式重新转换,但我从来没有随波逐流。
My app reads frames from video (using pyglet), extracts a 'strip' (i.e. region - full width by 1 to 6 video lines), then pastes each strip (appends it) into an image that can later be written out an *.png file.
Problem is Pyglet GL images are stored in graphics memory, so are very limited re size.
My current klunky workaround is build up the to-be png image as small tiles (i.e. within the pyglet GL size limit), when the tile is full, write it out to a *png file, read that back in as a PIL Image file, then paste/append the tile image to the final PIL Image * png file.
I reckon it should be possible to convert the pyglet-GL strip to a PIL Image-friendly format, and paste/append that straight into the final PIL Image, thus having no need for the tile business, which greatly complicates things and has performance impact.
But I can't find how to get the strip data into a form that I can paste into a PIL Image.
Have seen many requests re converting the other way, but I've never run with the herd.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我知道回答自己的问题是不好的形式,但我找到了一个可能对其他人有用的答案,所以这里是...
nextframe = source.get_next_video_frame() # 获取第一个视频帧
返回 None
while nextframe != None:# 在“while nextframe != None:”的 EOF 末尾
I know it's bad form to reply to one's own question, but I worked out an answer which may be useful to others, so here it is...
nextframe = source.get_next_video_frame() # get first video frame
while nextframe != None:# returns None at EOF
end of "while nextframe != None:"