导航

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

    stoz 发布的帖子

    • 接受几次数据后就卡死了

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

      uart = UART(3,4800, timeout_char=1000) # i使用给定波特率初始化
      uart.init(4800, bits=8, parity=None, stop=1, timeout_char=1000) # 使用给定参数初始化
      GRAYSCALE_THRESHOLD = [(0, 64)]
      ROIS = [ # [ROI, weight]
      (0, 0, 1, 1, 1), # You'll need to tweak the weights for your app
      (0, 50, 320, 30, 1), # depending on how your robot is setup.
      (0, 0, 1, 1, 1)
      ]

      weight_sum = 0
      for r in ROIS: weight_sum += r[4]

      sensor.reset() # Initialize the camera sensor.
      sensor.set_contrast(3)
      sensor.set_gainceiling(16)
      sensor.set_pixformat(sensor.GRAYSCALE) # use grayscale.
      sensor.set_framesize(sensor.VGA) # use QQVGA for speed.
      sensor.set_windowing((320, 240))
      sensor.skip_frames(time = 2000) # Let new settings take affect.
      sensor.set_auto_gain(False,value=100) # must be turned off for color tracking
      sensor.set_auto_whitebal(False) # must be turned off for color tracking
      clock = time.clock() # Tracks FPS.

      a=0
      def draw_keypoints(img, kpts):
      if kpts:
      print(kpts)
      img.draw_keypoints(kpts)
      img = sensor.snapshot()
      time.sleep(1000)
      kpts1 = image.load_descriptor("/desc.orb")
      img = sensor.snapshot()

      def high(x):
      x=x>>8
      return x

      def low(x):
      x=x&0xff
      return x

      while(True):
      clock.tick() # Track elapsed milliseconds between snapshots().
      img = sensor.snapshot() # Take a picture and return the image.
      print(1)
      if uart.any():
      a=int(uart.readchar())
      print(a)

      请在这里粘贴代码
      
      发布在 OpenMV Cam
      S
      stoz
    • 串口卡死?
      import sensor, image, time, math
      from pyb import UART
      
      uart = UART(3,4800, timeout_char=1000)                         # i使用给定波特率初始化
      uart.init(4800, bits=8, parity=None, stop=1, timeout_char=1000) # 使用给定参数初始化
      GRAYSCALE_THRESHOLD = [(0, 64)]
      ROIS = [ # [ROI, weight]
              (0, 0, 1, 1, 1), # You'll need to tweak the weights for your app
              (0, 50, 320, 30, 1), # depending on how your robot is setup.
              (0, 0, 1, 1, 1)
             ]
      
      weight_sum = 0
      for r in ROIS: weight_sum += r[4]
      
      
      sensor.reset() # Initialize the camera sensor.
      sensor.set_contrast(3)
      sensor.set_gainceiling(16)
      sensor.set_pixformat(sensor.GRAYSCALE) # use grayscale.
      sensor.set_framesize(sensor.VGA) # use QQVGA for speed.
      sensor.set_windowing((320, 240))
      sensor.skip_frames(time = 2000) # Let new settings take affect.
      sensor.set_auto_gain(False,value=100) # must be turned off for color tracking
      sensor.set_auto_whitebal(False) # must be turned off for color tracking
      clock = time.clock() # Tracks FPS.
      
      a=0
      def draw_keypoints(img, kpts):
          if kpts:
              print(kpts)
              img.draw_keypoints(kpts)
              img = sensor.snapshot()
              time.sleep(1000)
      kpts1 = image.load_descriptor("/desc.orb")
      img = sensor.snapshot()
      
      def high(x):
          x=x>>8
          return x
      
      def low(x):
          x=x&0xff
          return x
      
      while(True):
          clock.tick() # Track elapsed milliseconds between snapshots().
          img = sensor.snapshot() # Take a picture and return the image.
          print(0)
          if uart.any():
              a=int(uart.readchar())
              print(a)
          if a==1:
                   print(1)
                   if (kpts1 == None):
                       kpts1 = img.find_keypoints(max_keypoints=150, threshold=2, scale_factor=1.2)
                       draw_keypoints(img, kpts1)
                       uart.writechar(0)
                       uart.writechar(0)
                       uart.writechar(0)
                       uart.writechar(0)
                       uart.writechar(0)
                       uart.writechar(0)
                       uart.writechar(0x10)
                       uart.writechar(0x0d)
                       uart.writechar(0x0a)
                   else:
                       kpts2 = img.find_keypoints(max_keypoints=150, threshold=2, normalized=True)
                       if (kpts2):
                           match = image.match_descriptor(kpts1, kpts2, threshold=85)
                           if (match.count()>10):
                               img.draw_rectangle(match.rect())
                               img.draw_cross(match.cx(), match.cy(), size=10)
                               print(kpts2, "x:%d y:%d"%(match.cx(), match.cy()))
                               mv_x=(int)(match.cx()-160)
                               mv_y=(int)(120-match.cy())
                               Sum=mv_x+mv_y
                               uart.writechar(high(mv_x))
                               uart.writechar(low(mv_x))
                               uart.writechar(high(mv_y))
                               uart.writechar(low(mv_y))
                               uart.writechar(high(Sum))
                               uart.writechar(low(Sum))
                               uart.writechar(0x30)
                               uart.writechar(0x0d)
                               uart.writechar(0x0a)
                           else:
                               uart.writechar(0)
                               uart.writechar(0)
                               uart.writechar(0)
                               uart.writechar(0)
                               uart.writechar(0)
                               uart.writechar(0)
                               uart.writechar(0x10)
                               uart.writechar(0x0d)
                               uart.writechar(0x0a)
                       else:
                           uart.writechar(0)
                           uart.writechar(0)
                           uart.writechar(0)
                           uart.writechar(0)
                           uart.writechar(0)
                           uart.writechar(0)
                           uart.writechar(0x10)
                           uart.writechar(0x0d)
                           uart.writechar(0x0a)
          if a==2:
                   centroid_sum = 0
                   for r in ROIS:
                       blobs = img.find_blobs(GRAYSCALE_THRESHOLD, roi=r[0:4], merge=True) # r[0:4] is roi tuple.
      
                       if blobs:
                           # Find the blob with the most pixels.
                           largest_blob = max(blobs, key=lambda b: b.pixels())
      
                           # Draw a rect around the blob.
                           img.draw_rectangle(largest_blob.rect())
                           img.draw_cross(largest_blob.cx(),
                                          largest_blob.cy())
                           centroid_sum += largest_blob.cx() * r[4] # r[4] is the roi weight.
                   Mv_x=centroid_sum-160
                   Sum=Mv_x
                   uart.writechar(high(Mv_x))
                   uart.writechar(low(Mv_x))
                   uart.writechar(0)
                   uart.writechar(0)
                   uart.writechar(high(Sum))
                   uart.writechar(low(Sum))
                   uart.writechar(0x20)
                   uart.writechar(0x0d)
                   uart.writechar(0x0a)
                   print(2)
      
                   print("Turn Angle: %f" % Mv_x)
      
                   #print(clock.fps()) # Note: Your OpenMV Cam runs about half as fast while
      
      发布在 OpenMV Cam
      S
      stoz
    • 我用上位机发送1显示a=B"1"但是下面的if不会触发?
      import sensor, image, time, math
      from pyb import UART
      
      uart = UART(3,4800, timeout_char=1000)                         # i使用给定波特率初始化
      uart.init(4800, bits=8, parity=None, stop=1, timeout_char=1000) # 使用给定参数初始化
      GRAYSCALE_THRESHOLD = [(0, 64)]
      ROIS = [ # [ROI, weight]
              (0, 0, 0, 0, 0), # You'll need to tweak the weights for your app
              (0, 50, 320, 30, 0.3), # depending on how your robot is setup.
              (0, 0, 0, 0, 0)
             ]
      
      weight_sum = 0
      for r in ROIS: weight_sum += r[4]
      
      
      sensor.reset() # Initialize the camera sensor.
      sensor.set_contrast(3)
      sensor.set_gainceiling(16)
      sensor.set_pixformat(sensor.GRAYSCALE) # use grayscale.
      sensor.set_framesize(sensor.VGA) # use QQVGA for speed.
      sensor.set_windowing((320, 240))
      sensor.skip_frames(time = 2000) # Let new settings take affect.
      sensor.set_auto_gain(False,value=100) # must be turned off for color tracking
      sensor.set_auto_whitebal(False) # must be turned off for color tracking
      clock = time.clock() # Tracks FPS.
      
      a=0
      def draw_keypoints(img, kpts):
          if kpts:
              print(kpts)
              img.draw_keypoints(kpts)
              img = sensor.snapshot()
              time.sleep(1000)
      kpts1 = image.load_descriptor("/desc.orb")
      img = sensor.snapshot()
      
      def high(x):
          x=x>>8
          return x
      
      def low(x):
          x=x&0xff
          return x
      
      while(True):
          clock.tick() # Track elapsed milliseconds between snapshots().
          img = sensor.snapshot() # Take a picture and return the image.
          print(0)
          if uart.any():
              a=uart.read(1)
              print(a)
          if a==1:
                   print(2)
          if a==2:
                   print(3)
      发布在 OpenMV Cam
      S
      stoz