def find():
global piexel_y_L
global piexel_x_L
global piexel_y_L
global piexel_x_L
for i in range(240,180,-1):
for j in range(160,-1,-1):
if img.get_pixel(i,j)==255:
print(img.get_pixel(i,j))
piexel_y_L=i
piexel_x_L=j
print('piexel_y_L=%d,piexel_x_L=%d'%(i,j))
break
else:
piexel_x_L=0
print('piexel_y_L=%d,piexel_x_L=%d'%(i,0))
for j in range(160,320,1):
if img.get_pixel(i,j)==255:
print(img.get_pixel(i,j))
piexel_y_R=i
piexel_x_R=j
print('piexel_y_R=%d,piexel_x_R=%d'%(i,j))
break
else:
piexel_x_R=319
print('piexel_y_R=%d,piexel_x_R=%d'%(i,319))
break
import pyb, sensor, image,time
sensor.reset()
sensor.set_framesize(sensor.QVGA)
uart = pyb.UART(3, 19200)
grayscale_thres = (200, 255)
while(True):
sensor.set_pixformat(sensor.GRAYSCALE)
#sensor.set_windowing((0, 180,320,60))
#for i in range(20):
img = sensor.snapshot()
img.binary([grayscale_thres])
img.erode(2)
find()真的看不懂你的问题……
结果不正确,是怎么不正确?
和预期的不符?那什么是预期的结果?现象又是什么?
@kidswong999 屏幕上显示是白色的点,但获取的像素点二值化值确实黑色(值为0)
@17791079974 程序的结果是要从图像的240-180的中间(即从第160个点开始)向左右搜索,找到第一个遇到的黑点就跳出循环,并记录这个点的坐标,但是这个过程中获取到的像素点的值与我观察到的不一致
@陆时由 解决了,获取像素的i,j写反了
黑色是0,白色是255.
你是不是搞反了。。。?