import sensor, time, image, lcd, math,pyb
from pyb import UART
#RED_LED_PIN = 1
#BLUE_LED_PIN = 3
uart = UART(3, 115200)
sensor.reset()
sensor.set_contrast(3)
sensor.set_gainceiling(16)
sensor.set_framesize(sensor.HQVGA) # HQVGA最好,其次QVGA,QQVGA
sensor.set_pixformat(sensor.GRAYSCALE) #注意人脸识别只能用灰度图哦
sensor.skip_frames(10)
sensor.skip_frames(time = 5000) #等待5s
face_cascade = image.HaarCascade("frontalface", stages=25)
clock = time.clock()
lcd.init()
def face1():
uart.write("ok\r\n")
print("ok")
sensor.reset()
sensor.set_contrast(3)
sensor.set_gainceiling(16)
sensor.set_framesize(sensor.HQVGA) # HQVGA最好,其次QVGA,QQVGA
sensor.set_pixformat(sensor.GRAYSCALE) #注意人脸识别只能用灰度图哦
sensor.skip_frames(10) # Let new settings take affect.
sensor.skip_frames(time = 5000) #等待5s
while (True):
img = sensor.snapshot() # 拍摄一张照片
lcd.display(sensor.snapshot())
objects = img.find_features(face_cascade, threshold=0.75, scale=1.35) #thresholds越大,匹配速度越快,错误率也会上升。scale可以缩放被匹配特征的大小。
for r in objects:
img.draw_rectangle(r) #在找到的目标上画框,标记出来
if objects:
for object in objects:
fs=object[2]*object[3]
if fs>=14884:
print(fs)
print(objects)
break
while(True):
clock.tick()
img = sensor.snapshot() #1
lcd.display(sensor.snapshot()) #2 这两行无论哪一行运行,串口都无法接收到数据
a='0'
if uart.any():
a=uart.readline().decode()
print(a)
#pyb.delay(100)
if a=='a':
uart.write("a\r\n")
#img = sensor.snapshot()
face1()
print("face1")


标记的两行中,只要存在任意一行就无法接收到数据,是芯片处理能力不够吗?我见lcd与串口3的管脚定义也并没有重复
我想做的项目需要openMV作为识别装置,识别不同东西给32发送不同指令,并通过代码写的逻辑使得两块单片机通过互相通信实现自主运行
根据你的图片,第一张和第二张图片收到数据了。第三张图片没有收到数据。是吗?
@kidswong999 是前两张没收到数据,最后一张收到了
@kidswong999 我第一张是正常代码,无法接收到数据
第二张是把拍照的函数注释掉,也无法接收
第三张是把拍照和lcd显示的两个函数全注释掉,才能正常接收数据
第一张和第二张图片OpenMV收到数据了。第三张图片OpenMV没有收到数据。
因为IDE的终端里没有打印数据。
@kidswong999 你可以截下图我看下嘛?



@kidswong999 三次截图的不同之处在于,我把代码中的两行代码注释与否,所以才会得出不同结果,我想问的是代码中标记的两行代码为什么会影响串口发送数据?因为我看不到库是怎么写的,只有使用方法,所以现在不知道是哪里冲突还是怎样

看上去是if a=='a'这里有问题。
你可以试试再加一句else。
因为a有可以不是'a',
你的串口调试助手里的"发送新行",我不知道是加了'\r'还是'\n',还是'\r\n'。
假设是'\r\n'吧,那a有可能是'a\r\n'。
还有一个是沾包的问题。
解决办法就是串口初始化里设置一下timeout。
测试代码
import sensor, time, image, lcd, math,pyb
from pyb import UART
#RED_LED_PIN = 1
#BLUE_LED_PIN = 3
uart = UART(3, 115200)
sensor.reset()
sensor.set_contrast(3)
sensor.set_gainceiling(16)
sensor.set_framesize(sensor.HQVGA) # HQVGA最好,其次QVGA,QQVGA
sensor.set_pixformat(sensor.GRAYSCALE) #注意人脸识别只能用灰度图哦
sensor.skip_frames(10)
sensor.skip_frames(time = 5000) #等待5s
face_cascade = image.HaarCascade("frontalface", stages=25)
clock = time.clock()
lcd.init()
def face1():
uart.write("ok\r\n")
print("ok")
sensor.reset()
sensor.set_contrast(3)
sensor.set_gainceiling(16)
sensor.set_framesize(sensor.HQVGA) # HQVGA最好,其次QVGA,QQVGA
sensor.set_pixformat(sensor.GRAYSCALE) #注意人脸识别只能用灰度图哦
sensor.skip_frames(10) # Let new settings take affect.
sensor.skip_frames(time = 5000) #等待5s
while (True):
img = sensor.snapshot() # 拍摄一张照片
lcd.display(sensor.snapshot())
objects = img.find_features(face_cascade, threshold=0.75, scale=1.35) #thresholds越大,匹配速度越快,错误率也会上升。scale可以缩放被匹配特征的大小。
for r in objects:
img.draw_rectangle(r) #在找到的目标上画框,标记出来
if objects:
for object in objects:
fs=object[2]*object[3]
if fs>=14884:
print(fs)
print(objects)
break
while(True):
clock.tick()
img = sensor.snapshot() #1
lcd.display(sensor.snapshot()) #2 这两行无论哪一行运行,串口都无法接收到数据
a='0'
if uart.any():
a=uart.readline().decode()
print(a)
#pyb.delay(100)
if a=='a':
print('is a')
uart.write("a\r\n")
#img = sensor.snapshot()
face1()
print("face1")
else:
print('not a')
print(a)解决代码:
import sensor, time, image, lcd, math,pyb
from pyb import UART
#RED_LED_PIN = 1
#BLUE_LED_PIN = 3
uart = UART(3, 115200, timeout=1000)
sensor.reset()
sensor.set_contrast(3)
sensor.set_gainceiling(16)
sensor.set_framesize(sensor.HQVGA) # HQVGA最好,其次QVGA,QQVGA
sensor.set_pixformat(sensor.GRAYSCALE) #注意人脸识别只能用灰度图哦
sensor.skip_frames(10)
sensor.skip_frames(time = 5000) #等待5s
face_cascade = image.HaarCascade("frontalface", stages=25)
clock = time.clock()
lcd.init()
def face1():
uart.write("ok\r\n")
print("ok")
sensor.reset()
sensor.set_contrast(3)
sensor.set_gainceiling(16)
sensor.set_framesize(sensor.HQVGA) # HQVGA最好,其次QVGA,QQVGA
sensor.set_pixformat(sensor.GRAYSCALE) #注意人脸识别只能用灰度图哦
sensor.skip_frames(10) # Let new settings take affect.
sensor.skip_frames(time = 5000) #等待5s
while (True):
img = sensor.snapshot() # 拍摄一张照片
lcd.display(sensor.snapshot())
objects = img.find_features(face_cascade, threshold=0.75, scale=1.35) #thresholds越大,匹配速度越快,错误率也会上升。scale可以缩放被匹配特征的大小。
for r in objects:
img.draw_rectangle(r) #在找到的目标上画框,标记出来
if objects:
for object in objects:
fs=object[2]*object[3]
if fs>=14884:
print(fs)
print(objects)
break
while(True):
clock.tick()
img = sensor.snapshot() #1
lcd.display(sensor.snapshot()) #2 这两行无论哪一行运行,串口都无法接收到数据
a='0'
if uart.any():
a=uart.readline().decode().strip()
print(a)
#pyb.delay(100)
if a=='a':
print('is a')
uart.write("a\r\n")
#img = sensor.snapshot()
face1()
print("face1")
else:
print('not a')
print('a:',a)@kidswong999 谢谢你,问题解决了