可以给写一个历程吗,开白色和关闭白色
lxuy 发布的帖子
-
RE: 颜色过去以后会出现好几遍这个颜色,能不能只出现一次
现在是会出现好几个1好几个2好几个4但是我只想要一个124,就是这个红色会识别很多次绿色会识别很多次,蓝色会识别很多次
-
颜色过去以后会出现好几遍这个颜色,能不能只出现一次
颜色过去以后会出现好几遍这个颜色,能不能只出现一次
import sensor, image,time,pyb,utime import sensor, image, time,utime from pyb import UART uart = UART(3, 57600) output_str=0 yanse=0 flag=1 while 1: if uart.any(): flag=uart.readline().decode() flag=int(flag) print(flag) if flag==1: thresholds = [(60, 18, 37, 75, -35, 76),(58, 24, -11, 17, -61, -16),(60, 30, -17, -58, -43, 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) while flag : img = sensor.snapshot() blobs=img.find_blobs(thresholds, pixels_threshold=5000, area_threshold=400) for blob in blobs: img.draw_rectangle(blob.rect()) img.draw_cross(blob.cx(), blob.cy()) yanse="%s" % (blob.code()) print( yanse) if yanse: uart.write(yanse) yanse=0
-
两个程序运行
我要识别三个颜色,当三个颜色识别结束以后退出颜色识别程序打开二维码扫码程序,但是不能累加颜色识别计数
这是程序import sensor, image,time,pyb,utime import sensor, image, time,utime from pyb import UART p0 = pyb.Pin('P0', pyb.Pin.OUT_PP) p0.value(1) uart = UART(3, 57600) output_str=0 yanse=0 flag0=1 f=0 while 1: if uart.any(): flag0=uart.readline().decode() flag0=int(flag0) print(flag0) if flag0==1: thresholds= [(60, 18, 37, 75, -35, 76),(58, 24, -11, 17, -61, -16),(60, 30, -17, -58, -43, 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) while flag0 : img = sensor.snapshot() blobs=img.find_blobs(thresholds, pixels_threshold=5000, area_threshold=400) for blob in blobs: img.draw_rectangle(blob.rect()) img.draw_cross(blob.cx(), blob.cy()) yanse="%s" % (blob.code()) print( yanse) pyb.delay(500) if yanse : f=f+1 uart.write(yanse) yanse=0 if f==3 : flag0=2 if flag0==2: sensor.reset() sensor.set_pixformat(sensor.GRAYSCALE) sensor.set_framesize(sensor.VGA) sensor.set_windowing((240, 240)) sensor.skip_frames(30) sensor.set_auto_gain(False) while flag : img = sensor.snapshot() img.lens_corr(0.1) for code in img.find_qrcodes(): img.draw_rectangle(code.rect(), color = (255, 0, 0)) output_str="%s" % (code.payload()) print(output_str) pyb.delay(500) if output_str: uart.write(output_str) pyb.delay(10) p0.value(0) pyb.delay(10) p0.value(1) output_str=0 flag=0
-
两个标志位为什么标志为2不能执行,
import sensor, image,time,pyb,utime
import sensor, image, time,utime
from pyb import UART
p0 = pyb.Pin('P0', pyb.Pin.OUT_PP)
p0.value(1)
uart = UART(3, 19200)
output_str=0
yanse=0
flag=2
while 1:
if uart.any():
flag=uart.readline().decode()
flag=int(flag)
print(flag)
if flag==1:
sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.VGA)
sensor.set_windowing((240, 240)) # look at center 240x240 pixels of the VGA resolution.
sensor.skip_frames(30)
sensor.set_auto_gain(False) # must turn this off to prevent image washout...
clock = time.clock()
clock.tick()
img = sensor.snapshot()
img.lens_corr(0.1) # strength of 1.8 is good for the 2.8mm lens.
for code in img.find_qrcodes():
img.draw_rectangle(code.rect(), color = (255, 0, 0))
output_str="%s" % (code.payload())
uart.write(output_str)
print(output_str)
pyb.delay(500)
if output_str:
p0.value(0)
pyb.delay(10)
p0.value(1)
output_str=0
flag=0
if flag==2:
thresholds = [(54, 74, 44, 91, -16, 52),(76, 48, -22, 75, -76, -25),(68, 83, -47, -22, -7, 40)] # generic_blue_thresholds
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
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()
utime.sleep_ms(2000)
img = sensor.snapshot()
blobs=img.find_blobs(thresholds, pixels_threshold=5000, area_threshold=400)
for blob in blobs:
img.draw_rectangle(blob.rect())
img.draw_cross(blob.cx(), blob.cy())
yanse="%s" % (blob.code())
uart.write(yanse)
print( yanse)
pyb.delay(500)
if yanse:
p0.value(0)
pyb.delay(10)
p0.value(1)
yanse=0