星瞳实验室APP,快速收到回复
  • 每一个新的提问,单独发一个新帖子
  • 帖子需要目的,你要做什么?
  • 如果涉及代码,需要报错提示全部代码文本,请注意不要贴代码图片
  • 必看:玩转星瞳论坛了解一下图片上传,代码格式等问题。
  • 为什么霍夫变换检测到的直线不稳定呢



    • 一会有一会没有,这是什么导致的啊



    • 请提供代码和图片。



    • This post is deleted!


    • import sensor, image, time

      fuc_threshold_01 = (49, 100, 43, 120, -128, 22)
      red_threshold_01 = (0, 100, -38, 127, 39, 127)
      green_threshold_01 = (62, 75, -100, -18, -4, 127)
      vio_threshold_01 = (0, 53, -128, 34, -128, -1)

      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(10) # Let new settings take affect.
      sensor.set_auto_whitebal(False)
      #关闭白平衡。白平衡是默认开启的,在颜色识别中,需要关闭白平衡。
      clock = time.clock() # Tracks FPS.
      min_degree = 0
      max_degree = 179
      '''
      扩宽roi
      '''
      def expand_roi(roi):
      # set for QQVGA 160120
      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)
      

      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)
      blobs2 = img.find_blobs([green_threshold_01], area_threshold=150)
      blobs3 = img.find_blobs([fuc_threshold_01], area_threshold=150)
      blobs4 = img.find_blobs([vio_threshold_01], area_threshold=150)

      if blobs3:
      #      print(blobs)
          for blob in blobs3:
      #迭代找到的目标颜色区域
              is_circle = False
              max_circle = None
              max_radius = -1
      
              new_roi = expand_roi(blob.rect())
              
          for l in img.find_lines(threshold =2000, theta_margin = 1, rho_margin =1,roi=new_roi):
              if (min_degree <= l.theta()) and (l.theta() <= max_degree):
                  img.draw_line(l.line(), color = (255, 255, 0))
               #   print(l)
      
      
      
      print(clock.fps())




    • 我运行你的程序一直找不到。

      0_1557909403455_81826072-2048-423c-8b5d-d8ce0c2ced51-image.png