颜色识别和特征点检测两种识别方法怎么写在一起啊
就是用模板上的颜色识别和特征点检测不知道怎么写在一起
# Object tracking with keypoints example.
# Show the camera an object and then run the script. A set of keypoints will be extracted
# once and then tracked in the following frames. If you want a new set of keypoints re-run
# the script. NOTE: see the docs for arguments to tune find_keypoints and match_keypoints.
import sensor, time, image
# Reset sensor
sensor.reset()
# Sensor settings
sensor.set_contrast(3)
sensor.set_gainceiling(16)
sensor.set_framesize(sensor.VGA)
sensor.set_windowing((400, 320))
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.skip_frames(time = 2000)
sensor.set_auto_gain(False, value=100)
def draw_keypoints(img, kpts):
if kpts:
print(kpts)
img.draw_keypoints(kpts)
img = sensor.snapshot()
time.sleep_ms(1000)
#kpts1 = None
# NOTE: uncomment to load a keypoints descriptor from file
kpts1 = image.load_descriptor("/telunsu.orb")
kpts2 = image.load_descriptor("/xuehua.orb")
kpts3 = image.load_descriptor("/AD.orb")
kpts4 = image.load_descriptor("/wangqiu.orb")
kpts5 = image.load_descriptor("/hongniu.orb")
img = sensor.snapshot()
#draw_keypoints(img, kpts1)
clock = time.clock()
while (True):
clock.tick()
img = sensor.snapshot()
sensor.set_framesize(sensor.VGA)
sensor.set_pixformat(sensor.GRAYSCALE)
kptsn = img.find_keypoints(max_keypoints=150, threshold=10, normalized=True)
if kptsn:
match0 = image.match_descriptor(kpts1, kptsn, threshold=85)
if (match0.count()>12):
img.draw_rectangle(match0.rect())
img.draw_cross(match0.cx(), match0.cy(), size=10)
print("特仑苏")
#break
match1 = image.match_descriptor(kpts2, kptsn, threshold=85)
if(match1.count()>5):
img.draw_rectangle(match1.rect())
img.draw_cross(match1.cx(), match1.cy(), size=10)
print("雪花")
#break
match2=image.match_descriptor(kpts3,kptsn,threshold=85)
if(match2.count()>10):
img.draw_rectangle(match2.rect())
img.draw_cross(match2.cx(), match2.cy(), size=10)
print("AD钙")
#break
match3=image.match_descriptor(kpts4,kptsn,threshold=85)
if(match3.count()>15):
img.draw_rectangle(match3.rect())
img.draw_cross(match3.cx(), match3.cy(), size=10)
print("网球")
#break
match4=image.match_descriptor(kpts5,kptsn,threshold=85)
if(match4.count()>8):
img.draw_rectangle(match4.rect())
img.draw_cross(match4.cx(), match4.cy(), size=10)
print("红牛")
#break
else:
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA)
img = sensor.snapshot().lens_corr(1.8)
for r in img.find_rects(threshold = 10000):
area =r.rect()
statistics = img.get_statistics(roi=area)#像素颜色统计
print(statistics)
if 35<statistics.l_mode()<60 and 40<statistics.a_mode()<85 and 35<statistics.b_mode()<65:#if the circle is red
img.draw_rectangle(area, color = (255, 255, 255))#识别到的红色圆形用红色的圆框出来
print("red")
elif 20<statistics.l_mode()<100 and -70<statistics.a_mode()<-8 and -32<statistics.b_mode()<60:
img.draw_rectangle(area, color = (255, 255, 255))#识别到的红色圆形用红色的圆框出来
print("green")
elif 25<statistics.l_mode()<100 and -20<statistics.a_mode()<50 and -80<statistics.b_mode()<55:
img.draw_rectangle(area, color = (255, 255, 255))#识别到的红色圆形用红色的圆框出来
print("blue")
#print(kpts2, "matched:%d dt:%d"%(match.count(), match.theta()))
# NOTE: uncomment if you want to draw the keypoints
#img.draw_keypoints(kpts2, size=KEYPOINTS_SIZE, matched=True)
# Draw FPS
#img.draw_string(0, 0, "FPS:%.2f"%(clock.fps()))这样写对吗
https://singtown.com/learn/50029/