可以收到
1
1
1
1
2nc3 发布的帖子
-
RE: 数据接收问题,怎么办
不对
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
-
数据接收问题,怎么办
# 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
这样的 -
tag码识别有误差,偏转角度时
我选择性的求了x,z的k,当摄像头与tag码平行时误差可以接受,但tag码偏转角度时,测量误差就太大了。想问一下z,x的距离是摄像头到tag码中心的距离吗,当偏转时是要再加入角度进行计算吗?
import sensor, image, time, math sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QQVGA) # 如果分辨率大得多,内存就不够用了…… sensor.skip_frames(time = 2000) sensor.set_auto_gain(False) # 必须关闭此功能,以防止图像冲洗… sensor.set_auto_whitebal(False) # 必须关闭此功能,以防止图像冲洗… clock = time.clock() # 注意!与find_qrcodes不同,find_apriltags方法不需要对镜像进行镜头校正。 #标签系列有什么区别? 那么,例如,TAG16H5家族实际上是一个4x4的方形标签。 #所以,这意味着可以看到比6x6的TAG36H11标签更长的距离。 #然而,较低的H值(H5对H11),意味着4x4标签的假阳性率远高于6x6标签。 #所以,除非你有理由使用其他标签系列,否则使用默认族TAG36H11。 # AprilTags库输出标签的姿势信息。 这是x / y / z平移和x / y / z旋转。 # x / y / z旋转以弧度表示,可以转换为度数。 至于翻译单位是无量纲的, # 你必须应用一个转换函数。 # f_x是相机的x焦距。它应该等于以mm为单位的镜头焦距除以x传感器尺寸(以mm为单位)乘以图像中的像素数。 # 以下数值适用于配备2.8毫米镜头的OV7725相机。 # f_y是相机的y焦距。它应该等于以mm为单位的镜头焦距除以y传感器尺寸(以mm为单位)乘以图像中的像素数。 # 以下数值适用于配备2.8毫米镜头的OV7725相机。 # c_x是以像素为单位的图像x中心位置 # c_x是以像素为单位的图像x中心位置 f_x = (2.8 / 3.984) * 160 # find_apriltags 如果没有设置,则默认为这个 f_y = (2.8 / 2.952) * 120 # find_apriltags 如果没有设置,则默认为这个 c_x = 160 * 0.5 # find_apriltags 如果没有设置,则默认为这个 (the image.w * 0.5) c_y = 120 * 0.5 # find_apriltags 如果没有设置,则默认为这个 (the image.h * 0.5) k_z=-5.97 k_x=11.159 def degrees(radians): return (180 * radians) / math.pi while(True): clock.tick() img = sensor.snapshot() for tag in img.find_apriltags(families=image.TAG25H9,fx=f_x, fy=f_y, cx=c_x, cy=c_y): # 默认为 TAG36H11 img.draw_rectangle(tag.rect(), color = (255, 0, 0)) img.draw_cross(tag.cx(), tag.cy(), color = (0, 255, 0)) print_args = (tag.x_translation(), tag.y_translation(), tag.z_translation(), \ degrees(tag.x_rotation()), degrees(tag.y_rotation()), degrees(tag.z_rotation())) # 变换单位不详。旋转单位是度数。 #print("Tx: %f, Ty %f, Tz %f, Rx %f, Ry %f, Rz %f" % print_args) print(tag.id(),"x:",k_x*tag.x_translation()," z:",k_z*tag.z_translation()) print(clock.fps())
-
RE: 我在uart.write(c[0].x,c[1].x等等点)时会报错,让我不要加[],
import sensor, image, time, pyb sensor.reset() sensor.set_pixformat(sensor.RGB565) # grayscale is faster sensor.set_framesize(sensor.QQVGA) sensor.skip_frames(time = 2000) clock = time.clock() while(True): clock.tick() img = sensor.snapshot().lens_corr(1.8) # Circle objects have four values: x, y, r (radius), and magnitude. The # magnitude is the strength of the detection of the circle. Higher is # better... # `threshold` controls how many circles are found. Increase its value # to decrease the number of circles detected... # `x_margin`, `y_margin`, and `r_margin` control the merging of similar # circles in the x, y, and r (radius) directions. # r_min, r_max, and r_step control what radiuses of circles are tested. # Shrinking the number of tested circle radiuses yields a big performance boost. for circles in img.find_circles(threshold = 2000, x_margin = 10, y_margin = 10, r_margin = 10, r_min = 2, r_max = 100, r_step = 2): img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0)) c0=circles[0].x() print(c0)
最后就会显示AttributeError: 'int' object has no attribute 'x'
-
我在uart.write(c[0].x,c[1].x等等点)时会报错,让我不要加[],
是这样的,但我在uart.write(c[0].x,c[1].x等等点)时会报错,让我不要加[],这怎样解决
-
RE: 我可以在while内再进行roi的设置吗
同时,若果可以这么设置,那再新的roi区域里,识别到的新的圆形坐标是相对于整个图像的像素坐标还是相对于新的roi区域坐标的
-
串口输出坐标,为什么会失败
import sensor, image, time from machine import UART uart = UART(2, baudrate=115200) uart_num = 0 uart_array = [48,49,50,51,52,53,54,55,56,57] uart.write(uart_num.to_bytes(1, 'little')) uart.write(bytearray(uart_array)) uart.write(bytearray([0x41])) # 发送一个十六进制数据 sensor.reset() sensor.set_pixformat(sensor.RGB565) # grayscale is faster sensor.set_framesize(sensor.QQVGA) sensor.skip_frames(time = 2000) clock = time.clock() while(True): uart_num = uart.any() clock.tick() img = sensor.snapshot().lens_corr(1.8) # Circle objects have four values: x, y, r (radius), and magnitude. The # magnitude is the strength of the detection of the circle. Higher is # better... # `threshold` controls how many circles are found. Increase its value # to decrease the number of circles detected... # `x_margin`, `y_margin`, and `r_margin` control the merging of similar # circles in the x, y, and r (radius) directions. # r_min, r_max, and r_step control what radiuses of circles are tested. # Shrinking the number of tested circle radiuses yields a big performance boost. for c in img.find_circles(threshold = 2000, x_margin = 10, y_margin = 10, r_margin = 10, r_min = 2, r_max = 100, r_step = 2): img.draw_circle(c.x(), c.y()) if(uart_num): uart_str = uart.read(uart_num) uart.write(uart_str)
-
怎样避开json实现传出多个圆坐标
from machine import UART import json, sensor, image, time uart = UART(2, baudrate=115200) sensor.reset() sensor.set_pixformat(sensor.RGB565) # grayscale is faster sensor.set_framesize(sensor.QQVGA) sensor.skip_frames(time = 2000) clock = time.clock() while(True): clock.tick() img = sensor.snapshot().lens_corr(1.8) # Circle objects have four values: x, y, r (radius), and magnitude. The # magnitude is the strength of the detection of the circle. Higher is # better... # `threshold` controls how many circles are found. Increase its value # to decrease the number of circles detected... # `x_margin`, `y_margin`, and `r_margin` control the merging of similar # circles in the x, y, and r (radius) directions. # r_min, r_max, and r_step control what radiuses of circles are tested. # Shrinking the number of tested circle radiuses yields a big performance boost. circles = img.find_circles(threshold = 2000, x_margin = 10, y_margin = 10, r_margin = 10, r_min = 2, r_max = 100, r_step = 2) uart.write("111") if circles: print('sum :', len(circles)) output_str = json.dumps(circles) for c in circles: img.draw_circle(c.x(), c.y()) print('you send:',output_str) uart.write(output_str+'\n')