天天看點

寬帶伺服器圖檔不顯示不出來嗎,通過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...