为什么使用找圆程序会出现内存问题
-
截图的话,代码没法执行,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的那个区域其他的部分都不会占用内存的意思吗
-
@kidswong999 那插入SD可以解决此问题吗
-
@towb 插入SD卡不会解决ram内存的问题。