logo

我用色块查找 一个色块的坐标 但是有时在同一个位置下 会出现两个坐标值

2022-09-21 10:00
U
dagb

我用色块查找 一个色块的坐标 但是有时在同一个位置下 会出现两个坐标值 比如绝大多数时间是65,65 然后突然在不定时间的区间内会出现10,10 。在这两个坐标值之间来回出现几次,然后就回复正常了65,65 请问是什么问题呢

2022-09-22 20:05
I
网红小智智 星瞳科技

如果涉及代码,需要报错提示与全部代码文本,请注意不要贴代码图片

2022-09-23 09:33
U
dagb

@kidswong999

没有出现报错 就是会时不时出现上面的问题

import sensor, image, time

from pyb import UART

thresholds = [(67, 100, -21, 127, -9, 127)]

sensor.reset()

sensor.set_pixformat(sensor.RGB565)

sensor.set_framesize(sensor.VGA)

sensor.skip_frames(time = 2000)

sensor.set_auto_gain(False)

sensor.set_auto_whitebal(False)

clock = time.clock()

uart = UART(3, 9600)

while(True):

clock.tick()

img = sensor.snapshot()

for blob in img.find_blobs([thresholds[0]] , x_stride = 2, y_stride = 1):

img.draw_rectangle(blob.rect())

img.draw_cross(blob.cx(),blob.cy())

if blob.cx() > 527 or blob.cx() < 143 or blob.cy() > 383 or blob.cy() < 89:

time.sleep_ms(1250)

break

else:

x_location = (blob.cx() - 335)*(105 / 384)

y_location = (blob.cy() - 236)*(80 / 294)

str1 = "*0,%.2f,%.2f=" % (x_location,y_location)

if len(str1) > 17 or len(str1) < 13:

time.sleep_ms(1250)

break

# print(str1)

uart.write(str1)

time.sleep_ms(1250)