是的,用的官方的
Q
q3ok
@q3ok
0
声望
2
楼层
122
资料浏览
0
粉丝
0
关注
q3ok 发布的帖子
-
openmvWiFi传输图像为什么在接收端显示错误?
将openmv用作STA接入局域网中,向另一端口传输图片,以下是openmv端的代码:
import sensor, image, time, socket, network, io wlan = network.WLAN(network.STA_IF) #STA模式 wlan.active(True) if not wlan.isconnected(): #网络连接 print('connecting to network...') wlan.connect('5352123', 'fasdfagdad') while not wlan.isconnected(): pass print('网络配置:', wlan.ifconfig()) sensor.reset() #设定摄像头参数 sensor.set_pixformat(sensor.JPEG) sensor.set_vflip(True) #垂直翻转 sensor.set_framesize(sensor.HVGA) sensor.skip_frames(time = 2000) clock = time.clock() s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM,0) #UDP传输 while(True): clock.tick() img = sensor.snapshot() #拍摄图片 #img = img.compressed(quality=35) s.sendto(img,("192.168.1.112",5454)) #接收端地址 #print(img) print(clock.fps())
用python在目标地址电脑上产生一个接收端程序,代码如下:
import socket import cv2 import io import numpy as np from PIL import Image from PIL import ImageFile ImageFile.LOAD_TRUNCATED_IMAGES = True s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0) #UDP传输 s.bind(("0.0.0.0", 5454)) #端口号 while True: data, IP = s.recvfrom(100000) #接收数据 bytes_stream = io.BytesIO(data) #转化为二进制流 image = Image.open(bytes_stream) #打开图片 img = np.asarray(image) img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR) # 传输的是RGB格式,要转换为BGR(opencv的格式) cv2.imshow("ESP32 Capture Image", img) if cv2.waitKey(1) == ord("q"): #退出条件 break
在运行后显示如下错误:
Traceback (most recent call last):
File "D:\python\wifi\main.py", line 15, in
image = Image.open(bytes_stream)
File "D:\Anaconda3\envs\gjp\lib\site-packages\PIL\Image.py", line 3298, in open
raise UnidentifiedImageError(msg)
PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x00000206C87E03B0>提示不能识别文件,这是什么原因导致的?