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



    • 0_1656ng

      
      

      openmv代码
      import sensor, image, time
      from pyb import UART
      import json
      #设置颜色阈值
      yellow_threshold = (65, 100, -10, 6, 24, 51)

      #sensor.set_auto_gain() 自动增益开启(True)或者关闭(False)。在使用颜色追踪时,需要关闭自动#增益。
      #sensor.set_auto_whitebal() 自动白平衡开启(True)或者关闭(False)。在使用颜色追踪时,需要##关闭自动白平衡。
      #sensor.set_auto_exposure(enable[, exposure_us])
      #enable 打开(True)或关闭(False)自动曝光。默认打开。
      #如果 enable 为False, 则可以用 exposure_us 设置一个固定的曝光时间(以微秒为单位)。

      sensor.reset() # 初始化
      sensor.set_pixformat(sensor.RGB565) # use RGB565.
      sensor.set_framesize(sensor.QQVGA) # use QQVGA for speed.
      sensor.skip_frames(10) # 跳过n张照片,在更改设置后,跳过一些帧,等待感光元件变稳定
      sensor.set_auto_gain(False) #在使用颜色追踪时,需要关闭自动#增益。
      sensor.set_auto_whitebal(False) #在使用颜色追踪时,需要##关闭自动白平衡。
      clock = time.clock() # Tracks FPS.

      uart = UART(3, 115200)
      def find_max(blobs):
      max_size=0
      for blob in blobs:
      if blob.pixels() > max_size:
      max_blob=blob
      max_size = blob.pixels()
      return max_blob

      while(True):
      img = sensor.snapshot() # Take a picture and return the image.

      blobs = img.find_blobs([yellow_threshold])
      if blobs:
          max_blob=find_max(blobs)
          print('sum :', len(blobs))
          img.draw_rectangle(max_blob.rect())
          img.draw_cross(max_blob.cx(), max_blob.cy())
      
          output_str="[%d,%d]" % (max_blob.cx(),max_blob.cy()) #方式1
          #output_str=json.dumps([max_blob.cx(),max_blob.cy()]) #方式2
      
          print('you send:',output_str)
          uart.write(output_str+'\r\n')
      else:
          print('not found!')
      

      arduino代码
      #include <SoftwareSerial.h>

      SoftwareSerial softSerial(10, 11); // RX, TX 软串口通讯
      typedef struct
      {
      int data[50][2] = {{0,0}}; //50行2列数组(理解为)
      int len = 0;
      }List;
      List list; //结构体

      void setup() {
      softSerial.begin(115200);//openmv对应波特率
      Serial.begin(115200);
      }

      void loop() {
      if(softSerial.available())//检测软串口缓存
      {
      getList(); //获取数据
      for (int i=0; i<list.len; i++)
      {
      Serial.print(list.data[i][0]);
      Serial.print('\t');
      Serial.println(list.data[i][1]);
      }
      Serial.println("============");
      clearList();
      }

      }

      String detectString()
      {
      while(softSerial.read() != '{'); //arduino接收到的数据{}内的数据
      return(softSerial.readStringUntil('}'));
      }
      void clearList()
      {
      memset(list.data, sizeof(list.data),0);
      list.len = 0;
      }
      void getList()
      {
      String s = detectString(); //创建字符串
      String numStr = "";
      for(int i = 0; i<s.length(); i++)
      {
      if(s[i]=='('){
      numStr = "";
      }
      else if(s[i] == ','){
      list.data[list.len][0] = numStr.toInt();//将string转换为int
      numStr = "";
      }
      else if(s[i]==')'){ //openmv发送数据的倒数第二个作为结束标记
      list.data[list.len][1] = numStr.toInt();//将string转换为int
      numStr = "";
      list.len++;
      }
      else{
      numStr += s[i];
      }
      }
      }

      
      

      arduino没有反应呀,老师帮忙解决一下咋回事儿,接线是tx-p5 rx-p4 gnd-gnd



    • import sensor, image, time
      from pyb import UART
      import json
      #设置颜色阈值
      yellow_threshold   = (65, 100, -10, 6, 24, 51)
       
      #sensor.set_auto_gain() 自动增益开启(True)或者关闭(False)。在使用颜色追踪时,需要关闭自动#增益。
      #sensor.set_auto_whitebal() 自动白平衡开启(True)或者关闭(False)。在使用颜色追踪时,需要##关闭自动白平衡。
      #sensor.set_auto_exposure(enable[\, exposure_us])
      #enable 打开(True)或关闭(False)自动曝光。默认打开。
      #如果 enable 为False, 则可以用 exposure_us 设置一个固定的曝光时间(以微秒为单位)。
       
      sensor.reset() # 初始化
      sensor.set_pixformat(sensor.RGB565) # use RGB565.
      sensor.set_framesize(sensor.QQVGA) # use QQVGA for speed.
      sensor.skip_frames(10) # 跳过n张照片,在更改设置后,跳过一些帧,等待感光元件变稳定
      sensor.set_auto_gain(False) #在使用颜色追踪时,需要关闭自动#增益。
      sensor.set_auto_whitebal(False) #在使用颜色追踪时,需要##关闭自动白平衡。
      clock = time.clock() # Tracks FPS.
       
      uart = UART(3, 115200)
      def find_max(blobs):
          max_size=0
          for blob in blobs:
              if blob.pixels() > max_size:
                  max_blob=blob
                  max_size = blob.pixels()
          return max_blob
       
      while(True):
          img = sensor.snapshot() # Take a picture and return the image.
       
          blobs = img.find_blobs([yellow_threshold])
          if blobs:
              max_blob=find_max(blobs)
              print('sum :', len(blobs))
              img.draw_rectangle(max_blob.rect())
              img.draw_cross(max_blob.cx(), max_blob.cy())
       
              output_str="[%d,%d]" % (max_blob.cx(),max_blob.cy()) #方式1
              #output_str=json.dumps([max_blob.cx(),max_blob.cy()]) #方式2
       
              print('you send:',output_str)
              uart.write(output_str+'\r\n')
          else:
              print('not found!')
      

      老师这个是openmv的代码 上边那个格式出错



    • 估计你线接错了。你看Arduino上的代码,用的是10,11引脚。



    • 那不是openmv的p4,p5应该接tx和rx么?那个10 11管脚啥意思,从openmv出来3个线,分别连tx rx gnd 然后那个10 11 啥意思



    • 老师解决了 谢谢老师