你好,请教一个问题,怎么给识别到的图片进行编号
-
这是灰度图,识别到三个图像,我想给这三个图像从左到右进行编号1,2,3....我用坐标定位的话,只能一次随机测出一个图的坐标,我想请教一下,代码怎么编写,非常感谢!
-
如果是从左到右排序的话,可以用sorted函数,key就是中心横坐标。
import sensor, image, time sensor.reset() # Reset and initialize the sensor. sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE) sensor.set_framesize(sensor.QVGA) # Set frame size to QVGA (320x240) sensor.skip_frames(time = 2000) # Wait for settings take effect. clock = time.clock() # Create a clock object to track the FPS. green_threshold = (10,100,-30,40,-50,60)#随便写的,需要重新设置阈值 while(True): clock.tick() img = sensor.snapshot() blobs = img.find_blobs([green_threshold]) blobs = sorted(blobs,key=lambda b:b.cx()) for i in range(len(blobs)): print(i, blobs[i]) print(clock.fps())