这个算是基本能实现跟踪apriltag标签了,但是我想要的是通过云台来搜索标签在来控制小车的运动,请问这个可以实现吗
zvgd
@zvgd
zvgd 发布的帖子
-
RE: apriltag跟随小车无法实现
Blob Detection Example
This example shows off how to use the find_blobs function to find color
blobs in the image. This example in particular looks for dark green objects.
import sensor, image, time
import car
from pid import PIDYou may need to tweak the above settings for tracking green things...
Select an area in the Framebuffer to copy the color settings.
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA) # we run out of memory if the resolution is much bigger...
sensor.skip_frames(30)
sensor.set_auto_gain(False) # must turn this off to prevent image washout...
sensor.set_auto_whitebal(False) # turn this off.
clock = time.clock() # Tracks FPS.For color tracking to work really well you should ideally be in a very, very,
very, controlled enviroment where the lighting is constant...
f_x = (2.8 / 3.984) * 160 # 默认值
f_y = (2.8 / 2.952) * 120 # 默认值
c_x = 160 * 0.5 # 默认值(image.w * 0.5)
c_y = 120 * 0.5 # 默认值(image.h * 0.5)translation=-6
x_pid = PID(p=0.005, i=1, imax=100)
h_pid = PID(p=0.005, i=0.1, imax=50)def find_tag(tags):
size=0
for apriltag in tags:
print(apriltag)
if apriltag[2]*apriltag[3] > size:
tag=apriltag
size = apriltag[2]*apriltag[3]
return tagwhile(True):
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot() # Take a picture and return the image.tags = img.find_apriltags(fx=f_x, fy=f_y, cx=c_x, cy=c_y) # 默认为TAG36H11 #print(tags) if tags: tag = find_tag(tags) #print(tag) tag_id=tag[4] if (tag_id==2): print(tag[6]) x_error = tag[6]-img.width()/2 h_error = (tag[14]-translation)*200 #print(tag[14]) #print(h_error) #print("x error: ", x_error) ''' for b in blobs: # Draw a rect around the blob. img.draw_rectangle(b[0:4]) # rect img.draw_cross(b[5], b[6]) # cx, cy ''' img.draw_rectangle(tag[0:4], color = (255, 0, 0)) img.draw_cross(tag[6], tag[7], color = (0, 255, 0)) x_output=x_pid.get_pid(x_error,1) h_output=h_pid.get_pid(h_error,1) print("x_output",x_output) print("h_output",h_output) car.run(-h_output-x_output,-h_output+x_output) else: car.run(0,0)