logo

从图像底部160列向左右分别寻找黑色点,遇到第一个黑色点停止并记录,但是返回的结果好像不正确

2018-07-03 09:20
C
_17791079974
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()
2018-07-04 11:55
I
网红小智智 星瞳科技

真的看不懂你的问题……

结果不正确,是怎么不正确?

和预期的不符?那什么是预期的结果?现象又是什么?

2018-07-04 22:37
C
_17791079974

@kidswong999 屏幕上显示是白色的点,但获取的像素点二值化值确实黑色(值为0)

C
_17791079974

@17791079974 程序的结果是要从图像的240-180的中间(即从第160个点开始)向左右搜索,找到第一个遇到的黑点就跳出循环,并记录这个点的坐标,但是这个过程中获取到的像素点的值与我观察到的不一致

2018-07-04 23:45
C
_17791079974

@陆时由 解决了,获取像素的i,j写反了

2018-07-05 10:52
X
Yuan

黑色是0,白色是255.

你是不是搞反了。。。?