@kidswong999
while(1)
拍照
if 找到红球
对准红球
if 找到绿球
对准绿球
else 来回转动
else 来回转动
简化了一下可以吗
Z
zgny
@zgny
0
声望
11
楼层
393
资料浏览
0
粉丝
0
关注
zgny 发布的帖子
-
RE: 如何实现先后识别颜色呢
-
RE: 如何实现先后识别颜色呢
@kidswong999 那大佬,我上面写的代码对吗?就先水平方向对准,没有夹住球的过程,找不到红球就0度到180度一直动找不到绿球也是0到180度一直动
-
如何实现先后识别颜色呢
先识别一个颜色然后跟踪,然后识别另一个颜色进行跟踪
while(True):
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot() # Take a picture and return the image.blobs = img.find_blobs([red_threshold]) if blobs: max_blob = find_max(blobs) pan_error = max_blob.cx()-img.width()/2 tilt_error = max_blob.cy()-img.height()/2 print("pan_error: ", pan_error) img.draw_rectangle(max_blob.rect()) # rect img.draw_cross(max_blob.cx(), max_blob.cy()) # cx, cy pan_output=pan_pid.get_pid(pan_error,1)/2 tilt_output=tilt_pid.get_pid(tilt_error,1) print("pan_output",pan_output) pan_servo.angle(pan_servo.angle()+pan_output) blobs = img.find_blobs([green_threshold]) if blobs: max_blob = find_max(blobs) pan_error = max_blob.cx()-img.width()/2 tilt_error = max_blob.cy()-img.height()/2 print("pan_error: ", pan_error) img.draw_rectangle(max_blob.rect()) # rect img.draw_cross(max_blob.cx(), max_blob.cy()) # cx, cy pan_output=pan_pid.get_pid(pan_error,1)/2 tilt_output=tilt_pid.get_pid(tilt_error,1) print("pan_output",pan_output) pan_servo.angle(pan_servo.angle()+pan_output) else: pan_servo.angle(0) pan_servo.angle(180) else: pan_servo.angle(0) pan_servo.angle(180)
这样对吗
-
求解 pan_servo.angle和tilt_servo.angle哪一个是横向转动,哪一个是纵向转动呢
while(True):
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot() # Take a picture and return the image.blobs = img.find_blobs([red_threshold]) if blobs: max_blob = find_max(blobs) pan_error = max_blob.cx()-img.width()/2 tilt_error = max_blob.cy()-img.height()/2 print("pan_error: ", pan_error) img.draw_rectangle(max_blob.rect()) # rect img.draw_cross(max_blob.cx(), max_blob.cy()) # cx, cy pan_output=pan_pid.get_pid(pan_error,1)/2 tilt_output=tilt_pid.get_pid(tilt_error,1) print("pan_output",pan_output) pan_servo.angle(pan_servo.angle()+pan_output) tilt_servo.angle(tilt_servo.angle()-tilt_output)