標籤:

星瞳科技OpenMV視頻教程12-WiFi無線圖傳

星瞳科技OpenMV視頻教程12-WiFi無線圖傳

來自專欄走在電子的前列線上 https://www.zhihu.com/video/986932072321228800

星瞳科技OpenMV官方代理視頻地址:點擊這裡!!!

嗶哩嗶哩地址:

星瞳科技OpenMV視頻教程12-WiFi無線圖傳_野生技術協會_科技_bilibili_嗶哩嗶哩

wifi通信

OpenMV官方擴展板採用ATWINC1500模組,可以傳輸圖像。

詳細參數:singtown.com/product/61

wifi掃描

無線傳輸圖像

無線傳輸小球坐標

import sensor, image, time, network, usocket, sys, jsonSSID =OPENMV_AP # Network SSIDKEY =1234567890 # Network key (must be 10 chars)HOST = # Use first available interfacePORT = 8080 # Arbitrary non-privileged portgreen_threshold = ( 0, 80, -70, -10, -0, 30)# Reset sensorsensor.reset()# Set sensor settingssensor.set_contrast(1)sensor.set_brightness(1)sensor.set_saturation(1)sensor.set_gainceiling(16)sensor.set_framesize(sensor.QQVGA)sensor.set_pixformat(sensor.GRAYSCALE)# 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)# You can block waiting for client to connect#print(wlan.wait_for_sta(10000))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(1024) # Should parse client request here # Send multipart header client.send("HTTP/1.1 200 OK
" "Server: OpenMV
" "Content-Type: application/json
" "Cache-Control: no-cache
" "Pragma: no-cache

") # FPS clock clock = time.clock() # Start streaming images # NOTE: Disable IDE preview to increase streaming FPS. img = sensor.snapshot() blobs = img.find_blobs([green_threshold]) if blobs: for b in blobs: img.draw_rectangle(b[0:4]) # rect img.draw_cross(b[5], b[6]) # cx, cy client.send(json.dumps(blobs)) 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. s.settimeout(3) response(s) except OSError as e: s.close() print("socket error: ", e) #sys.print_exception(e)

與傳輸圖像類似,瀏覽器輸入192.168.1.1:8080

就可以獲得json數據

如果想在自己的代碼中獲得數據,只需要GET 192.168.1.1:8080

就會獲得JSON。

例如python:

import requestsr = requests.get(192.168.1.1:8080)

只傳輸一張圖片

import sensor, image, time, network, usocket, sysSSID =OPENMV_AP # Network SSIDKEY =1234567890 # Network key (must be 10 chars)HOST = # Use first available interfacePORT = 8080 # Arbitrary non-privileged port# Reset sensorsensor.reset()# Set sensor settingssensor.set_contrast(1)sensor.set_brightness(1)sensor.set_saturation(1)sensor.set_gainceiling(16)sensor.set_framesize(sensor.QQVGA)sensor.set_pixformat(sensor.GRAYSCALE)# 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)# You can block waiting for client to connect#print(wlan.wait_for_sta(10000))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(1024) # Should parse client request here # Send multipart header client.send("HTTP/1.1 200 OK
" "Server: OpenMV
" "Content-Type: image/jpeg

") # 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.send(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. s.settimeout(3) response(s) except OSError as e: s.close() print("socket error: ", e) #sys.print_exception(e)

瀏覽器輸入192.168.1.1:8080,即可查看一張圖片。

常式講解WiFi-Shield->mjpeg_streamer_ap 熱點

# MJPEG Streaming AP.## 這個例子展示了如何在AccessPoint模式下進行MJPEG流式傳輸。# Android上的Chrome,Firefox和MJpegViewer App已經過測試。# 連接到OPENMV_AP並使用此URL:http://192.168.1.1:8080查看流。import sensor, image, time, network, usocket, sysSSID =OPENMV_AP # Network SSIDKEY =1234567890 # Network key (must be 10 chars)HOST = # Use first available interfacePORT = 8080 # Arbitrary non-privileged port# Reset sensorsensor.reset()# Set sensor settingssensor.set_contrast(1)sensor.set_brightness(1)sensor.set_saturation(1)sensor.set_gainceiling(16)sensor.set_framesize(sensor.QQVGA)sensor.set_pixformat(sensor.GRAYSCALE)# 在AP模式下啟動wlan模塊。wlan = network.WINC(mode=network.WINC.MODE_AP)wlan.start_ap(SSID, key=KEY, security=wlan.WEP, channel=2)#您可以阻止等待客戶端連接#print(wlan.wait_for_sta(10000))def start_streaming(s): print (Waiting for connections..) client, addr = s.accept() # 將客戶端套接字超時設置為2秒 client.settimeout(2.0) print (Connected to + addr[0] + : + str(addr[1])) # 從客戶端讀取請求 data = client.recv(1024) # 應該在這裡解析客戶端請求 # 發送多部分head client.send("HTTP/1.1 200 OK
" "Server: OpenMV
" "Content-Type: multipart/x-mixed-replace;boundary=openmv
" "Cache-Control: no-cache
" "Pragma: no-cache

") # FPS clock clock = time.clock() # 開始流媒體圖像 #註:禁用IDE預覽以增加流式FPS。 while (True): clock.tick() # Track elapsed milliseconds between snapshots(). frame = sensor.snapshot() cframe = frame.compressed(quality=35) header = "
--openmv
" "Content-Type: image/jpeg
" "Content-Length:"+str(cframe.size())+"

" client.send(header) client.send(cframe) print(clock.fps())while (True): # 創建伺服器套接字 s = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM) try: # Bind and listen s.bind([HOST, PORT]) s.listen(5) # 設置伺服器套接字超時 # 注意:由於WINC FW bug,如果客戶端斷開連接,伺服器套接字必須 # 關閉並重新打開。在這裡使用超時關閉並重新創建套接字。 s.settimeout(3) start_streaming(s) except OSError as e: s.close() print("socket error: ", e) #sys.print_exception(e)

推薦閱讀:

秋涼Lightroom視頻教程整理出來的文字教程
WGCNA分析,簡單全面的最新教程
Python基礎視頻教程全集分享
王晨霞手診視頻教程 視頻+文稿
星瞳科技OpenMV視頻教程06-追小球的雲台

TAG:視頻教程 |