
程序错误代码为list index out of range
但是输出的tag列表没有超范围,求助
请把报错提示和代码一起截图
一个提问,一个帖子,标题为问题的介绍
请贴出具体的代码,与报错提示。
代码一定要让别人可以运行的文本,不要贴图片
@yuan
```
# 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 PID
# You 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 tag
while(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)请截报错的图。因为报错是提示你具体哪行错的。
这个算是基本能实现跟踪apriltag标签了,但是我想要的是通过云台来搜索标签在来控制小车的运动,请问这个可以实现吗
可以实现,但云台和小车不能直接都接到同一个OpenMV上,引脚冲突。你要考虑自己加主控串口通信。