utime报错'module' object has no attribute 'sleep_ms'如何解决?
-
红外RGB565跟踪示例
这个例子展示了使用OpenMV Cam进行红外RGB565跟踪。
import sensor, image
#import timefrom pyb import UART
import utime
import pyb
thresholds = (100,100,0,0,0,0) # thresholds for bright white light from IR.
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.VGA)
sensor.set_windowing((240,240)) # 240x240 center pixels of VGA
sensor.skip_frames(time = 10)
sensor.set_auto_gain(False) # must be turned off for color tracking
sensor.set_auto_whitebal(False) # must be turned off for color tracking
clock = time.clock() # Tracks FPS.
uart = UART(3, 115200)
def find_max(blobs):
max_size=0
for blob in blobs:
if blob.pixels() >max_size:
max_blob=blobmax_size = blob.pixels()
return max_blob
while(True):
time.sleep_ms(50)
#clock.tick() #for i in range(0,600): # clock.tick()# Track elapsed milliseconds between snapshots(). start = time.ticks_ms() #time_start = pyb.millis() img = sensor.snapshot()#binary([thresholds], invert=True, zero=True) blobs=img.find_blobs([thresholds],pixels_threshold=200,area_threshold=250) if blobs: output_str = json.dumps(blobs) max_blob=find_max(blobs) img.draw_rectangle(max_blob.rect(),color=(255,0,0)) output_str="[%d,%d]" % (max_blob.cx(),max_blob.cy()) print('you send:',output_str) uart.write(output_str+'\n') print(clock.fps()) delta = time.ticks_diff(time.ticks_ms(), start) #duration = pyb.elapsed_millis(time_start) print('a',delta) print("FPS:", clock.fps()) #img.draw_cross(blob.cx(), blob.cy()) else: print('not found!')
-
改成time.sleep()
-
在delta = time.ticks_diff(time.ticks_ms(), start)报错,'module' object has no attribute 'ticks_diff'
-
delta = utime.ticks_diff(utime.ticks_ms(), start)