import sensor, image, time
sensor.reset()
sensor.set_pixformat(sensor.RGB565) # grayscale is faster
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time = 2000)
sensor.set_auto_whitebal(False)
clock = time.clock()
while(True):
clock.tick()
img = sensor.snapshot().lens_corr(1.8)
2, r_max = 100, r_step = 2):
#img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0))
#print(c)
roi=(20,20,160,80)
juxing=img.find_rects(roi,threshold = 15000)
for r in juxing:
img.draw_rectangle(r.rect(), color = (255, 0, 0))
#for p in r.corners(): img.draw_circle(p[0], p[1], 5, color = (0, 255, 0))
#print(r)
#yuan=img.find_circles(threshold = 2000, x_margin = 10, y_margin = 10, r_margin = 10,r_min = 2, r_max = 100, r_step = 2)
print('矩形有',len(juxing))
print("FPS %f" % clock.fps())
6
6hgw
@6hgw
0
声望
6
楼层
854
资料浏览
1
粉丝
0
关注
6hgw 发布的帖子
-
识别矩形圆形也被识别出来,三角形也会被识别成矩形?这是为什么
-
颜色识别,因为亮度加了曝光,可是摄像头拍摄时就一闪一闪的,怎么解决?
# Color Tracking Thresholds (L Min, L Max, A Min, A Max, B Min, B Max) # The below thresholds track in general red/green things. You may wish to tune them... thresholds = [(63, 72, 27, 127, -128, 127), # generic_red_thresholds -> index is 0 so code == (1 << 0) (30, 100, -64, -8, -32, 32), # generic_green_thresholds -> index is 1 so code == (1 << 1) (97, 100, -5, 33, -3, 30)] # generic_blue_thresholds -> index is 2 so code == (1 << 2) # Codes are or'ed together when "merge=True" for "find_blobs". 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 sensor.set_auto_exposure(False, 1500)#这里设置曝光时间 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" must be set to merge overlapping color blobs for color codes. while(True): clock.tick() img = sensor.snapshot() is_red=img.find_blobs([thresholds[0]],roi=(30,10,200,50),pixels_threshold=200, area_threshold=200) is_green=img.find_blobs([thresholds[1]],roi=(30,10,200,50),pixels_threshold=200, area_threshold=200) is_yellow=img.find_blobs([thresholds[2]],roi=(30,10,200,50),pixels_threshold=200, area_threshold=200) if is_red: print(1) if is_green: print(2) if is_yellow: print(3)