• 免费好用的星瞳AI云服务上线!简单标注,云端训练,支持OpenMV H7和OpenMV H7 Plus。可以替代edge impulse。 https://forum.singtown.com/topic/9519
  • 我们只解决官方正版的OpenMV的问题(STM32),其他的分支有很多兼容问题,我们无法解决。
  • 如果有产品硬件故障问题,比如无法开机,论坛很难解决。可以直接找售后维修
  • 发帖子之前,请确认看过所有的视频教程,https://singtown.com/learn/ 和所有的上手教程http://book.openmv.cc/
  • 每一个新的提问,单独发一个新帖子
  • 帖子需要目的,你要做什么?
  • 如果涉及代码,需要报错提示全部代码文本,请注意不要贴代码图片
  • 必看:玩转星瞳论坛了解一下图片上传,代码格式等问题。
  • 大佬,这个是怎么回事?应该怎么解决?这是已经插上SD卡了,没插也是类似错误。为什么?



    • 0_1540130736075_a8472630-fc75-46f5-9d25-c38ac2160e36-image.png



    • 你要发你的代码。



    • import pyb
      import sensor, image, time,utime
      import car
      from pid import PID
      from pyb import UART
      from pyb import Pin
      from pyb import Timer
      sensor.reset()
      sensor.set_vflip(True)
      sensor.set_hmirror(True)
      sensor.set_pixformat(sensor.RGB565)
      sensor.set_framesize(sensor.QQVGA)
      sensor.skip_frames(10)
      sensor.set_auto_whitebal(False)
      clock = time.clock()
      uart = UART(3, 115200)
      thresholds = [(0, 100, 23, 127, -128, 127),
                    (0, 100, -128, -20, 126, -128),
                    (0, 80, 0, -128, -8, -128)]
      size_threshold = 500000
      x_pid = PID(p=0.5, i=1, imax=100)
      h_pid = PID(p=0.05, i=0.1, imax=50)
      def func():
          car.run(50,50)
      def find_max(blobs):
          max_size=0
          for blob in blobs:
              if blob[2]*blob[3] > max_size:
                  max_blob=blob
                  max_size = blob[2]*blob[3]
          return max_blob
      m = [0,0,0]
      flag1 = 1
      flag2 = 1
      flag3 = 1
      while(True):
          clock.tick()
          if(time.ticks()<=2700):
              car.run(0,0)
          elif(time.ticks()<=3500):
              car.run(100,100)
          elif(time.ticks()<=4500):
              car.run(50,-50)
          elif(time.ticks()<=7500):
              car.run(100,100)
          elif(time.ticks()<=8500):
              car.run(50,-50)
          elif(time.ticks()<=9000):
              car.run(100,100)
          else:
              car.run(0,0)
          img = sensor.snapshot()
          img.lens_corr(1)
          for code in img.find_qrcodes():
              uart.write(code.payload())
              m=list(code.payload())
              if(m!=[0,0,0]):
                  print(m)
                  while(flag1):
                      sensor.set_auto_whitebal(False)
                      img = sensor.snapshot()
                      if(m[0]=='1'):
                          blobs = img.find_blobs([thresholds[0]])
                          if blobs:
                              max_blob = find_max(blobs)
                              x_error = max_blob[5]-img.width()/2
                              h_error = max_blob[2]*max_blob[3]-size_threshold
                              img.draw_rectangle(max_blob[0:4])
                              img.draw_cross(max_blob[5], max_blob[6])
                              x_output=x_pid.get_pid(x_error,1)
                              h_output=h_pid.get_pid(h_error,1)
                              car.run(-h_output-x_output,-h_output+x_output)
                              blobs = img.find_blobs([thresholds[0]])
                              k = h_error+500000
                              if(k>=16000):
                                  img = sensor.snapshot()
                                  tim = time.ticks()
                                  while(tim+500>=time.ticks()):
                                      img = sensor.snapshot()
                                      car.run(50,50)
                                  tim = time.ticks()
                                  while(tim+2000>=time.ticks()):
                                      img = sensor.snapshot()
                                      car.run(0,0)
                                  tim = time.ticks()
                                  while(tim+1000>=time.ticks()):
                                      img = sensor.snapshot()
                                      car.run(-100,-100)
                                  while(True):
                                      img = sensor.snapshot()
                                      blobs = img.find_blobs([thresholds[0]])
                                      if blobs:
                                          max_blob = find_max(blobs)
                                          x_error = max_blob[5]-img.width()/2
                                          h_error = max_blob[2]*max_blob[3]-size_threshold
                                          img.draw_rectangle(max_blob[0:4])
                                          img.draw_cross(max_blob[5], max_blob[6])
                                          x_output=x_pid.get_pid(x_error,1)
                                          h_output=h_pid.get_pid(h_error,1)
                                          car.run(-h_output-x_output,-h_output+x_output)
                                          blobs = img.find_blobs([thresholds[0]])
                                          k = h_error+500000
                                          if k >= 1000:
                                              img = sensor.snapshot()
                                              tim = time.ticks()
                                              while(tim+1000>=time.ticks()):
                                                  img = sensor.snapshot()
                                                  car.run(50,50)
                                              tim = time.ticks()
                                              while(tim+2000>=time.ticks()):
                                                  img = sensor.snapshot()
                                                  car.run(0,0)
                                              tim = time.ticks()
                                              while(tim+1000>=time.ticks()):
                                                  img = sensor.snapshot()
                                                  car.run(-100,-100)
                                              while(True):
                                                  img = sensor.snapshot()
                                                  if(m[1]=='2'):
                                                      blobs = img.find_blobs([thresholds[1]])
                                                      if blobs:
                                                          max_blob = find_max(blobs)
                                                          x_error = max_blob[5]-img.width()/2
                                                          h_error = max_blob[2]*max_blob[3]-size_threshold
                                                          img.draw_rectangle(max_blob[0:4])
                                                          img.draw_cross(max_blob[5], max_blob[6])
                                                          x_output=x_pid.get_pid(x_error,1)
                                                          h_output=h_pid.get_pid(h_error,1)
                                                          car.run(-h_output-x_output,-h_output+x_output)
                                                          k = h_error+500000
                                                          if(k>=16000):
                                                              img = sensor.snapshot()
                                                              tim = time.ticks()
                                                              while(tim+500>=time.ticks()):
                                                                  img = sensor.snapshot()
                                                                  car.run(50,50)
                                                              tim = time.ticks()
                                                              while(tim+2000>=time.ticks()):
                                                                  img = sensor.snapshot()
                                                                  car.run(0,0)
                                                              tim = time.ticks()
                                                              while(tim+1000>=time.ticks()):
                                                                  img = sensor.snapshot()
                                                                  car.run(-100,-100)
                                                              while(True):
                                                                  img = sensor.snapshot()
                                                                  blobs = img.find_blobs([thresholds[1]])
                                                                  if blobs:
                                                                      max_blob = find_max(blobs)
                                                                      x_error = max_blob[5]-img.width()/2
                                                                      h_error = max_blob[2]*max_blob[3]-size_threshold
                                                                      img.draw_rectangle(max_blob[0:4])
                                                                      img.draw_cross(max_blob[5], max_blob[6])
                                                                      x_output=x_pid.get_pid(x_error,1)
                                                                      h_output=h_pid.get_pid(h_error,1)
                                                                      car.run(-h_output-x_output,-h_output+x_output)
                                                                      blobs = img.find_blobs([thresholds[1]])
                                                                      k = h_error+500000
                                                                      if k >= 1000:
                                                                          img = sensor.snapshot()
                                                                          tim = time.ticks()
                                                                          while(tim+1000>=time.ticks()):
                                                                              img = sensor.snapshot()
                                                                              car.run(50,50)
                                                                          tim = time.ticks()
                                                                          while(tim+2000>=time.ticks()):
                                                                              img = sensor.snapshot()
                                                                              car.run(0,0)
                                                                          tim = time.ticks()
                                                                          while(tim+1000>=time.ticks()):
                                                                              img = sensor.snapshot()
                                                                              car.run(-100,-100)
                                                                          while(True):
                                                                              if(m[2]=='3'):
                                                                                  blobs = img.find_blobs([thresholds[2]])
                                                                                  if blobs:
                                                                                      max_blob = find_max(blobs)
                                                                                      x_error = max_blob[5]-img.width()/2
                                                                                      h_error = max_blob[2]*max_blob[3]-size_threshold
                                                                                      img.draw_rectangle(max_blob[0:4])
                                                                                      img.draw_cross(max_blob[5], max_blob[6])
                                                                                      x_output=x_pid.get_pid(x_error,1)
                                                                                      h_output=h_pid.get_pid(h_error,1)
                                                                                      car.run(-h_output-x_output,-h_output+x_output)
                                                                                      k = h_error+500000
                                                                                      if(k>=16000):
                                                                                          img = sensor.snapshot()
                                                                                          tim = time.ticks()
                                                                                          while(tim+500>=time.ticks()):
                                                                                              img = sensor.snapshot()
                                                                                              car.run(50,50)
                                                                                          tim = time.ticks()
                                                                                          while(tim+2000>=time.ticks()):
                                                                                              img = sensor.snapshot()
                                                                                              car.run(0,0)
                                                                                          tim = time.ticks()
                                                                                          while(tim+1000>=time.ticks()):
                                                                                              img = sensor.snapshot()
                                                                                              car.run(-100,-100)
                                                                                          while(True):
                                                                                              img = sensor.snapshot()
                                                                                              blobs = img.find_blobs([thresholds[2]])
                                                                                              if blobs:
                                                                                                  max_blob = find_max(blobs)
                                                                                                  x_error = max_blob[5]-img.width()/2
                                                                                                  h_error = max_blob[2]*max_blob[3]-size_threshold
                                                                                                  img.draw_rectangle(max_blob[0:4])
                                                                                                  img.draw_cross(max_blob[5], max_blob[6])
                                                                                                  x_output=x_pid.get_pid(x_error,1)
                                                                                                  h_output=h_pid.get_pid(h_error,1)
                                                                                                  car.run(-h_output-x_output,-h_output+x_output)
                                                                                                  blobs = img.find_blobs([thresholds[2]])
                                                                                                  k = h_error+500000
                                                                                                  if k >= 1000:
                                                                                                      img = sensor.snapshot()
                                                                                                      tim = time.ticks()
                                                                                                      while(tim+1000>=time.ticks()):
                                                                                                          img = sensor.snapshot()
                                                                                                          car.run(50,50)
                                                                                                      tim = time.ticks()
                                                                                                      while(tim+2000>=time.ticks()):
                                                                                                          img = sensor.snapshot()
                                                                                                          car.run(0,0)
                                                                                                      tim = time.ticks()
                                                                                                      while(tim+1000>=time.ticks()):
                                                                                                          img = sensor.snapshot()
                                                                                                          car.run(-100,-100)
                                                                                              else:
                                                                                                  car.run(50,-50)
                                                                                            
                                                                                  else:
                                                                                      car.run(50,-50)
                                                                  else:
                                                                      car.run(50,-50)
                                                                
                                                      else:
                                                          car.run(50,-50)
                                                  if(m[1]=='3'):
                                                      blobs = img.find_blobs([thresholds[2]])
                                                      if blobs:
                                                          max_blob = find_max(blobs)
                                                          x_error = max_blob[5]-img.width()/2
                                                          h_error = max_blob[2]*max_blob[3]-size_threshold
                                                          img.draw_rectangle(max_blob[0:4])
                                                          img.draw_cross(max_blob[5], max_blob[6])
                                                          x_output=x_pid.get_pid(x_error,1)
                                                          h_output=h_pid.get_pid(h_error,1)
                                                          car.run(-h_output-x_output,-h_output+x_output)
                                                          k = h_error+500000
                                                          if(k>=16000):
                                                              img = sensor.snapshot()
                                                              tim = time.ticks()
                                                              while(tim+500>=time.ticks()):
                                                                  img = sensor.snapshot()
                                                                  car.run(50,50)
                                                              tim = time.ticks()
                                                              while(tim+2000>=time.ticks()):
                                                                  img = sensor.snapshot()
                                                                  car.run(0,0)
                                                              tim = time.ticks()
                                                              while(tim+1000>=time.ticks()):
                                                                  img = sensor.snapshot()
                                                                  car.run(-100,-100)
                                                              while(True):
                                                                  img = sensor.snapshot()
                                                                  blobs = img.find_blobs([thresholds[2]])
                                                                  if blobs:
                                                                      max_blob = find_max(blobs)
                                                                      x_error = max_blob[5]-img.width()/2
                                                                      h_error = max_blob[2]*max_blob[3]-size_threshold
                                                                      img.draw_rectangle(max_blob[0:4])
                                                                      img.draw_cross(max_blob[5], max_blob[6])
                                                                      x_output=x_pid.get_pid(x_error,1)
                                                                      h_output=h_pid.get_pid(h_error,1)
                                                                      car.run(-h_output-x_output,-h_output+x_output)
                                                                      blobs = img.find_blobs([thresholds[2]])
                                                                      k = h_error+500000
                                                                      if k >= 1000:
                                                                          img = sensor.snapshot()
                                                                          tim = time.ticks()
                                                                          while(tim+1000>=time.ticks()):
                                                                              img = sensor.snapshot()
                                                                              car.run(50,50)
                                                                          tim = time.ticks()
                                                                          while(tim+2000>=time.ticks()):
                                                                              img = sensor.snapshot()
                                                                              car.run(0,0)
                                                                          tim = time.ticks()
                                                                          while(tim+1000>=time.ticks()):
                                                                              img = sensor.snapshot()
                                                                              car.run(-100,-100)
                                                                          while(True):
                                                                              if(m[2]=='2'):
                                                                                  blobs = img.find_blobs([thresholds[1]])
                                                                                  if blobs:
                                                                                      max_blob = find_max(blobs)
                                                                                      x_error = max_blob[5]-img.width()/2
                                                                                      h_error = max_blob[2]*max_blob[3]-size_threshold
                                                                                      img.draw_rectangle(max_blob[0:4])
                                                                                      img.draw_cross(max_blob[5], max_blob[6])
                                                                                      x_output=x_pid.get_pid(x_error,1)
                                                                                      h_output=h_pid.get_pid(h_error,1)
                                                                                      car.run(-h_output-x_output,-h_output+x_output)
                                                                                      k = h_error+500000
                                                                                      if(k>=16000):
                                                                                          img = sensor.snapshot()
                                                                                          tim = time.ticks()
                                                                                          while(tim+500>=time.ticks()):
                                                                                              img = sensor.snapshot()
                                                                                              car.run(50,50)
                                                                                          tim = time.ticks()
                                                                                          while(tim+2000>=time.ticks()):
                                                                                              img = sensor.snapshot()
                                                                                              car.run(0,0)
                                                                                          tim = time.ticks()
                                                                                          while(tim+1000>=time.ticks()):
                                                                                              img = sensor.snapshot()
                                                                                              car.run(-100,-100)
                                                                                          while(True):
                                                                                              img = sensor.snapshot()
                                                                                              blobs = img.find_blobs([thresholds[1]])
                                                                                              if blobs:
                                                                                                  max_blob = find_max(blobs)
                                                                                                  x_error = max_blob[5]-img.width()/2
                                                                                                  h_error = max_blob[2]*max_blob[3]-size_threshold
                                                                                                  img.draw_rectangle(max_blob[0:4])
                                                                                                  img.draw_cross(max_blob[5], max_blob[6])
                                                                                                  x_output=x_pid.get_pid(x_error,1)
                                                                                                  h_output=h_pid.get_pid(h_error,1)
                                                                                                  car.run(-h_output-x_output,-h_output+x_output)
                                                                                                  blobs = img.find_blobs([thresholds[1]])
                                                                                                  k = h_error+500000
                                                                                                  if k >= 1000:
                                                                                                      img = sensor.snapshot()
                                                                                                      tim = time.ticks()
                                                                                                      while(tim+1000>=time.ticks()):
                                                                                                          img = sensor.snapshot()
                                                                                                          car.run(50,50)
                                                                                                      tim = time.ticks()
                                                                                                      while(tim+2000>=time.ticks()):
                                                                                                          img = sensor.snapshot()
                                                                                                          car.run(0,0)
                                                                                                      tim = time.ticks()
                                                                                                      while(tim+1000>=time.ticks()):
                                                                                                          img = sensor.snapshot()
                                                                                                          car.run(-100,-100)
                                                                                          else:
                                                                                              car.run(50,-50)
                                                                                        
                                                                              else:
                                                                                  car.run(50,-50)
                                                                  else:
                                                                      car.run(50,-50)
                                                                
                                                      else:
                                                          car.run(50,-50)
                                          else:
                                          car.run(50,-50)
                          else:
                              car.run(50,-50)
      


    • @kidswong999 老板,这个怎么解决,麻烦啦。





    • @kidswong999 咱能不能具体问题给出一些具体的措施?你那个统一回复我还是不知道我这个程序该怎么改,怎么解决问题。



    • 根据我的猜测,可能是一次性代码太长了。

      在IDE里运行的时候,其实是通过串口把所有的代码文字传输给OpenMV,然后运行,好像是这个问题。

      解决办法:多模块编程,把任务分开,分割成不同的文件。