Python屏幕捕获错误(Python screen capture error)
我正在尝试修改这里给出的用于屏幕流的代码。 在上面的教程中,它用于从磁盘读取图像,而我试图截取屏幕截图。 我收到此错误。
断言isinstance(数据,字节)'应用程序必须写入字节'AssertionError:应用程序必须写入字节
我应该做些什么改变才能发挥作用?
这就是我迄今为止所做的 -
<br>index.html<br> <html> <head> <title>Video Streaming Demonstration</title> </head> <body> <h1>Video Streaming Demonstration</h1> <img src="{{ url_for('video_feed') }}"> </body> </html>
app.py#!/usr/bin/env python from flask import Flask, render_template, Response import time # emulated camera from camera import Camera # Raspberry Pi camera module (requires picamera package) # from camera_pi import Camera app = Flask(__name__) @app.route('/') def index(): """Video streaming home page.""" return render_template('index.html') def gen(camera): """Video streaming generator function.""" while True: time.sleep(0.1) frame = camera.get_frame() yield (frame) @app.route('/video_feed') def video_feed(): """Video streaming route. Put this in the src attribute of an img tag.""" return Response(gen(Camera()), mimetype='multipart/x-mixed-replace; boundary=frame') if __name__ == '__main__': app.run(host='0.0.0.0', debug=True, threaded=True)
camera.pyfrom time import time from PIL import Image from PIL import ImageGrab import sys if sys.platform == "win32": grabber = Image.core.grabscreen class Camera(object): def __init__(self): #self.frames = [open('shot0' + str(f) + '.png', 'rb').read() for f in range(1,61)] self.frames = [ImageGrab.grab() for f in range(1,61)] def get_frame(self): return self.frames[int(time()) % 3]
完整的错误: 链接
I am trying to modify the code given here for screen streaming. In the above tutorial it was for reading images from disk whereas I am trying to take screenshots. I receive this error.
assert isinstance(data, bytes), 'applications must write bytes' AssertionError: applications must write bytes
What changes should I make for it to work?
This is what I've done so far -
<br>index.html<br> <html> <head> <title>Video Streaming Demonstration</title> </head> <body> <h1>Video Streaming Demonstration</h1> <img src="{{ url_for('video_feed') }}"> </body> </html>
app.py#!/usr/bin/env python from flask import Flask, render_template, Response import time # emulated camera from camera import Camera # Raspberry Pi camera module (requires picamera package) # from camera_pi import Camera app = Flask(__name__) @app.route('/') def index(): """Video streaming home page.""" return render_template('index.html') def gen(camera): """Video streaming generator function.""" while True: time.sleep(0.1) frame = camera.get_frame() yield (frame) @app.route('/video_feed') def video_feed(): """Video streaming route. Put this in the src attribute of an img tag.""" return Response(gen(Camera()), mimetype='multipart/x-mixed-replace; boundary=frame') if __name__ == '__main__': app.run(host='0.0.0.0', debug=True, threaded=True)
camera.pyfrom time import time from PIL import Image from PIL import ImageGrab import sys if sys.platform == "win32": grabber = Image.core.grabscreen class Camera(object): def __init__(self): #self.frames = [open('shot0' + str(f) + '.png', 'rb').read() for f in range(1,61)] self.frames = [ImageGrab.grab() for f in range(1,61)] def get_frame(self): return self.frames[int(time()) % 3]
Full error : Link
原文:https://stackoverflow.com/questions/40060653
满意答案
尝试使用UnmanagedMemoryStream :
此类支持使用现有的基于流的模型访问非托管内存,并且不要求将非托管内存中的内容复制到堆中。
这意味着您将寻找/读取/重置流,但这避免了编组。 它仍然不是你希望在.NET属性中包含这些访问的意义上的。
另一种选择:也许你可以在获得非托管指针后使用System.Buffer 。 你可能需要做一些聪明的演员。
Try using the UnmanagedMemoryStream:
This class supports access to unmanaged memory using the existing stream-based model and does not require that the contents in the unmanaged memory be copied to the heap.
This means you will be seeking/reading/resetting the stream, but this avoids the marshalling. It's still not live in the sense you'd want to probably want to wrap these accesses in .NET properties.
Another alternative: maybe you could use System.Buffer, after getting the unmanaged pointer. You may need to do some clever casting.
相关问答
更多Nios 2“Hello World”?(Nios 2 “Hello World”?)
在C#中释放非托管代码(Freeing up of unmanaged code in C#)
将结构数组编组到C#中的指针(Marshalling an array of structs to a pointer in C#)
编组结构,嵌入指针从C#到非托管驱动程序(Marshalling struct with embedded pointer from C# to unmanaged driver)
C#结构中的事件?(Are Events in C# structs?)
来自C#的Hello World世界到Twitter(Hello World to Twitter from C#)
在非托管C ++代码中使用C#属性(Use C# properties in unmanaged C++ code)
非托管C#与C ++ [关闭](Unmanaged C# versus C++ [closed])
来自非管理世界的C#结构能否“实时” - 更新?(Can C# structs coming from the unmanaged world be “live”-updating?)
Spring MVC Samples中的“Hello World”来自哪里?(Where is the “Hello World” coming from in Spring MVC Samples)
相关文章
更多eclipse里报:An internal error occurred during:
The connection to adb is down, and a severe error has occured.
solr error logs org.apache.solr.common.SolrException: ERROR: [doc=17] unknown field alias
python2和python3的区别
Solr安装异常:SolrException: Error loading class 'solr.VelocityResponseWriter'
error C2668: 'M' : ambiguous call to overloaded function
Python 写的Hadoop小程序
spark--scala-douban模仿做了个python的版本
win8安装VirtualBox-4.2.18提示Installation failed!error:系统找不到指定的路径
Hadoop 异常记录 ERROR: org.apache.hadoop.hbase.MasterNotRunningException: Retried 7 times
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!