• 星瞳实验室APP,快速收到回复。扫描二维码或者点击 https://singtown.com/app/
  • 必看:玩转星瞳论坛了解一下图片上传,代码格式等问题。
  • 每一个新的提问,单独发一个新帖子
  • 描述一定要详细 描述一定要详细 描述一定要详细
  • 请贴出具体的的目的,就是你要做什么。
  • 请贴出具体的代码,与报错提示
  • 代码一定要让别人可以运行的文本,不要贴图片
  • 为什么使用找圆程序会出现内存问题



    • 0_1520756492765_e992585d-ee9a-422e-8435-1d3b5c9dd243-image.png



    • 你需要把代码都粘贴上来,才能复现问题



    • 0_1520758432581_481807c2-bde9-4627-b21c-70af5cea5397-image.png 0_1520758453822_4dfb2cc8-82b6-4462-aad7-cf3254a0b687-image.png
      0_1520758479254_94bfc19a-dae9-45d5-99b5-79700a7c2270-image.png



    • 截图的话,代码没法执行,https://forum.singtown.com/topic/57/玩转星瞳论坛,根据格式粘贴代码。



    • import sensor, image, time
      
      
      threshold_100 = (44, 52, 33, 58, -2, 19)
      threshold_1 = (39, 59, -13, -2, 7, 23)
      threshold_5 = (23, 52, 1, 30, -16, 5)
      threshold_10 = (44, 78, -7, 9, 11, 4)
      threshold_20 = (31, 49, 9, 30, 3, 13)
      threshold_50 = (40, 67, -26, -6, -3, 15)
      
      sensor.reset()
      sensor.set_pixformat(sensor.RGB565)
      sensor.set_framesize(sensor.QVGA)
      sensor.skip_frames(time = 2000)
      sensor.set_auto_gain(False) # must be turned off for color tracking
      sensor.set_auto_whitebal(False) # must be turned off for color tracking
      clock = time.clock()
      
      # Only blobs that with more pixels than "pixel_threshold" and more area than "area_threshold" are
      # returned by "find_blobs" below. Change "pixels_threshold" and "area_threshold" if you change the
      # camera resolution. "merge=True" merges all overlapping blobs in the image.
      
      
      while(1):
          clock.tick()
          img = sensor.snapshot().lens_corr(1.8)
          for blob_100 in img.find_blobs([threshold_100], pixels_threshold = 200, area_threshold = 200, merge = True):
              img.draw_rectangle(blob_100.rect())
              img.draw_cross(blob_100.cx(), blob_100.cy())
              img.draw_string(blob_100.cx(),blob_100.cy(),"100yuan",color = 0)
      
          for blob_20 in img.find_blobs([threshold_20], pixels_theshold = 200, area_threshold = 200, merge = True):
              img.draw_rectangle(blob_20.rect(),color = (255,0,0))
              img.draw_cross(blob_20.cx(), blob_20.cy())
              img.draw_string(blob_20.cx(),blob_20.cy(),"20yuan",color = (255,0,0))
      
          for blob_10 in img.find_blobs([threshold_10], pixels_theshold = 200, area_threshold = 200, merge = True):
              img.draw_rectangle(blob_10.rect(),color = (0,255,0))
              img.draw_cross(blob_10.cx(), blob_10.cy())
              img.draw_string(blob_10.cx(),blob_10.cy(),"10yuan",color = (0,255,0))
      
          for blob_5 in img.find_blobs([threshold_5], pixels_theshold = 200, area_threshold = 200, merge = True):
              img.draw_rectangle(blob_5.rect(),color = (0,0,255))
              img.draw_cross(blob_5.cx(), blob_5.cy())
              img.draw_string(blob_5.cx(),blob_5.cy(),"5yuan",color = (0,0,255))
      
          for blob_1 in img.find_blobs([threshold_1], pixels_theshold = 200, area_threshold = 200, merge = True):
              img.draw_rectangle(blob_1.rect(),color = 0)
              img.draw_cross(blob_1.cx(), blob_1.cy())
              img.draw_string(blob_1.cx(),blob_1.cy(),"1yuan",color = 255)
      
          for blob_50 in img.find_blobs([threshold_50], pixels_theshold = 200, area_threshold = 200, merge = True):
              img.draw_rectangle(blob_50.rect(),color = (0,100,100))
              img.draw_cross(blob_50.cx(), blob_50.cy())
              img.draw_string(blob_50.cx(),blob_50.cy(),"50yuan",color = (0,100,255))
      
          for c in img.find_circles(threshold = 2000, x_margin = 10, y_margin = 10, r_margin = 10):
              img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0))
             # print(c)
      
      
        #  print(clock.fps())
          print("FPS %f" % clock.fps())
      
      


    • @kidswong999 请问这代码是哪里出问题了吗



    • @kidswong999 你好,我想知道这个找色块的函数太多然后加上找圆的函数就不行了还是什么原因呢?



    • http://book.openmv.cc/example/09-Feature-Detection/find-circles.html

      find_circles只能使用QQVGA。

      QVGA内存不够。



    • 可是为什么这样又可以呢,这个也是QVGA,难道是因为我单独定义了ROI吗

      
      import sensor, image, time
      
      sensor.reset()
      sensor.set_pixformat(sensor.RGB565)
      sensor.set_framesize(sensor.QVGA)
      sensor.skip_frames(time = 2000)
      sensor.set_auto_gain(False) # must be turned off for color tracking
      sensor.set_auto_whitebal(False) # must be turned off for color tracking
      clock = time.clock()
      
      
      ROI=(240,160,50,50)
      
      threshold_100 = (44, 52, 33, 58, -2, 19)
      
      
      while(True):
          img = sensor.snapshot()        # Take a picture and return the image.
      
          for blob_100 in img.find_blobs([threshold_100], roi = ROI, pixels_threshold = 200, area_threshold = 200, merge = True):
              img.draw_rectangle(blob_100.rect())
              img.draw_cross(blob_100.cx(), blob_100.cy())
              img.draw_string(blob_100.cx(),blob_100.cy(),"100yuan",color = 0)
      
          for c in img.find_circles(roi = ROI, threshold = 2000, x_margin = 10, y_margin = 10, r_margin = 10):
              img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0))
              print(c)
      
      
      
      
          img.draw_rectangle(ROI)```


    • 加了ROI,就不会费那么多内存了呗



    • 所以是除了ROI的那个区域其他的部分都不会占用内存的意思吗