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



    • import sensor
      import image
      import time
      import network
      import usocket
      import sys
      import sensor
      import image
      import time
      import network
      import usocket
      import sys
      import math
      import pyb
      from pyb import UART
      from pyb import LED
      
      # 变量分配区
      # 绿色追踪
      threshold = [53, 238]
      Frame_Cnt = 0
      fCnt_tmp = [0, 0]
      count = 0
      rangefinder = 0
      
      # 局部函数定义区
      
      red_led = LED(1)
      green_led = LED(2)
      blue_led = LED(3)
      ir_led = LED(4)
      
      
      def get_rangefinder(uart_line):
          try:
              if (len(uart_line) < 8):
                  return 0xFF
              if(uart_line[0] != 0x59):
                  return 0xFF
              if(uart_line[1] != 0x59):
                  return 0xFF
              if(uart_line[2] != None and uart_line[3] != None):
                  return uart_line[3] * 256 | uart_line[2]
          except:
              return 20
              pass
      
      
      def ExceptionVar(var):
          data = []
          data.append(0)
          data.append(0)
      
          if var == -1:
              data[0] = 0
              data[1] = 0
          else:
              data[0] = var & 0xFF
              data[1] = var >> 8
          return data
      
      # 串口3 P4 P5 = TX RX
      # 串口1 P1 P2 = TX RX
      
      
      def UART_Send(FormType, Loaction0, Location1, range_finder=0):
          global Frame_Cnt
          global fCnt_tmp
          Frame_Head = [170, 170]
          Frame_End = [85, 85]
          fFormType_tmp = [FormType]
          Frame_Cnt += 1
      
          if Frame_Cnt > 65534:
              FrameCnt = 0
      
          fHead = bytes(Frame_Head)
      
          fCnt_tmp[0] = range_finder & 0xFF
          fCnt_tmp[1] = range_finder >> 8
          # if(range_finder != 0):
          #     fCnt_tmp[1] = range_finder
          fCnt = bytes(fCnt_tmp)
      
          fFormType = bytes(fFormType_tmp)
          fLoaction0 = bytes(ExceptionVar(Loaction0))
          fLoaction1 = bytes(ExceptionVar(Location1))
          fEnd = bytes(Frame_End)
          FrameBuffe = fHead + fCnt + fFormType + fLoaction0 + fLoaction1 + fEnd
          return FrameBuffe
      
      
      
      
      # main函数区
      sensor.set_contrast(3)
      sensor.set_gainceiling(16)
      sensor.set_framesize(sensor.VGA)
      sensor.set_windowing((320, 240))
      sensor.set_pixformat(sensor.GRAYSCALE)
      #sensor.skip_frames(time = 2000)
      sensor.set_auto_gain(False, value=100)
      
      clock = time.clock()
      uart = UART(3, 115200)
      uart_Rangefinder = UART(1, 115200)
      
      #文件导入特征点
      kpts1 = image.load_descriptor("/desc.orb")
      #img = sensor.snapshot()
      
      start = pyb.millis()
      while pyb.elapsed_millis(start)<10000:
          clock.tick()
          img = sensor.snapshot()
          kpts2 = img.find_keypoints(max_keypoints=150, threshold=10, normalized=False)
          if kpts2:
              match = image.match_descriptor(kpts1, kpts2, threshold=85)
              if(match.count()>10):
                  img.draw_rectangle(match.rect())
                  img.draw_cross(match.cx(), match.cy(), size=10)
              P0 = match.x()
              P1 = match.y()
              Type = 306
              print(Type,P0,P1)
      
          else:
              print("no find kpts")
              green_led.off()
              Type = 0xFF
              P0 = -1
              P1 = -1
      
          uart.write(UART_Send(Type, P0, P1))
      
      
      while(True):
          clock.tick()
          img = sensor.snapshot()
          circles = img.find_circles(threshold=4000, x_margin=100,
                                 y_margin=100, r_margin=10, r_min=2, r_max=100, r_step=2)
      
          if circles:
              green_led.on()
              for circle_ in circles:
                  img.draw_circle(circle_.x(), circle_.y(),
                              circle_.r(), color=(255, 0, 0))
                  img.draw_cross(circle_.x(), circle_.y())
                  P0 = circle_.x()
                  P1 = circle_.y()
                  Type = 202
                  print(Type, P0, P1)
              # uart.write(UART_Send(Type, P0, P1, rangefinder))
      
          else:
              print("no find circle")
              green_led.off()
              Type = 0xFF
              P0 = -1
              P1 = -1
      
      


    • 你的代码没有sensor.reset()

      运行hello world有没有问题?



    • 可以运行,但是一个程序可以像上面那样用两个while吗



    • @hmwy 可以,但是下面的死循环永远不会运行。