openmv如果要做激光扫描三维重建测量物体尺寸要怎么实现
chep
@chep
chep 发布的帖子
-
为什么这段代码里面 颜色分割部分会报错
import sensor, image, time from pyb import Pin, LED # 初始化相机、LED灯和引脚 sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) led = LED(3) pin1 = Pin('P1', Pin.OUT_PP) # 预设颜色阈值 green_threshold = (72, 100, -1, 82, -11, 101) red_threshold = (0, 50, 20, 80, -10, 40) while True: # 获取图像并处理 img = sensor.snapshot() # 进行颜色分割 green_mask = img.color_threshold(green_threshold) red_mask = img.color_threshold(red_threshold) # 对颜色分割进行形态学操作 green_mask.erode(1) green_mask.dilate(2) red_mask.erode(1) red_mask.dilate(2) # 对颜色分割进行轮廓检测 green_blobs = green_mask.find_blobs(min_area=500) red_blobs = red_mask.find_blobs(min_area=500) # 数量统计到count变量中 count = len(green_blobs) + len(red_blobs) # 判断数量是否大于等于2,输出电平和点亮LED蓝灯 if count >= 2: pin1.low() led.on() else: pin1.high() led.off()
为什么这段代码里面green_mask = img.color_threshold(green_threshold)段会报错找不到原因
-
在这个代码里面怎么插入一个颜色识别,然后识别到颜色P0输出一个低电平信号,识别到神经网络模型,P1输出一个低电平信号。
# Edge Impulse - OpenMV Image Classification Example import sensor, image, time, os, tf, uos, gc 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.set_windowing((240, 240)) # Set 240x240 window. sensor.skip_frames(time=2000) # Let the camera adjust. net = None labels = None try: # load the model, alloc the model file on the heap if we have at least 64K free after loading net = tf.load("trained.tflite", load_to_fb=uos.stat('trained.tflite')[6] > (gc.mem_free() - (64*1024))) except Exception as e: print(e) raise Exception('Failed to load "trained.tflite", did you copy the .tflite and labels.txt file onto the mass-storage device? (' + str(e) + ')') try: labels = [line.rstrip('\n') for line in open("labels.txt")] except Exception as e: raise Exception('Failed to load "labels.txt", did you copy the .tflite and labels.txt file onto the mass-storage device? (' + str(e) + ')') clock = time.clock() while(True): clock.tick() img = sensor.snapshot() # default settings just do one detection... change them to search the image... for obj in net.classify(img, min_scale=1.0, scale_mul=0.8, x_overlap=0.5, y_overlap=0.5): print("**********\nPredictions at [x=%d,y=%d,w=%d,h=%d]" % obj.rect()) img.draw_rectangle(obj.rect()) # This combines the labels and confidence values into a list of tuples predictions_list = list(zip(labels, obj.output())) for i in range(len(predictions_list)): print("%s = %f" % (predictions_list[i][0], predictions_list[i][1])) print(clock.fps(), "fps")
-
RE: 怎么在这个代码里添加一个线段数量值然后达到线段数量比如识别5条线段后输出到一个引脚作低电平信号输出
@kidswong999 在 怎么在这个代码里添加一个线段数量值然后达到线段数量比如识别5条线段后输出到一个引脚作低电平信号输出 中说:
enable_lens_corr = False
import sensor, image, time
sensor.reset()
sensor.set_pixformat(sensor.RGB565) # 灰度更快
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time = 2000)
clock = time.clock()pin1 = Pin('P1', Pin.OUT_PP, Pin.PULL_NONE)
pin1.value(0)while(True):
clock.tick()
img = sensor.snapshot()
if enable_lens_corr: img.lens_corr(1.8) # for 2.8mm lens...
segments = img.find_line_segments(merge_distance = 0, max_theta_diff = 5)
result_segments = []for l in segments: if l.length() > 50: result_segments.append(l) if len(result_segments) > 5: pin1.value(1) else: pin1.value(0) for l in result_segments: img.draw_line(l.line(), color = (255, 0, 0)) # print(l) print("FPS %f" % clock.fps())
现在是可以过滤掉短的了 ,然后有一个就是 这个有办法过滤掉,好的线段的跳动吗?跳动变动,输出信号不稳定,
-
RE: 怎么在这个代码里添加一个线段数量值然后达到线段数量比如识别5条线段后输出到一个引脚作低电平信号输出
@kidswong999 在 怎么在这个代码里添加一个线段数量值然后达到线段数量比如识别5条线段后输出到一个引脚作低电平信号输出 中说:
result_segments = []
for l in segments:
if l.length() > 50:
result_segments.append(l)这段代码放上去过滤不了 短的线 没效果
-
RE: 怎么在这个代码里添加一个线段数量值然后达到线段数量比如识别5条线段后输出到一个引脚作低电平信号输出
@kidswong999 你好!在吗?怎么过滤掉那个比较短的线。或者说只识别边缘的线段就可以。可以这样设置吗
-
RE: 怎么在这个代码里添加一个线段数量值然后达到线段数量比如识别5条线段后输出到一个引脚作低电平信号输出
@kidswong999 哦 放进去了 就是还有很多出现很短的线 要怎么屏蔽过滤
-
RE: 怎么在这个代码里添加一个线段数量值然后达到线段数量比如识别5条线段后输出到一个引脚作低电平信号输出
@kidswong999 非常感谢!要怎么插入到那段代码上呢,刚贴进去,报错