程序有时候可以用,有时候两三秒之后就会卡死。
-
# Blob Detection Example # # This example shows off how to use the find_blobs function to find color # blobs in the image. This example in particular looks for dark green objects. import sensor, image, time,utime,lcd from pyb import Servo from pyb import Pin # For color tracking to work really well you should ideally be in a very, very, # very, controlled enviroment where the lighting is constant... red_threshold_01 = (0, 24, -22, 43, -8, 41) #设置红色的阈值,括号里面的数值分别是L A B 的最大值和最小值(minL, maxL, minA, # maxA, minB, maxB),LAB的值在图像左侧三个坐标图中选取。如果是灰度图,则只需 #设置(min, max)两个数字即可。 # You may need to tweak the above settings for tracking green things... # Select an area in the Framebuffer to copy the color settings. sensor.reset() # Initialize the camera sensor. sensor.set_pixformat(sensor.RGB565) # use RGB565. sensor.set_framesize(sensor.QQVGA) # use QQVGA for speed. lcd.init() # Initialize the lcd screen. sensor.skip_frames(50) # Let new settings take affect. p_in00 = Pin("P5", Pin.IN)#设置p0输入 p_in00.value() sensor.set_auto_whitebal(False) #关闭白平衡。白平衡是默认开启的,在颜色识别中,需要关闭白平衡。 clock = time.clock() # Tracks FPS. start = utime.ticks_ms() # get value of millisecond counter 获取毫秒计数器的值 while(True): sensor.set_vflip(True) #垂直方向翻转 if(p_in00.value()==0): print(p_in00.value()) while(True): clock.tick() # Track elapsed milliseconds between snapshots(). img = sensor.snapshot() # Take a picture and return the image. # pixels_threshold=100, area_threshold=100 blobs = img.find_blobs([red_threshold_01], area_threshold=150) if blobs: #如果找到了目标颜色 for b in blobs: #迭代找到的目标颜色区域 # Draw a rect around the blob. if(blobs[0].pixels())>6000: tt=utime.ticks_diff(utime.ticks_ms(), start) print(utime.ticks_diff(utime.ticks_ms(), start)) img.draw_rectangle(b[0:4]) # rect #用矩形标记出目标颜色区域 img.draw_cross(b[5], b[6]) # cx, cy #在目标颜色区域的中心画十字形标记 while(True): lcd.display(img.draw_string(20,0, "%d"%tt,200,2)) lcd.display(sensor.snapshot()) # Take a picture and display the image. #print(clock.fps()) # Note: Your OpenMV Cam runs about half as fast while # connected to your computer. The FPS should increase once disconnected. ```
-
在同学的openmv就不会卡顿,但是我用新的就不行,一会好,一会就两三秒卡死。求大佬帮忙解决。
-
这个代码目的就是识别到颜色,并从开始到识别到颜色这段时间进行及时
-
代码逻辑的问题,
你的程序有死循环,还没有break,当然不会跳出。