天天看点

宽带服务器图片不显示不出来吗,通过HTTP的Python网络摄像头图像服务器不显示imag...

我试图使用pythonsocket和OpenCV通过HTTP提供网络摄像头图像,但它不能正常工作。服务器无法提供从网络摄像头捕获的适当JPEG图像。它只显示一些二进制数组。在import io

import socket

import atexit

from cv2 import *

from PIL import Image

def camServer():

while True:

print("wait...")

conn, addr = server_socket.accept()

if conn:

print(conn)

print(addr)

connection = conn.makefile('wb')

break

print("Connecting")

try:

cam = VideoCapture(0)

s, imgArray = cam.read()

if s:

atexit.register(onExit)

img = io.BytesIO()

imgPIL = Image.fromarray(imgArray)

imgPIL.save(img, format="jpeg")

img.seek(0)

connection.write(img.read())

img.seek(0)

img.truncate()

finally:

print("close connection")

connection.close()

def onExit():

connection.close()

server_socket.close()

print("exit")

server_socket = socket.socket()

server_socket.bind(('0.0.0.0', 8000))

server_socket.listen(0)

server_socket.setblocking(1)

while True:

camServer()

宽带服务器图片不显示不出来吗,通过HTTP的Python网络摄像头图像服务器不显示imag...
宽带服务器图片不显示不出来吗,通过HTTP的Python网络摄像头图像服务器不显示imag...