当前位置:   article > 正文

用python获取esp-32 cam的视频流_python 获取esp32cam视频流

python 获取esp32cam视频流

开始之前ESP32cam要烧写MicroPython固件。

烧写方法自行百度。

  1. import socket
  2. import network
  3. import camera
  4. import time
  5. #连接wifi
  6. wlan = network.WLAN(network.STA_IF)
  7. wlan.active(True)
  8. if not wlan.isconnected():
  9. print('connecting to network...')
  10. wlan.connect('uuu', '12345678')
  11. while not wlan.isconnected():
  12. pass
  13. print('网络配置:', wlan.ifconfig())
  14. #摄像头初始化
  15. try:
  16. camera.init(0, format=camera.JPEG)
  17. except Exception as e:
  18. camera.deinit()
  19. camera.init(0, format=camera.JPEG)
  20. #图像设置----------------------------
  21. ## Other settings:
  22. # flip up side down
  23. camera.flip(1)
  24. # left / right
  25. camera.mirror(1)
  26. # framesize
  27. camera.framesize(camera.FRAME_HVGA)
  28. # The options are the following:
  29. # FRAME_96X96 FRAME_QQVGA FRAME_QCIF FRAME_HQVGA FRAME_240X240
  30. # FRAME_QVGA FRAME_CIF FRAME_HVGA FRAME_VGA FRAME_SVGA
  31. # FRAME_XGA FRAME_HD FRAME_SXGA FRAME_UXGA FRAME_FHD
  32. # FRAME_P_HD FRAME_P_3MP FRAME_QXGA FRAME_QHD FRAME_WQXGA
  33. # FRAME_P_FHD FRAME_QSXGA
  34. # Check this link for more information: https://bit.ly/2YOzizz
  35. # special effects
  36. camera.speffect(camera.EFFECT_NONE)
  37. # The options are the following:
  38. # EFFECT_NONE (default) EFFECT_NEG EFFECT_BW EFFECT_RED EFFECT_GREEN EFFECT_BLUE EFFECT_RETRO
  39. # white balance
  40. camera.whitebalance(camera.WB_NONE)
  41. # The options are the following:
  42. # WB_NONE (default) WB_SUNNY WB_CLOUDY WB_OFFICE WB_HOME
  43. # saturation
  44. camera.saturation(0)
  45. # -2,2 (default 0). -2 grayscale
  46. # brightness
  47. camera.brightness(0)
  48. # -2,2 (default 0). 2 brightness
  49. # contrast
  50. camera.contrast(0)
  51. #-2,2 (default 0). 2 highcontrast
  52. # quality
  53. camera.quality(10)
  54. # 10-63 lower number means higher quality/
  55. #图像设置----------------------------
  56. #socket UDP 的创建
  57. s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM,0)
  58. while True:
  59. buf = camera.capture() # 获取图像数据
  60. s.sendto(buf,("192.168.43.61",9090)) # 向服务器发送图像数据
  61. time.sleep(0.1)

esp32cam代码部分,复制后保存即可。注意ip wifi账号密码改成自己的!

服务端代码

  1. import socket
  2. import cv2
  3. import io
  4. from PIL import Image
  5. import numpy as np
  6. s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0)
  7. s.bind(("192.168.43.61", 9090))
  8. while True:
  9. data, IP = s.recvfrom(100000)
  10. print("!1")
  11. bytes_stream = io.BytesIO(data)
  12. image = Image.open(bytes_stream)
  13. img = np.asarray(image)
  14. cv2.imshow("12", img)
  15. if cv2.waitKey(1) == ord("q"):
  16. break

 

从esp32cam获取的效果

 

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/383358
推荐阅读
相关标签
  

闽ICP备14008679号