Z
z1ep
@z1ep
0
声望
4
楼层
367
资料浏览
0
粉丝
0
关注
z1ep 发布的帖子
-
想问一下,进行颜色识别后再将RGB565转为灰度图,但是之后的模板匹配没现象?
import sensor, image, time from image import SEARCH_EX, SEARCH_DS thresholds = [(16, 50, 24, 99, -18, 67), (40, 65, -32, 32, 27, 82), (10, 27, -52, -16, -19, 99)] sensor.reset() sensor.set_pixformat(sensor.RGB565) #sensor.set_pixformat(sensor.GRAYSCALE) sensor.set_framesize(sensor.QQVGA) 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() #templates = ["/left.pgm", "/right.pgm", "/band.pgm"] #保存多个模板 template1 = image.Image("left.pgm") template2 = image.Image("right.pgm") template3 = image.Image("band.pgm") while(True): clock.tick() img = sensor.snapshot() for blob in img.find_blobs(thresholds, pixels_threshold=200, area_threshold=200): img.draw_rectangle(blob.rect()) img.draw_cross(blob.cx(), blob.cy()) if blob.code() == 1: print("前方为红灯") if blob.code() == 2: print("前方为黄灯") if blob.code() == 4: print("前方为绿灯") if blob.code()!=1 and blob.code()!=2 and blob.code()!=4: img = img.to_grayscale() r = img.find_template(template1, 0.10, step=4, search=SEARCH_EX) #, roi=(81, 49, 165, 166)) if r: img.draw_rectangle(r) print("前方左转") r = img.find_template(template2, 0.10, step=4, search=SEARCH_EX) #, roi=(81, 49, 165, 166)) if r: img.draw_rectangle(r) print("前方右转") r = img.find_template(template3, 0.10, step=4, search=SEARCH_EX) #, roi=(81, 49, 165, 166)) if r: img.draw_rectangle(r) print("禁止通行")
-
在模板匹配中,未检测到目标,elseif这一句该怎么写?(我图中并不能实现此功能)
我想问一下,在模板匹配中,如果没有识别到对应的图片,想要输出“未检测到标志”,elseif这一句该怎么写?(我图中并不能实现此功能)