导航

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

    uc5f

    @uc5f

    0
    声望
    10
    楼层
    950
    资料浏览
    0
    粉丝
    0
    关注
    注册时间 最后登录

    uc5f 关注

    uc5f 发布的帖子

    • 我想给Arduino发送红色色块的一个坐标信息,在Arduino那边串口监视器显示的是乱码

      import sensor, image, time
      import json
      from pyb import UART

      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 = (30, 100, 15, 127, 15, 127)

      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 QQVGA for speed.分辨率为120*160。
      sensor.skip_frames(10) # Let new settings take affect.
      sensor.set_auto_whitebal(False) # turn this off.
      clock = time.clock() # Tracks FPS.

      uart = UART(3, 115200)

      def find_max(blobs):
      max_size=0
      for blob in blobs:
      if blob[2]*blob[3]>max_size:
      max_blob=blob
      max_size=blob[2]*blob[3]
      return max_blob

      while(True):
      clock.tick() # Track elapsed milliseconds between snapshots().
      img = sensor.snapshot() # Take a picture and return the image.
      img.draw_cross(int(img.width()/2),int(img.height()/2))
      blobs = img.find_blobs([red_threshold])
      if blobs:
      max_blob = find_max(blobs)
      #print('sum : %d'% len(blobs))

              # Draw a rect around the blob.
        img.draw_rectangle(max_blob[0:4]) # rect
        img.draw_cross(max_blob[5], max_blob[6]) # cx, cy
      
      
      
          #{(1,22),(-3,33),(22222,0),(9999,12),(0,0)}
      
        uart.writechar((max_blob[5]))
       # print('you send:',data_out)
        print(max_blob[5], max_blob[6])
        print(img.width()/2,img.height()/2)#宽度80,高度60
      else:
        print("not found!")
      

      Arduino

      #include <SoftwareSerial.h>

      SoftwareSerial softSerial(10, 11); // RX, TX
      char c;
      String comdata = "";

      void setup() {
      // put your setup code here, to run once:
      softSerial.begin(115200);
      Serial.begin(115200);
      }

      void loop() {
      if(softSerial.available())
      {comdata += char(softSerial.read());
      delay(2);

      Serial.println(comdata);
      }
      }

      发布在 OpenMV Cam
      U
      uc5f
    • RE: openMv与Arduino通信 Arduino的串口显示器打印的是乱码!!!

      @kidswong999 你发的贴子都没有解决里面的问题

      发布在 OpenMV Cam
      U
      uc5f
    • RE: 和Arduino串口通信不对,

      @h3gn 回不回是要用软串口

      发布在 OpenMV Cam
      U
      uc5f
    • openMv与Arduino通信 Arduino的串口显示器打印的是乱码!!!

      openMv代码

      Blob Detection Example

      这个例子展示了如何使用find_blobs函数来查找图像中的颜色色块。这个例子特别寻找深绿色的物体。

      import sensor, image, time
      from pyb import UART
      import json

      为了使色彩追踪效果真的很好,你应该在一个非常受控制的照明环境中。

      green_threshold = (30, 100, 15, 127, 15, 127)
      #设置绿色的阈值,括号里面的数值分别是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 QQVGA for speed.
      sensor.skip_frames(10) # Let new settings take affect.
      sensor.set_auto_whitebal(False) # turn this off.
      #关闭白平衡。白平衡是默认开启的,在颜色识别中,需要关闭白平衡。
      clock = time.clock() # Tracks FPS.

      uart = UART(3, 115200)
      while(True):
      clock.tick() # Track elapsed milliseconds between snapshots().
      img = sensor.snapshot() # Take a picture and return the image.

      blobs = img.find_blobs([green_threshold])
      #find_blobs(thresholds, invert=False, roi=Auto),thresholds为颜色阈值,
      #是一个元组,需要用括号[ ]括起来。invert=1,反转颜色阈值,invert=False默认
      #不反转。roi设置颜色识别的视野区域,roi是一个元组, roi = (x, y, w, h),代表
      #从左上顶点(x,y)开始的宽为w高为h的矩形区域,roi不设置的话默认为整个图像视野。
      #这个函数返回一个列表,[0]代表识别到的目标颜色区域左上顶点的x坐标,[1]代表
      #左上顶点y坐标,[2]代表目标区域的宽,[3]代表目标区域的高,[4]代表目标
      #区域像素点的个数,[5]代表目标区域的中心点x坐标,[6]代表目标区域中心点y坐标,
      #[7]代表目标颜色区域的旋转角度(是弧度值,浮点型,列表其他元素是整型),
      #[8]代表与此目标区域交叉的目标个数,[9]代表颜色的编号(它可以用来分辨这个
      #区域是用哪个颜色阈值threshold识别出来的)。
      if blobs:
          #print('sum : %d'% len(blobs))
      
          for b in blobs:
              # Draw a rect around the blob.
              img.draw_rectangle(b.rect()) # rect
               #img.draw_rectangle(b[0:4]) # rect
              img.draw_cross(b.cx(), b.cy()) # cx, cy
      
              img.draw_cross(int(img.width()/2),int(img.height()/2))
          #{(1,22),(-3,33),(22222,0),(9999,12),(0,0)}
          #data_out = json.dumps(set(data))
          uart.writechar(int(b.cx()))
          print(b[5], b[6])
                   # print((img.width()/2), (img.height()/2))
      
          #print('you send:',data_out)
      

      else:

        # print("not found!")
      

      Arduino代码

      #include <SoftwareSerial.h>

      SoftwareSerial softSerial(10, 11); // RX, TX
      char c;

      void setup() {
      // put your setup code here, to run once:
      softSerial.begin(115200);
      Serial.begin(115200);
      }

      void loop() {
      if(softSerial.available())
      {
      Serial.write(softSerial.read());
      }
      }

      发布在 OpenMV Cam
      U
      uc5f
    • 画矩形提示有错误,好像有冲突?

      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 QQVGA for speed.
      sensor.skip_frames(10) # Let new settings take affect.
      sensor.set_auto_whitebal(False) # turn this off.
      #关闭白平衡。白平衡是默认开启的,在颜色识别中,需要关闭白平衡。
      clock = time.clock() # Tracks FPS.

      uart = UART(3, 115200)
      while(True):
      clock.tick() # Track elapsed milliseconds between snapshots().
      img = sensor.snapshot() # Take a picture and return the image.

      blobs = img.find_blobs([green_threshold])
      #find_blobs(thresholds, invert=False, roi=Auto),thresholds为颜色阈值,
      #是一个元组,需要用括号[ ]括起来。invert=1,反转颜色阈值,invert=False默认
      #不反转。roi设置颜色识别的视野区域,roi是一个元组, roi = (x, y, w, h),代表
      #从左上顶点(x,y)开始的宽为w高为h的矩形区域,roi不设置的话默认为整个图像视野。
      #这个函数返回一个列表,[0]代表识别到的目标颜色区域左上顶点的x坐标,[1]代表
      #左上顶点y坐标,[2]代表目标区域的宽,[3]代表目标区域的高,[4]代表目标
      #区域像素点的个数,[5]代表目标区域的中心点x坐标,[6]代表目标区域中心点y坐标,
      #[7]代表目标颜色区域的旋转角度(是弧度值,浮点型,列表其他元素是整型),
      #[8]代表与此目标区域交叉的目标个数,[9]代表颜色的编号(它可以用来分辨这个
      #区域是用哪个颜色阈值threshold识别出来的)。
      if blobs:
          #print('sum : %d'% len(blobs))
          
          for b in blobs:
              # Draw a rect around the blob.
              #img.draw_rectangle(b.rect()) # rect
               img.draw_rectangle(b[0:4]) # rect
              img.draw_cross(b.cx(), b.cy()) # cx, cy
              
              img.draw_cross(int(img.width()/2),int(img.height()/2))
          #{(1,22),(-3,33),(22222,0),(9999,12),(0,0)}
          #data_out = json.dumps(set(data))
          uart.writechar(b.cx())
         # print(blob[5], blob[6])
                   # print((img.width()/2), (img.height()/2))
          
          #print('you send:',data_out)
      

      else:

        # print("not found!")
      发布在 OpenMV Cam
      U
      uc5f
    • RE: 应该怎么用uart.write来发送数据呢?

      请问怎么解决的呢

      发布在 OpenMV Cam
      U
      uc5f
    • 画矩形的两种方式? 有什么不同呢 ?可以怎么应用?

      img.draw_rectangle(b.rect()) # rect
      img.draw_rectangle(b[0:4]) # rect
      请问上面的两个方式有什么区别

      发布在 OpenMV Cam
      U
      uc5f
    • RE: 给arduino发送色块中心的坐标 提示代码有错误?

      @kidswong999 # Blob Detection Example

      这个例子展示了如何使用find_blobs函数来查找图像中的颜色色块。这个例子特别寻找深绿色的物体。

      import sensor, image, time
      from pyb import UART
      import json

      为了使色彩追踪效果真的很好,你应该在一个非常受控制的照明环境中。

      green_threshold = (30, 100, 15, 127, 15, 127)
      #设置绿色的阈值,括号里面的数值分别是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 QQVGA for speed.
      sensor.skip_frames(10) # Let new settings take affect.
      sensor.set_auto_whitebal(False) # turn this off.
      #关闭白平衡。白平衡是默认开启的,在颜色识别中,需要关闭白平衡。
      clock = time.clock() # Tracks FPS.

      uart = UART(3, 115200)
      while(True):
      clock.tick() # Track elapsed milliseconds between snapshots().
      img = sensor.snapshot() # Take a picture and return the image.

      blobs = img.find_blobs([green_threshold])
      #find_blobs(thresholds, invert=False, roi=Auto),thresholds为颜色阈值,
      #是一个元组,需要用括号[ ]括起来。invert=1,反转颜色阈值,invert=False默认
      #不反转。roi设置颜色识别的视野区域,roi是一个元组, roi = (x, y, w, h),代表
      #从左上顶点(x,y)开始的宽为w高为h的矩形区域,roi不设置的话默认为整个图像视野。
      #这个函数返回一个列表,[0]代表识别到的目标颜色区域左上顶点的x坐标,[1]代表
      #左上顶点y坐标,[2]代表目标区域的宽,[3]代表目标区域的高,[4]代表目标
      #区域像素点的个数,[5]代表目标区域的中心点x坐标,[6]代表目标区域中心点y坐标,
      #[7]代表目标颜色区域的旋转角度(是弧度值,浮点型,列表其他元素是整型),
      #[8]代表与此目标区域交叉的目标个数,[9]代表颜色的编号(它可以用来分辨这个
      #区域是用哪个颜色阈值threshold识别出来的)。
      if blobs:
      #如果找到了目标颜色
          for blob in blobs:
          #迭代找到的目标颜色区域
              # Draw a rect around the blob.
              img.draw_rectangle(blob[0:4]) # rect
              #用矩形标记出目标颜色区域
              img.draw_cross(blob[5], blob[6]) # cx, cy
               output_str=json.dumps([find_blob.cx(),find_blob.cy()]) #方式2
              img.draw_cross(int(img.width()/2),int(img.height()/2))
              #在目标颜色区域的中心画十字形标记
              print(blob[5], blob[6])
              print((img.width()/2), (img.height()/2))
              #输出目标物体中心坐标
      
      #print(clock.fps()) # Note: Your OpenMV Cam runs about half as fast while
      # connected to your computer. The FPS should increase once disconnected
      发布在 OpenMV Cam
      U
      uc5f
    • 给arduino发送色块中心的坐标 提示代码有错误?

      我想给arduino发送色块中心的坐标 提示错误?

      for blob in blobs:
      #迭代找到的目标颜色区域
      # Draw a rect around the blob.
      img.draw_rectangle(blob[0:4]) # rect
      #用矩形标记出目标颜色区域
      img.draw_cross(blob[5], blob[6]) # cx, cy
      output_str="[%d,%d]" % (blob.cx(),blob.cy()) #方式1
      img.draw_cross(int(img.width()/2),int(img.height()/2))
      #在目标颜色区域的中心画十字形标记
      print(blob[5], blob[6])
      print((img.width()/2), (img.height()/2))
      #输出目标物体中心坐标

      错误的是 output_str="[%d,%d]" % (blob.cx(),blob.cy()) #方式1

      发布在 OpenMV Cam
      U
      uc5f