logo

引用特定于OpenMV Cam的库 的问题

2022-07-26 16:56
T
gmfo
import sensor, image, time

sensor.reset()
sensor.set_pixformat(sensor.RGB565) # 灰度更快(160x120 max on OpenMV-M7)
sensor.set_framesize(sensor.QQVGA)#160 * 120
sensor.skip_frames(time = 2000)
clock = time.clock()

while(True):
    clock.tick()
    img = sensor.snapshot()

    for r in img.find_rects(threshold = 20000):                                         
              
        img.draw_rectangle(r.rect(), color = (255, 0, 0))
        rects=img.find_rects(threshold = 20000)
            
      
        for p in r.corners(): 
            img.draw_circle(p[0], p[1], 5, color = (0, 255, 0)) 
            x=rect.x()
        
        print(r)

    print("FPS %f" % clock.fps())

运行报错NameError: name 'rect' isn't defined

应该如何写这个函数(rect.x())

2022-07-26 18:18
I
网红小智智 星瞳科技

你代码写的不对。

正确的代码:

import sensor, image, time

sensor.reset()
sensor.set_pixformat(sensor.RGB565) # 灰度更快(160x120 max on OpenMV-M7)
sensor.set_framesize(sensor.QQVGA)#160 * 120
sensor.skip_frames(time = 2000)
clock = time.clock()

while(True):
    clock.tick()
    img = sensor.snapshot()

    for r in img.find_rects(threshold = 20000):                                         
              
        img.draw_rectangle(r.rect(), color = (255, 0, 0))
            
        for p in r.corners(): 
            img.draw_circle(p[0], p[1], 5, color = (0, 255, 0)) 
        x=r.x()
        print(x)
        
        print(r)

    print("FPS %f" % clock.fps())
2022-07-26 18:50
T
gmfo

谢谢:winking_face: