我想要识别矩形,并测出旋转角度,如何实现
lw3f 发布的帖子
-
我想用它串口发送矩形四个角的坐标,报错:object with buffer protocol required
# Find Rects Example # # 这个例子展示了如何使用april标签代码中的四元检测代码在图像中找到矩形。 四元检测算法以非常稳健的方式检测矩形,并且比基于Hough变换的方法好得多。 例如,即使镜头失真导致这些矩形看起来弯曲,它仍然可以检测到矩形。 圆角矩形是没有问题的! # (但是,这个代码也会检测小半径的圆)... import sensor, image, time from pyb import UART import json sensor.reset() sensor.set_pixformat(sensor.RGB565) # 灰度更快(160x120 max on OpenMV-M7) sensor.set_framesize(sensor.QQVGA) sensor.skip_frames(time = 2000) clock = time.clock() uart = UART(3, 115200) uart.init(115200,bits=8,parity=None,stop=1,timeout_char=1000) while(True): clock.tick() img = sensor.snapshot() # 下面的`threshold`应设置为足够高的值,以滤除在图像中检测到的具有 # 低边缘幅度的噪声矩形。最适用与背景形成鲜明对比的矩形。 for r in img.find_rects(threshold = 10000): img.draw_rectangle(r.rect(), color = (255, 0, 0)) for p in r.corners(): img.draw_circle(p[0], p[1], 5, color = (0, 255, 0)) #print(r) data = r.corners() print(data) uart.write(data) #print("FPS %f" % clock.fps())
-
这个代码是要实现云台追踪应该怎么修改?
import sensor, image, time, math
threshold=(60, 255, -20, 20, -20, 20) # 激光灯在纸上颜色的阈值,可以执行调节
from pyb import Pin
sensor.reset()
sensor.set_auto_gain(False)
sensor.set_pixformat(sensor.GRAYSCALE) # or sensor.RGB565
sensor.set_framesize(sensor. QVGA) # or sensor.QVGA (or others)
sensor.skip_frames(time=900) # Let new settings take affect.
sensor.set_auto_exposure(False, 1000)#在这里调节曝光度,调节完可以比较清晰地看清激光点
sensor.set_auto_whitebal(False) # turn this off.
sensor.set_auto_gain(False) # 关闭增益(色块识别时必须要关)
clock = time.clock() # Tracks FPS.def color_blob(threshold):
blobs = img.find_blobs([threshold,x_stride=1, y_stride=1, area_threshold=0, pixels_threshold=0,merge=False,margin=1]) if len(blobs)>=1 :#有色块 # Draw a rect around the blob. b = blobs[0] img.draw_rectangle(b[0:4]) # rect cx = b[5] cy = b[6] for i in range(len(blobs)-1): img.draw_rectangle(b[0:4]) # rect cx = blobs[i][5]+cx cy = blobs[i][6]+cy cx=int(cx/len(blobs)) cy=int(cy/len(blobs)) img.draw_cross(cx, cy) # cx, cy print(cx,cy) return int(cx), int(cy) return -1, -1 #表示没有找到
while(True):
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot() # Take a picture and return the image.blobs = img.find_blobs([threshold]) if blobs: max_blob = color_blob(threshold) pan_error = max_blob.cx()-img.width()/2 tilt_error = max_blob.cy()-img.height()/2 print("pan_error: ", pan_error) img.draw_rectangle(max_blob.rect()) # rect img.draw_cross(max_blob.cx(), max_blob.cy()) # cx, cy pan_output=pan_pid.get_pid(pan_error,1)/2 tilt_output=tilt_pid.get_pid(tilt_error,1) print("pan_output",pan_output) pan_servo.angle(pan_servo.angle()+pan_output) tilt_servo.angle(tilt_servo.angle()-tilt_output)
-
这句代码应该怎么改,括号里面是什么意思
blobs = img.find_blobs([threshold,x_stride=1, y_stride=1, area_threshold=0, pixels_threshold=0,merge=False,margin=1])