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



    • import sensor, image, time
      # 初始化摄像头
      sensor.reset()
      sensor.set_pixformat(sensor.RGB565)
      sensor.set_framesize(sensor.QVGA)
      sensor.skip_frames(time = 10)
      sensor.set_auto_whitebal(False)  # 关闭自动白平衡
      sensor.set_auto_gain(False)  # 关闭自动增益
      # 定义颜色识别参数
      thresholds = [(0, 94, 51, 13, -65, 80)] # 根据实际情况调整
      # 打开文件准备写入数据
      with open("object_centers.txt", "w") as file:  # 使用绝对路径保存到根目录
          while(True):
              img = sensor.snapshot()
              # 查找目标颜色
              blobs = img.find_blobs(thresholds, pixels_threshold=200, area_threshold=200)
              if blobs:
                  # 找到目标,计算中心坐标
                  for blob in blobs:
                      img.draw_rectangle(blob.rect())
                      img.draw_cross(blob.cx(), blob.cy())
                      file.write("({}, {})\n".format(blob.cx(), blob.cy()))
      


    • 我测试你的代码,可以正常写入数据。注意OpenMV要重新插入电脑才能显示新的内容。



    • 但重新插入经常会出现磁盘损坏或文件损坏的情况



    • 我认为你没有写入数据,是因为没有识别到色块。

      写文件的时候断电容易造成文件系统故障。
      分开保存会好一些:

      import sensor, image, time
      # 初始化摄像头
      sensor.reset()
      sensor.set_pixformat(sensor.RGB565)
      sensor.set_framesize(sensor.QVGA)
      sensor.skip_frames(time = 10)
      sensor.set_auto_whitebal(False)  # 关闭自动白平衡
      sensor.set_auto_gain(False)  # 关闭自动增益
      # 定义颜色识别参数
      thresholds = [(0, 94, 51, 13, -65, 80)] # 根据实际情况调整
      # 打开文件准备写入数据
      num = 0
      while(True):
          img = sensor.snapshot()
          # 查找目标颜色
          blobs = img.find_blobs(thresholds, pixels_threshold=200, area_threshold=200)
          with open("object_center_%d.txt" % num, "w") as file:  # 使用绝对路径保存到根目录
              if blobs:
                  # 找到目标,计算中心坐标
                  for blob in blobs:
                      img.draw_rectangle(blob.rect())
                      img.draw_cross(blob.cx(), blob.cy())
                      file.write("({}, {})\n".format(blob.cx(), blob.cy()))
                  num += 1
                  print(num)