import sensor, image, time
from pyb import Pin
import math
threshold_index = 0
thresholds = [
(34, 82, -32, -12, -13, 31),
]
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time=2000)
sensor.set_auto_gain(False)
sensor.set_auto_whitebal(False)
clock = time.clock()
pin0 = Pin("P0", Pin.OUT_PP, Pin.PULL_NONE)
pin1 = Pin("P1", Pin.OUT_PP, Pin.PULL_NONE)
LED1 = Pin("P2", Pin.OUT_PP, Pin.PULL_NONE)
LED2 = Pin("P3", Pin.OUT_PP, Pin.PULL_NONE)
while True:
clock.tick()
img = sensor.snapshot()
for blob in img.find_blobs(
[thresholds[threshold_index]],
pixels_threshold=200,
area_threshold=200,
merge=True,
):
if blob.elongation() > 0.5:
img.draw_edges(blob.min_corners(), color=(255, 0, 0))
img.draw_line(blob.major_axis_line(), color=(0, 255, 0))
img.draw_line(blob.minor_axis_line(), color=(0, 0, 255))
img.draw_rectangle(blob.rect())
img.draw_cross(blob.cx(), blob.cy())
img.draw_keypoints(
[(blob.cx(), blob.cy(), int(math.degrees(blob.rotation())))], size=20
)
pin1.value(1)
LED1.value(1)
pin0.value(0)
LED2.value(0)
time.sleep(5)
print(clock.fps())
pin1.value(0)
LED1.value(0)
pin0.value(1)
LED2.value(1)
time.sleep(5)
G
gqmf
@gqmf
0
声望
4
楼层
654
资料浏览
0
粉丝
0
关注
gqmf 发布的帖子
-
摄像头运行过程中,画面卡顿怎么解决?希望摄像头在供电的情况下一直识别颜色
-
下载代码后Open MV指示灯不亮不知道是否在工作,是代码问题吗
import sensor, image, time from pyb import Pin import math threshold_index = 0 thresholds = [ (34, 82, -32, -12, -13, 31), ] sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) sensor.skip_frames(time=2000) sensor.set_auto_gain(False) sensor.set_auto_whitebal(False) clock = time.clock() pin0 = Pin("P0", Pin.OUT_PP, Pin.PULL_NONE) pin1 = Pin("P1", Pin.OUT_PP, Pin.PULL_NONE) LED1 = Pin("P2", Pin.OUT_PP, Pin.PULL_NONE) LED2 = Pin("P3", Pin.OUT_PP, Pin.PULL_NONE) while True: clock.tick() img = sensor.snapshot() for blob in img.find_blobs( [thresholds[threshold_index]], pixels_threshold=200, area_threshold=200, merge=True, ): if blob.elongation() > 0.5: img.draw_edges(blob.min_corners(), color=(255, 0, 0)) img.draw_line(blob.major_axis_line(), color=(0, 255, 0)) img.draw_line(blob.minor_axis_line(), color=(0, 0, 255)) img.draw_rectangle(blob.rect()) img.draw_cross(blob.cx(), blob.cy()) img.draw_keypoints( [(blob.cx(), blob.cy(), int(math.degrees(blob.rotation())))], size=20 ) if detected : pin1.value(1) LED1.value(1) time.sleep(30) pin1.value(0) LED1.value(0) else: pin0.value(1) LED2.value(1) time.sleep(30) print(clock.fps())