logo

怎样得到物块位置

2018-11-20 16:39
Z
rsyh

就是的到cx,cy,x,y这些值的。想把他们定义到变量当中,就像h=cx(h为某一变量)

I
网红小智智 星瞳科技

有什么问题?变量复制就行,就像你说的那样。:smiling_face_with_open_mouth_cold_sweat:

Z
rsyh

就是那个色块识别的程序,有个print(clock.fps())直接把所有的都输出了。但是我想判断里面的cx,cy,然后再发送命令

I
网红小智智 星瞳科技

print(clock.fps())只是输出帧率,和你的色块没有关系。

Z
rsyh

cx,cy是色块的位置吧。我是想判断他的大小,然后控制机械手去抓。但是我不知道怎么调用cx,cy的值来做判断

I
网红小智智 星瞳科技

不明白有什么不懂的,看一下python的语法就知道了。

print(cx, cy)
if cx > 10 and cy >10:
   xxx
Z
rsyh

显示错误。提示是name 'cx' is not defined

I
网红小智智 星瞳科技

请贴出具体的代码,与报错提示。

代码一定要让别人可以运行的文本,不要贴图片

2018-11-20 16:57
Z
rsyh

import sensor, image, timered_threshold_01 = (0, 35, 0, 50, -10, 40)sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QQVGA) sensor.skip_frames(10) sensor.set_auto_whitebal(False)clock = time.clock() while(True): clock.tick() img = sensor.snapshot() blobs = img.find_blobs([red_threshold_01], area_threshold=150) if blobs: print(blobs) for b in blobs: img.draw_rectangle(b[0:4]) img.draw_cross(b[5], b[6]) print(cx,cy) print(clock.fps())

2018-11-20 17:43
I
网红小智智 星瞳科技

你的代码格式不对,我没法运行