logo

急急急Wifi 传图不支持高清图片吗?不支持的话,这个sensor.WQXGA2: 2592x1944 格式是咋用的

2023-07-25 14:56
U
Kevin
import sensor, image, time, network, usocket, sys

import sensor, image, time, network, usocket, sys

SSID ='HSAuto'
KEY  ='Aa123456'
HOST =' 10.119.96.163'
PORT = 8082

# Reset sensor
sensor.reset()
sensor.set_framesize(sensor.WQXGA2)
sensor.set_pixformat(sensor.RGB565)

# Init wlan module and connect to network
print("Trying to connect... (may take a while)...")
wlan = network.WINC()
wlan.connect(SSID, key=KEY, security=wlan.WPA_PSK)

# We should have a valid IP now via DHCP
print(wlan.ifconfig())

# Create server socket
s = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM)

# Bind and listen
s.bind([HOST, PORT])
s.listen(5)
print(s)
# Set server socket to blocking
s.setblocking(True)

def response(s):
    print ('Waiting for connections..')
    client, addr = s.accept()
    # set client socket timeout to 2s
    client.settimeout(2.0)
    print ('Connected to ' + addr[0] + ':' + str(addr[1]))

    # Read request from client
    #data = client.recv(8192)
    # Should parse client request here

    # Send multipart header
    client.send("HTTP/1.1 200 OK\r\n" \
                "Server: OpenMV\r\n" \
                "Content-Type: image/jpeg\r\n\r\n")

    # FPS clock
    clock = time.clock()

    # Start streaming images
    # NOTE: Disable IDE preview to increase streaming FPS.


    frame = sensor.snapshot()
    cframe = frame.compressed(quality=35)
    client.write(cframe)
    client.close()

while (True):
    # Create server socket
    s = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM)
    try:
        # Bind and listen
        s.bind([HOST, PORT])
        s.listen(5)

        # Set server socket timeout
        # NOTE: Due to a WINC FW bug, the server socket must be closed and reopened if
        # the client disconnects. Use a timeout here to close and re-create the socket.

        response(s)
        s.settimeout(60)
    except OSError as e:
        s.close()
        print("socket error: ", e)
        #sys.print_exception(e)
7572b0c1-4522-4e2a-ae52-cb2eb226b83e.png
2023-07-25 16:32
U
Kevin

在补上一张 不支持高清图片的错误

2284bf25-9b50-4241-bde3-41d8855c3a0d.png
2023-07-25 17:04
I
网红小智智 星瞳科技

改成

sensor.set_pixformat(sensor.JPEG)
sensor.set_framesize(sensor.WQXGA2)

然后把compressed()删掉。

注意分辨率太高了会非常慢。

2023-07-25 20:35
U
Kevin

@kidswong999 在 [急急急Wifi 传图不支持高清图片吗?不支持的话,这个sensor\.WQXGA2: 2592x1944 格式是咋用的](/post/29634) 中说:

> sensor.set_pixformat(sensor.JPEG)

> sensor.set_framesize(sensor.WQXGA2)

8a97e70e-8057-4cba-a6bb-b260cdc5cd21.png

还是不行,内存不够吧

2023-07-26 09:52
U
Kevin

@kidswong999 在 [急急急Wifi 传图不支持高清图片吗?不支持的话,这个sensor\.WQXGA2: 2592x1944 格式是咋用的](/post/29634) 中说:

> sensor.set_pixformat(sensor.JPEG)

> sensor.set_framesize(sensor.WQXGA2)

使用Wifi传输的时候 就会出现这个问题,请问该怎样解决

U
Kevin

@kidswong999 删掉compressed()之后 图片就成这样了

96d33def-96cd-4197-abaa-443826e41e4d.png

这样也没办法用啊

2023-07-26 19:21
I
网红小智智 星瞳科技
# MJPEG Streaming AP.
#
# This example shows off how to do MJPEG streaming in AccessPoint mode.
# Chrome, Firefox and MJpegViewer App on Android have been tested.
# Connect to OPENMV_AP and use this URL: http://192.168.1.1:8080 to view the stream.

import sensor, image, time, network, usocket, sys

SSID ='OPENMV_AP'    # Network SSID
KEY  ='1234567890'    # Network key (must be 10 chars)
HOST = ''           # Use first available interface
PORT = 8080         # Arbitrary non-privileged port

# Reset sensor
sensor.reset()
sensor.set_framesize(sensor.WQXGA2)
sensor.set_pixformat(sensor.JPEG)

# Init wlan module in AP mode.
wlan = network.WINC(mode=network.WINC.MODE_AP)
wlan.start_ap(SSID, key=KEY, security=wlan.WEP, channel=2)
print("AP mode started. SSID: {} IP: {}".format(SSID, wlan.ifconfig()[0]))

# You can block waiting for client to connect
#print(wlan.wait_for_sta(10000))

def start_streaming(s):
    print ('Waiting for connections..')
    client, addr = s.accept()
    # set client socket timeout to 2s
    client.settimeout(2.0)
    print ('Connected to ' + addr[0] + ':' + str(addr[1]))

    # Read request from client
    data = client.recv(1024)
    # Should parse client request here

    # Send multipart header
    client.send("HTTP/1.1 200 OK\r\n" \
                "Server: OpenMV\r\n" \
                "Content-Type: multipart/x-mixed-replace;boundary=openmv\r\n" \
                "Cache-Control: no-cache\r\n" \
                "Pragma: no-cache\r\n\r\n")

    # FPS clock
    clock = time.clock()

    # Start streaming images
    # NOTE: Disable IDE preview to increase streaming FPS.
    while (True):
        clock.tick() # Track elapsed milliseconds between snapshots().
        cframe = sensor.snapshot()
        header = "\r\n--openmv\r\n" \
                 "Content-Type: image/jpeg\r\n"\
                 "Content-Length:"+str(cframe.size())+"\r\n\r\n"
        client.send(header)
        client.send(cframe)
        print(clock.fps())

while (True):
    # Create server socket
    s = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM)
    try:
        # Bind and listen
        s.bind([HOST, PORT])
        s.listen(5)

        # Set server socket timeout
        # NOTE: Due to a WINC FW bug, the server socket must be closed and reopened if
        # the client disconnects. Use a timeout here to close and re-create the socket.
        s.settimeout(3)
        start_streaming(s)
    except OSError as e:
        s.close()
        print("socket error: ", e)
        #sys.print_exception(e)

固件版本4.4.2,OpenMV4 H7 Plus,运行没问题。