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



    • # Blob Detection Example
      #
      # This examp le shows off how to use the find_blobs function to find color
      # blobs in the image. This example in particular looks for dark green objects.
      
      import sensor, image, time,pyb
      
      # For color tracking to work really well you should ideally be in a very, very,
      # very, controlled enviroment where the lighting is constant...
      red_threshold_01 =(13, 83, 1, 94, -6, 74)
      #设置红色的阈值,括号里面的数值分别是L A B 的最大值和最小值(minL, maxL, minA,
      # maxA, minB, maxB),LAB的值在图像左侧三个坐标图中选取。如果是灰度图,则只需
      #设置(min, max)两个数字即可。
      
      # You may need to tweak the above settings for tracking green things...
      # Select an area in the Framebuffer to copy the color settings.
      
      sensor.reset() # Initialize the camera sensor.
      sensor.set_pixformat(sensor.RGB565) # use RGB565.
      sensor.set_framesize(sensor.QQVGA) # use QVGA for quailtiy ,use QQVGA for speed.
      sensor.skip_frames(100) # Let new settings take affect.
      sensor.set_auto_whitebal(False)
      #关闭白平衡。白平衡是默认开启的,在颜色识别中,需要关闭白平衡。
      clock = time.clock() # Tracks FPS.
      led = pyb.LED(3)
      
      
      #定义串口
      from pyb import UART
      
      uart = UART(3, 19200)
      
      
      zuoshou='Z'
      youshou='Y'
      daiming='G'
      
      
      '''
        扩宽roi
      '''
      def expand_roi(roi):
          # set for QQVGA 160*120
          extra = 5
          win_size = (160, 120)
          (x, y, width, height) = roi
          new_roi = [x-extra, y-extra, width+2*extra, height+2*extra]
      
          if new_roi[0] < 0:
              new_roi[0] = 0
          if new_roi[1] < 0:
              new_roi[1] = 0
          if new_roi[2] > win_size[0]:
              new_roi[2] = win_size[0]
          if new_roi[3] > win_size[1]:
              new_roi[3] = win_size[1]
      
          return tuple(new_roi)
      
      #机器人坐标系中心点
      center_x=80
      center_y=160
      
      
      
      
      
      while(True):
          clock.tick() # Track elapsed milliseconds between snapshots().
          img = sensor.snapshot() # Take a picture and return the image.
          #  pixels_threshold=100, area_threshold=100
          blobs = img.find_blobs([red_threshold_01], area_threshold=150)
          led.on()
         # time.sleep(100)
      
          if blobs:
          #如果找到了目标颜色
              print(blobs)
              for blob in blobs:
              #迭代找到的目标颜色区域
                  is_circle = False
                  max_circle = None
                  max_radius = -1
      
                  new_roi = expand_roi(blob.rect())
      
                  for c in img.find_circles(threshold = 2000, x_margin = 20, y_margin = 20, r_margin = 10, roi=new_roi):
                      is_circle = True
                      # img.draw_circle(c.x(), c.y(), c.r(), color = (255, 255, 255))
                      if c.r() > max_radius:
                          max_radius = c.r()
                          max_circle = c
                  if is_circle:
                      # 如果有对应颜色的圆形 标记外框
                      # Draw a rect around the blob.
                      img.draw_rectangle(new_roi) # rect
                      img.draw_rectangle(blob.rect()) # rect
                      #用矩形标记出目标颜色区域
                      img.draw_cross(blob[5], blob[6]) # cx, cy
                      img.draw_circle(max_circle.x(), max_circle.y(), max_circle.r(), color = (0, 255, 0))
                      img.draw_circle(max_circle.x(), max_circle.y(), max_circle.r() + 1, color = (0, 255, 0))
      
      
      
                      print("%d,%d",blob.cx(),blob.cy())
      
                      ball_center_x=blob.cx()
                      ball_center_y=blob.cy()
                      if uart.any():
                          if (uart.readchar() == ord("K")):
                              if ball_center_x > 75:
                                  uart.write("Y")
                              if ball_center_x < 30:
                                  uart.write("Z")
                              if (ball_center_x>30 and ball_center_x<75):
                                  uart.write("G")
      
      
      以下是arduino程序
      

      #include <avr\pgmspace.h>
      #include "GI2C_V11.h"
      #include <Wire.h>

      char a;
      int i=1;
      unsigned char Buf[61+1];
      GI2CV11 MenSao_RCB1(Buf,sizeof(Buf));

      const unsigned char ActionCode_daiming[][49] PROGMEM = {
      129,36,145,251,251,251,251,135,180,166,100,125, 85,126,210, 75,137,251,251,251,251,251,189,161, 21, 21, 21, 1, 1, 1, 1, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 1, 1, 1, 1, 1, 21, 21,10
      };

      const unsigned char ActionCode_youshou[][49] PROGMEM = {
      129, 36,145,251,251,251,251,135,180,166,100,125, 85,126,210, 75,137,251,251,251,251,251,189,161, 21, 21, 21, 1, 1, 1, 1, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 1, 1, 1, 1, 1, 21, 21,5,
      129, 36,145,251,251,251,251,119,180,166,100, 81, 89,126,210, 75,152,251,251,251,251,251,189,161, 21, 21, 21, 1, 1, 1, 1, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 1, 1, 1, 1, 1, 21, 21,5,
      129, 36,145,251,251,251,251,137,180,166,100,137,104,126,210, 75,145,251,251,251,251,251,189,161, 21, 21, 21, 1, 1, 1, 1, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 1, 1, 1, 1, 1, 21, 21,5,
      129, 36,145,251,251,251,251,135,180,166,100,125, 85,126,210, 75,137,251,251,251,251,251,189,161, 21, 21, 21, 1, 1, 1, 1, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 1, 1, 1, 1, 1, 21, 21,5,
      129, 36,164,251,251,251,251,135,196,250, 16,125, 85, 47,119, 87,137,251,251,251,251,251,189,161, 21, 21, 21, 1, 1, 1, 1, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 1, 1, 1, 1, 1, 21, 21,10,
      129,236,164,251,251,251,251,173,196,250, 16,169, 85, 89,154, 87,178,251,251,251,251,251,158,161, 21, 21, 21, 1, 1, 1, 1, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 1, 1, 1, 1, 1, 21, 21,10
      };

      const unsigned char ActionCode_zuoshou[][49] PROGMEM = {
      129,36,145,251,251,251,251,135,180,166,100,125, 85,126,210, 75,137,251,251,251,251,251,189,161, 21, 21, 21, 1, 1, 1, 1, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 1, 1, 1, 1, 1, 21, 21,5,
      129,36,145,251,251,251,251,126,180,166,100,123,120,126,210, 75,155,251,251,251,251,251,189,161, 21, 21, 21, 1, 1, 1, 1, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 1, 1, 1, 1, 1, 21, 21,5,
      129,36,145,251,251,251,251,133,180,166,103,105, 83,126,210, 75,140,251,251,251,251,251,189,161, 21, 21, 21, 1, 1, 1, 1, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 1, 1, 1, 1, 1, 21, 21,5,
      129,36,145,251,251,251,251,135,180,166,100,125, 85,126,210, 75,137,251,251,251,251,251,189,161, 21, 21, 21, 1, 1, 1, 1, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 1, 1, 1, 1, 1, 21, 21,5,
      129,36,164,251,251,251,251,135,196,250, 16,125, 85, 47,119, 87,137,251,251,251,251,251,189,161, 21, 21, 21, 1, 1, 1, 1, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 1, 1, 1, 1, 1, 21, 21,10,
      129,189,164,251,251,251,251, 86,213,191, 61,125, 51, 45,119, 87, 99,251,251,251,251,251, 0,161, 21, 21, 21, 1, 1, 1, 1, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 1, 1, 1, 1, 1, 21, 21,10
      };

      void daiming()
      {
      int i,j;
      int row = sizeof(ActionCode_daiming) / sizeof(ActionCode_daiming[0]);
      for(j=0;j<row;j++)
      {
      for(i=0;i<48;i++)
      {
      //更新缓冲区
      Buf[i+13] = pgm_read_byte(&ActionCode_daiming[j][i]);
      }
      //将缓冲区中的数据发送给舵机控制单元,完成舵机控制
      MenSao_RCB1.Write(1,13,48);
      //动作组间的延时,注意*100
      delay((int)(pgm_read_byte(&ActionCode_daiming[j][i])) * 100);
      }
      }

      void youshou()
      {
      int i,j;
      int row = sizeof(ActionCode_youshou) / sizeof(ActionCode_youshou[0]);
      for(j=0;j<row;j++)
      {
      for(i=0;i<48;i++)
      {
      //更新缓冲区
      Buf[i+13] = pgm_read_byte(&ActionCode_youshou[j][i]);
      }
      //将缓冲区中的数据发送给舵机控制单元,完成舵机控制
      MenSao_RCB1.Write(1,13,48);
      //动作组间的延时,注意*100
      delay((int)(pgm_read_byte(&ActionCode_youshou[j][i])) * 100);
      }
      }

      void zuoshou()
      {
      int i,j;
      int row = sizeof(ActionCode_zuoshou) / sizeof(ActionCode_zuoshou[0]);
      for(j=0;j<row;j++)
      {
      for(i=0;i<48;i++)
      {
      //更新缓冲区
      Buf[i+13] = pgm_read_byte(&ActionCode_zuoshou[j][i]);
      }
      //将缓冲区中的数据发送给舵机控制单元,完成舵机控制
      MenSao_RCB1.Write(1,13,48);
      //动作组间的延时,注意*100
      delay((int)(pgm_read_byte(&ActionCode_zuoshou[j][i])) * 100);
      }
      }

      void setup()
      {
      Serial.begin(19200);

      }

      void loop()
      {
      daiming();
      /*if(flag==0)
      {
      for(i=1;i<=6;i++)
      {
      Go();
      }
      daiming();
      Serial.write("K");
      } */

      if (Serial.available())
      {
      a = Serial.read();
      switch(a)
      {
      //case 'D': daiming(); Serial.print("K"); break;
      //case 'G': Go(); Serial.print("K"); break;
      case 'Z': zuoshou(); Serial.print("K"); break;
      case 'Y': youshou(); Serial.print("K"); break;
      /case 'L': Left();Serial.print("L"); break;
      case 'R': Right();Serial.print("R"); break;
      /
      case 'D': daiming();Serial.print("K"); break;
      //default :daiming(); Serial.print("K"); break;
      }

      }

      }

      
      


    • OpenMV 和Arduino 的串口应该分别调试。你应该先用串口助手看一下OpenMV 的串口数据。



    • @kidswong999 额.........我试试,谢谢