@kidswong999
主要是翻转查找对象,需要使用invert参数设置。
3
3iy5 发布的帖子
-
RE: 循迹画框修改默认颜色
请教各位大神,我使用上述代码,它默认寻找的是白色物体,我想修改寻找黑色物品。请问怎么修改修改哪些变量?
31行代码:blobs = img.find_blobs([red_threshold_01], area_threshold=150)
修改为
blobs = img.find_blobs([red_threshold_01],invert=True, area_threshold=150)
invert 反转阈值,把阈值以外的颜色作为阈值进行查找;默认情况下是false
-
循迹画框修改默认颜色
# 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 # 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 = (36, 100, -26, 122, -113, 118) #设置红色的阈值,括号里面的数值分别是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. sensor.skip_frames(10) # Let new settings take affect. sensor.set_auto_whitebal(False) #关闭白平衡。白平衡是默认开启的,在颜色识别中,需要关闭白平衡。 clock = time.clock() # Tracks FPS. 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.binary([(100, 255)],invert=False) blobs = img.find_blobs([red_threshold_01], area_threshold=150) if blobs: #如果找到了目标颜色 print(blobs) for b in blobs: #迭代找到的目标颜色区域 # Draw a rect around the blob. img.draw_rectangle(b[0:4]) # rect #用矩形标记出目标颜色区域 img.draw_cross(b[5], b[6]) # cx, cy #在目标颜色区域的中心画十字形标记 print(clock.fps()) # Note: Your OpenMV Cam runs about half as fast while # connected to your computer. The FPS should increase once disconnected.
请教各位大神,我使用上述代码,它默认寻找的是白色物体,我想修改寻找黑色物品。请问怎么修改修改哪些变量?
十分感谢您在百忙之中回答我的问题。