数据接收问题,怎么办
-
# Hello World Example # # Welcome to the OpenMV IDE! Click on the green run arrow button below to run the script! import sensor, image, time, math from machine import UART uart = UART(2, baudrate=115200) 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. thresholds = (64, 81) while(True): clock.tick() # Update the FPS clock. img = sensor.snapshot() # Take a picture and return the image. uart_num = uart.any() # 获取当前串口数据数量 if(uart_num): uart_str = uart.read(uart_num).decode().strip() # 读取串口数据 print(uart_str) if(uart_str==3): print("lllll") for blob in img.find_blobs([thresholds], pixels_threshold=100, area_threshold=100, merge=True): # These values depend on the blob not being circular - otherwise they will be shaky. if blob.elongation() > 0.5: img.draw_edges(blob.min_corners(), color=0) img.draw_line(blob.major_axis_line(), color=0) img.draw_line(blob.minor_axis_line(), color=0) # These values are stable all the time. img.draw_rectangle(blob.rect(), color=127) if blob.cy()>110 and blob.cx()<200 and blob.cx()> 160 and blob.cy()< 130: uart.write("t") print("t") elif blob.cy()< 110 and blob.cx()> 160 and blob.cx() < 200: uart.write("h") print("q") elif blob.cy()> 130 and blob.cx()<200 and blob.cx()> 160: uart.write("q") print("h") elif blob.cx()<160: uart.write("y") print("z") elif blob.cx() > 200: uart.write("z") print("y")
等于3判定不通过
接受的是
3
3
3
3
3
3
这样的
-
if(uart_str==3):
改为
if(uart_str=='3'):
-
不对
enable_lens_corr = False # turn on for straighter lines...import sensor, image, time, pyb, math
import os, tf
from machine import UART
from pyb import LED
from struct import packwhite=LED(4)
uart = UART(2, 115200)
sensor.reset()
sensor.set_auto_gain(False) # must be turned off for color tracking
sensor.set_auto_whitebal(False) # must be turned off for color tracking
#sensor.set_auto_whitebal(False)
sensor.set_pixformat(sensor.RGB565) # 灰度更快(160x120 max on OpenMV-M7)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
clock = time.clock()
thresholds=(30, 65, -27, 47, -15, 33)
#Large_area=[76,22,210,122]
net_path = "mobilenet_v2-2022-06-29T03-44-15.608Z_in-int8_out-int8_channel_ptq.tflite" # 定义模型的路径
labels = [line.rstrip() for line in open("/sd/labels_animal_fruits_traffic.txt")] # 加载标签
net = tf.load(net_path, load_to_fb=True) # 加载模型min_degree = 70
max_degree = 110#点到直线距离公式
def get_point_line_distance(point, p0, p1):
point_x = point[0]
point_y = point[1]
line_s_x, line_s_y=p0
line_e_x, line_e_y=p1
#若直线与y轴平行,则距离为点的x坐标与直线上任意一点的x坐标差值的绝对值
if line_e_x - line_s_x == 0:
return math.fabs(point_x - line_s_x)
#若直线与x轴平行,则距离为点的y坐标与直线上任意一点的y坐标差值的绝对值
if line_e_y - line_s_y == 0:
return math.fabs(point_y - line_s_y)
#斜率
k = (line_e_y - line_s_y) / (line_e_x - line_s_x)
#截距
b = line_s_y - k * line_s_x
#带入公式得到距离dis
dis = math.fabs(k * point_x - point_y + b) / math.pow(k * k + 1, 0.5)
return dis
#两点长度计算
def get_point_point_distance(p0, p1):
line_s_x, line_s_y=p0
line_e_x, line_e_y=p1
line_long = math.sqrt(pow(line_s_x-line_e_x,2)+pow(line_s_y-line_e_y,2))
return line_longwhile(True):
clock.tick()
img = sensor.snapshot().lens_corr(1.8)
white.on()
uart_str = uart.read(uart.any()).decode().strip()
print(uart_str)
if(uart_str=='1'):
print("a")
print("...........")这样我仍然无法打印a
-
打印a那是有空格的
-
这是发送端
-
可以收到
1
1
1
1
-
@2nc3 把OpenMV终端的log发一下。
-
先用串口调试扩展板,和星瞳串口助手测试。