导航

    • 登录
    • 搜索
    • 版块
    • 产品
    • 教程
    • 论坛
    • 淘宝
    1. 主页
    2. vicm
    3. 楼层
    V
    • 举报资料
    • 资料
    • 关注
    • 粉丝
    • 屏蔽
    • 帖子
    • 楼层
    • 最佳
    • 群组

    vicm 发布的帖子

    • RE: 请问为什么写入不了数据,是我的代码有问题吗?

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

      发布在 OpenMV Cam
      V
      vicm
    • RE: openmv传输数据转存不到电脑上的txt文件里(第一个是openmv代码,第二个是电脑运行的py代码)

      我看过了,串口助手可以接收到数据

      发布在 OpenMV Cam
      V
      vicm
    • openmv传输数据转存不到电脑上的txt文件里(第一个是openmv代码,第二个是电脑运行的py代码)
      import sensor, image, time
      from pyb import UART
      import json
      # 初始化摄像头
      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)] # 根据实际情况调整
      uart = UART(3, 115200)
      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())
                  uart.write("({}, {})\n".format(blob.cx(), blob.cy()))
      
      import serial
      import os
      
      # 初始化串口
      ser = serial.Serial('COM3', 115200)  # 将 'COMX' 替换为OpenMV连接的串口号,9600 替换为与OpenMV设置相同的波特率
      
      # 检查文件是否存在,不存在则创建
      file_path = r'D:\data.txt'  # D盘中的目标文件路径
      if not os.path.exists(file_path):
          open(file_path, 'w').close()
      
      # 打开txt文件,以追加写入的方式
      with open(file_path, 'a') as file:
          while True:
              if ser.in_waiting > 0:  # 检查是否有可用数据
                  data = ser.readline().decode().strip('\n')  # 读取一行数据并解码成字符串,去除末尾的换行符
                  
                  # 将数据写入txt文件
                  file.write(data + '\n')
                  print("Received:", data)  # 打印接收到的数据
      
      发布在 OpenMV Cam
      V
      vicm
    • 请问为什么写入不了数据,是我的代码有问题吗?
      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 Cam
      V
      vicm