星瞳实验室APP,快速收到回复
  • 我们只解决官方正版的OpenMV的问题(STM32),其他的分支有很多兼容问题,我们无法解决。
  • 如果有产品硬件故障问题,比如无法开机,论坛很难解决。可以直接找售后维修
  • 发帖子之前,请确认看过所有的视频教程,https://singtown.com/learn/ 和所有的上手教程http://book.openmv.cc/
  • 每一个新的提问,单独发一个新帖子
  • 帖子需要目的,你要做什么?
  • 如果涉及代码,需要报错提示全部代码文本,请注意不要贴代码图片
  • 必看:玩转星瞳论坛了解一下图片上传,代码格式等问题。
  • 这个Capture Failed:-4是由什么导致的



    • 0_1597045798845_QQ截图20200810154927.png



    • 你用的是什么硬件?
      什么固件?
      什么程序?



    • 用了一个WIFI拓展版,和云台,由arduino给出控制信号,两个不同时使用,固件是3.6.70_1597214644038_4348.png

      import sensor, image, mjpeg, pyb, network, usocket, sys
      import time
      
      
      SSID ='OPENMV_AP'    # Network SSID
      KEY  ='1234567890'   # wifi密码(必须为10字符)
      HOST = ''           # 使用第一个可用的端口
      PORT = 8080         # 任意非特权端口
      
      
      from pid import PID
      from pyb import Servo
      from pyb import Pin
      pan_servo=Servo(1)
      tilt_servo=Servo(2)
      red_threshold  = (13, 49, 18, 61, 6, 47)
      pan_pid = PID(p=0.07, i=0, imax=90)
      tilt_pid = PID(p=0.05, i=0, imax=90)
      sensor.reset()
      
      # 设置传感器设置
      sensor.set_contrast(1)
      sensor.set_brightness(1)
      sensor.set_saturation(1)
      sensor.set_gainceiling(16)
      
      sensor.set_pixformat(sensor.RGB565)
      sensor.set_framesize(sensor.QQVGA)
      sensor.set_vflip(True)#将镜头倒转过来
      sensor.skip_frames(10)
      sensor.set_auto_whitebal(False)
      clock = time.clock()
      p_out = Pin('P9', Pin.OUT_PP)
      p_4 = Pin('P4', Pin.IN, Pin.PULL_UP)#设置p_1为输入引脚,并开启上拉电阻
      p_5 = Pin('P5', Pin.IN, Pin.PULL_UP)#设置p_2为输入引脚,并开启上拉电阻
      
      def find_max(blobs):
          max_size=0
          for blob in blobs:
              if blob[2]*blob[2] > max_size:
                  max_blob=blob
                  max_size = blob[2]*blob[2]
          return max_blob
      
      # 在AP模式下启动wlan模块。
      
      #您可以阻止等待客户端连接
      #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\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()
      
          # 开始流媒体图像
          #注:禁用IDE预览以增加流式FPS。
          while (True):
              if p_4.value()==0:
                  b = 0
              clock.tick() # 跟踪snapshots()之间经过的毫秒数。
              img = sensor.snapshot().lens_corr(1.8)
              blobs = img.find_circles(threshold = 1500, x_margin = 10, y_margin = 10, r_margin = 10,
              r_min = 2, r_max = 100, r_step = 2)
              if blobs:
                  p_out.high()
                  print("输出信号1")
                  max_blob = find_max(blobs)
                  img.draw_circle(max_blob.x(), max_blob.y(), max_blob.r(), color = (255, 0, 0))
                  img.draw_cross(int(max_blob[0]), int(max_blob[1]))
              else:
                  p_out.low()
                  print("输出信号0")
              frame = sensor.snapshot()
              cframe = frame.compressed(quality=35)
              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(1):
          if p_4.value() == 0:            #追踪
              a = 1
              img_writer = image.ImageWriter("/stream.bin")
              while(a == 1):
                  clock.tick()
                  img = sensor.snapshot().lens_corr(1.8)
                  img_writer.add_frame(img)#写入图片
                  blobs = img.find_circles(threshold = 1500, x_margin = 10, y_margin = 10, r_margin = 10,
                  r_min = 2, r_max = 100, r_step = 2)
                  if blobs:
                      p_out.high()
                      max_blob = find_max(blobs)
                      pan_error = max_blob[0]-img.width()/2
                      tilt_error = max_blob[1]-img.height()/2
                      print("pan_error: ", pan_error)
                      img.draw_circle(max_blob.x(), max_blob.y(), max_blob.r(), color = (255, 0, 0))
                      img.draw_cross(int(max_blob[0]), int(max_blob[1]))
                      pan_output=pan_pid.get_pid(pan_error,1)/2
                      tilt_output=tilt_pid.get_pid(tilt_error,1)
                      print("pan_output",pan_output)
                      pan_servo.angle(pan_servo.angle()-pan_output)
                      tilt_servo.angle(tilt_servo.angle()+tilt_output)
                      print(a)
                  
                  else:
                      p_out.low()
                  if p_5.value() == 0:
                      a = 0
                      print(a)
      
      
          elif p_5.value() == 0:               #图传
              b = 1
              wlan = network.WINC(mode=network.WINC.MODE_AP)
              wlan.start_ap(SSID, key=KEY, security=wlan.WEP, channel=2)
      
              while (b==1):
                  # 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)
      
      img_writer.close()
      
      


    • 你这个程序我没办法测试啊,能给一个我能测试的最小程序吗?和具体的操作步骤。



    • 这个可以测试

      import sensor, image, mjpeg, pyb, network, usocket, sys
      import time
      
      
      SSID ='OPENMV_AP'    # Network SSID
      KEY  ='1234567890'   # wifi密码(必须为10字符)
      HOST = ''           # 使用第一个可用的端口
      PORT = 8080         # 任意非特权端口
      
      
      from pid import PID
      from pyb import Servo
      from pyb import Pin
      pan_servo=Servo(1)
      tilt_servo=Servo(2)
      red_threshold  = (13, 49, 18, 61, 6, 47)
      pan_pid = PID(p=0.07, i=0, imax=90)
      tilt_pid = PID(p=0.05, i=0, imax=90)
      sensor.reset()
      
      # 设置传感器设置
      sensor.set_contrast(1)
      sensor.set_brightness(1)
      sensor.set_saturation(1)
      sensor.set_gainceiling(16)
      
      sensor.set_pixformat(sensor.RGB565)
      sensor.set_framesize(sensor.QQVGA)
      sensor.set_vflip(True)#将镜头倒转过来
      sensor.skip_frames(10)
      sensor.set_auto_whitebal(False)
      clock = time.clock()
      p_out = Pin('P9', Pin.OUT_PP)
      p_4 = Pin('P4', Pin.IN, Pin.PULL_UP)#设置p_1为输入引脚,并开启上拉电阻
      p_5 = Pin('P5', Pin.IN, Pin.PULL_UP)#设置p_2为输入引脚,并开启上拉电阻
      
      def find_max(blobs):
          max_size=0
          for blob in blobs:
              if blob[2]*blob[2] > max_size:
                  max_blob=blob
                  max_size = blob[2]*blob[2]
          return max_blob
      
      # 在AP模式下启动wlan模块。
      
      #您可以阻止等待客户端连接
      #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\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()
      
          # 开始流媒体图像
          #注:禁用IDE预览以增加流式FPS。
          while (True):
              if p_4.value()==0:
                  b = 0
              clock.tick() # 跟踪snapshots()之间经过的毫秒数。
              img = sensor.snapshot().lens_corr(1.8)
              blobs = img.find_circles(threshold = 1500, x_margin = 10, y_margin = 10, r_margin = 10,
              r_min = 2, r_max = 100, r_step = 2)
              if blobs:
                  p_out.high()
                  print("输出信号1")
                  max_blob = find_max(blobs)
                  img.draw_circle(max_blob.x(), max_blob.y(), max_blob.r(), color = (255, 0, 0))
                  img.draw_cross(int(max_blob[0]), int(max_blob[1]))
              else:
                  p_out.low()
                  print("输出信号0")
              frame = sensor.snapshot()
              cframe = frame.compressed(quality=35)
              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(1):
          #if p_4.value() >= 1:            #追踪
          print(p_4.value())
          a = 1
          img_writer = image.ImageWriter("/stream.bin")
          while(a == 1):
              clock.tick()
              img = sensor.snapshot().lens_corr(1.8)
              img_writer.add_frame(img)#写入图片
              blobs = img.find_circles(threshold = 1500, x_margin = 10, y_margin = 10, r_margin = 10,
              r_min = 2, r_max = 100, r_step = 2)
              if blobs:
                  p_out.high()
                  max_blob = find_max(blobs)
                  pan_error = max_blob[0]-img.width()/2
                  tilt_error = max_blob[1]-img.height()/2
                  print("pan_error: ", pan_error)
                  img.draw_circle(max_blob.x(), max_blob.y(), max_blob.r(), color = (255, 0, 0))
                  img.draw_cross(int(max_blob[0]), int(max_blob[1]))
                  pan_output=pan_pid.get_pid(pan_error,1)/2
                  tilt_output=tilt_pid.get_pid(tilt_error,1)
                  print("pan_output",pan_output)
                  pan_servo.angle(pan_servo.angle()-pan_output)
                  tilt_servo.angle(tilt_servo.angle()+tilt_output)
                  print(a)
                  
              else:
                      
                  p_out.low()
              if p_4.value() == 0:
                  a=a+1
                  print(a)
          
      
          '''elif p_5.value() == 0:               #图传
              b = 1
              wlan = network.WINC(mode=network.WINC.MODE_AP)
              wlan.start_ap(SSID, key=KEY, security=wlan.WEP, channel=2)
      
              while (b==1):
                  # 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)
      
      img_writer.close()'''
      
      


    • 运行几分钟他就出问题了



    • @kidswong999 您看看这是个什么错误



    • 我测试没发现问题,你联系售后寄回测试吧。