• 免费好用的星瞳AI云服务上线!简单标注,云端训练,支持OpenMV H7和OpenMV H7 Plus。可以替代edge impulse。 https://forum.singtown.com/topic/9519
  • 我们只解决官方正版的OpenMV的问题(STM32),其他的分支有很多兼容问题,我们无法解决。
  • 如果有产品硬件故障问题,比如无法开机,论坛很难解决。可以直接找售后维修
  • 发帖子之前,请确认看过所有的视频教程,https://singtown.com/learn/ 和所有的上手教程http://book.openmv.cc/
  • 每一个新的提问,单独发一个新帖子
  • 帖子需要目的,你要做什么?
  • 如果涉及代码,需要报错提示全部代码文本,请注意不要贴代码图片
  • 必看:玩转星瞳论坛了解一下图片上传,代码格式等问题。
  • 运行圆形识别代码并同步无心啊传输数据,socket error 返回-13 什么意思,如何解决?



    • 0_1587473461830_批注 2020-04-21 205042.png

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

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

      green_threshold = ( 0, 80, -70, -10, -0, 30)

      Reset sensor

      sensor.reset()

      Set sensor settings

      sensor.set_contrast(3)
      sensor.set_brightness(1)
      sensor.set_saturation(1)
      sensor.set_gainceiling(16)
      sensor.set_pixformat(sensor.GRAYSCALE)
      sensor.set_framesize(sensor.VGA)

      sensor.set_windowing((320, 240))

      Init wlan module in AP mode.

      wlan = network.WINC(mode=network.WINC.MODE_AP)

      Init wlan module in Download mode.

      #wlan = network.WINC(mode=network.WINC.MODE_FIRMWARE)

      For ATWINC1500-MR210PB only.

      #wlan.fw_update("/winc_19_6_1.bin")

      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\r\n" \
                  "Server: OpenMV\r\n" \
                  "Content-Type: application/json\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.
      
      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)