星瞳实验室APP,快速收到回复
  • 每一个新的提问,单独发一个新帖子
  • 帖子需要目的,你要做什么?
  • 如果涉及代码,需要报错提示全部代码文本,请注意不要贴代码图片
  • 必看:玩转星瞳论坛了解一下图片上传,代码格式等问题。
  • 两个标志位为什么标志为2不能执行,



    • import sensor, image,time,pyb,utime
      import sensor, image, time,utime
      from pyb import UART
      p0 = pyb.Pin('P0', pyb.Pin.OUT_PP)
      p0.value(1)
      uart = UART(3, 19200)
      output_str=0
      yanse=0
      flag=2
      while 1:
      if uart.any():
      flag=uart.readline().decode()
      flag=int(flag)
      print(flag)
      if flag==1:
      sensor.reset()
      sensor.set_pixformat(sensor.GRAYSCALE)
      sensor.set_framesize(sensor.VGA)
      sensor.set_windowing((240, 240)) # look at center 240x240 pixels of the VGA resolution.
      sensor.skip_frames(30)
      sensor.set_auto_gain(False) # must turn this off to prevent image washout...
      clock = time.clock()
      clock.tick()
      img = sensor.snapshot()
      img.lens_corr(0.1) # strength of 1.8 is good for the 2.8mm lens.
      for code in img.find_qrcodes():
      img.draw_rectangle(code.rect(), color = (255, 0, 0))
      output_str="%s" % (code.payload())
      uart.write(output_str)
      print(output_str)
      pyb.delay(500)
      if output_str:
      p0.value(0)
      pyb.delay(10)
      p0.value(1)
      output_str=0
      flag=0
      if flag==2:
      thresholds = [(54, 74, 44, 91, -16, 52),(76, 48, -22, 75, -76, -25),(68, 83, -47, -22, -7, 40)] # generic_blue_thresholds
      sensor.reset()
      sensor.set_pixformat(sensor.RGB565)
      sensor.set_framesize(sensor.QVGA)
      sensor.skip_frames(time = 2000)
      sensor.set_auto_gain(False) # must be turned off for color tracking
      sensor.set_auto_whitebal(False) # must be turned off for color tracking
      clock = time.clock()
      utime.sleep_ms(2000)
      img = sensor.snapshot()
      blobs=img.find_blobs(thresholds, pixels_threshold=5000, area_threshold=400)
      for blob in blobs:
      img.draw_rectangle(blob.rect())
      img.draw_cross(blob.cx(), blob.cy())
      yanse="%s" % (blob.code())
      uart.write(yanse)
      print( yanse)
      pyb.delay(500)
      if yanse:
      p0.value(0)
      pyb.delay(10)
      p0.value(1)
      yanse=0



    • 代码缩进不对,逻辑不对。



    • 怎么修改呢,给一个提示可以吗



    • 第16行后面全部运行不到,因为在死循环外面。