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



    • 想把识别到的简单数据直接写入一个文本文件,但报错0_1564620942061_8RSF5_)0BBNZOXKV$DN8_K2.png

      while(True):
          clock.tick()
          img = sensor.snapshot()
          f = open("test.txt")
          for tag in img.find_apriltags(families=tag_families): # defaults to TAG36H11 without "families".
              img.draw_rectangle(tag.rect(), color = (255, 0, 0))
              img.draw_cross(tag.cx(), tag.cy(), color = (0, 255, 0))
              print_args = (family_name(tag), tag.id(), (180 * tag.rotation()) / math.pi)
              id = tag.id()
              f.write(id)
      


    • 请提供全部的代码,否则我没办法测试。



    • 
      import sensor, image, time, math, pyb
      
      sensor.reset()
      sensor.set_pixformat(sensor.RGB565)
      sensor.set_framesize(sensor.QQVGA) # we run out of memory if the resolution is much bigger...
      sensor.skip_frames(time = 2000)
      sensor.set_auto_gain(False)  # must turn this off to prevent image washout...
      sensor.set_auto_whitebal(False)  # must turn this off to prevent image washout...
      clock = time.clock()
      
      tag_families = 0
      tag_families |= image.TAG16H5 # comment out to disable this family
      tag_families |= image.TAG25H7 # comment out to disable this family
      tag_families |= image.TAG25H9 # comment out to disable this family
      tag_families |= image.TAG36H10 # comment out to disable this family
      tag_families |= image.TAG36H11 # comment out to disable this family (default family)
      tag_families |= image.ARTOOLKIT # comment out to disable this family
      
      def family_name(tag):
          if(tag.family() == image.TAG16H5):
              return "TAG16H5"
          if(tag.family() == image.TAG25H7):
              return "TAG25H7"
          if(tag.family() == image.TAG25H9):
              return "TAG25H9"
          if(tag.family() == image.TAG36H10):
              return "TAG36H10"
          if(tag.family() == image.TAG36H11):
              return "TAG36H11"
          if(tag.family() == image.ARTOOLKIT):
              return "ARTOOLKIT"
      
      while(True):
          clock.tick()
          img = sensor.snapshot()
          f = open("test.txt")
          for tag in img.find_apriltags(families=tag_families): # defaults to TAG36H11 without "families".
              img.draw_rectangle(tag.rect(), color = (255, 0, 0))
              img.draw_cross(tag.cx(), tag.cy(), color = (0, 255, 0))
              print_args = (family_name(tag), tag.id(), (180 * tag.rotation()) / math.pi)
              #print("Tag Family %s, Tag ID %d, rotation %f (degrees)" % print_args)
              id = tag.id()
              f.write(id)        
          #print(clock.fps())
      
      


    • @kidswong999 麻烦了



    • 需要把id从数字变为字符串,然后写入文件。
      f.write(str(id))

      PS:你这个代码。。。只open,不close啊。



    • @kidswong999 谢提醒,close了😂 但改为写入字符串就又出现了了不知名错误……0_1564662247648_56b8ffa5-e4a9-46f3-81c9-9b9150b560fa-image.png





    • @kidswong999 感谢