系统迁移中,暂时无法访问,所有数据会迁移到新的网站。
OpenMV VSCode 扩展发布了,在插件市场直接搜索OpenMV就可以安装
如果有产品硬件故障问题,比如无法开机,论坛很难解决。可以直接找售后维修。
发帖子之前,请确认看过所有的视频教程,https://singtown.com/learn/ 和所有的上手教程http://book.openmv.cc/
每一个新的提问,单独发一个新帖子
帖子需要目的,你要做什么?
如果涉及代码,需要报错提示与全部代码文本,请注意不要贴代码图片
必看:玩转星瞳论坛了解一下图片上传,代码格式等问题。
二值化观察闪烁的LED,但像素不停取反,怎么办?
-
import pyb,sensor, image, time sensor.reset() sensor.set_framesize(sensor.QQVGA) sensor.set_pixformat(sensor.GRAYSCALE) sensor.set_auto_whitebal(False) low_threshold = (0, 80) high_threshold = (180, 255) # 灰度二值化 while(True): # 测试低阈值 for i in range(100): img = sensor.snapshot() img.binary([low_threshold]) #img.binary(thresholds, invert=False)此函数将在thresholds内的 #图像部分的全部像素变为1白,将在阈值外的部分全部像素变为0黑。invert将图像 #的0 1(黑 白)进行反转,默认为false不反转。 # 测试高阈值 for i in range(100): img = sensor.snapshot() img.binary([high_threshold]) #测试不是低阈值 for i in range(100): img = sensor.snapshot() img.binary([low_threshold], invert = 1) # Test not high threshold #测试不是高阈值 for i in range(100): img = sensor.snapshot() img.binary([high_threshold], invert = 1) #腐蚀膨胀 #设置阈值 grayscale_thres = (230, 255) rgb565_thres = (70, 100, -128, 127, -128, 127) while(True): sensor.set_pixformat(sensor.GRAYSCALE) for i in range(20): img = sensor.snapshot() img.binary([grayscale_thres]) img.dilate(2) #对图像边缘进行膨胀,膨胀函数image.dilate(size, threshold=Auto),size为 #kernal的大小,使边缘膨胀。threshold用来设置去除相邻点的个数,threshold数值 #越大,边缘越膨胀; #数值越小,边缘膨胀的小。 for i in range(20): img = sensor.snapshot() #先对图像进行分割,二值化,将在阈值内的区域变为白色,阈值外区域变为黑色 img.binary([grayscale_thres]) #对图像边缘进行侵蚀,侵蚀函数erode(size, threshold=Auto),size为 #kernal的大小,去除边缘相邻处多余的点。threshold用来设置去除相邻点的个数, #threshold数值越大,被侵蚀掉的边缘点越多,边缘旁边白色杂点少;数值越小, #被侵蚀掉的边缘点越少,边缘旁边的白色杂点越多。 img.erode(2) sensor.set_pixformat(sensor.RGB565) for i in range(20): img = sensor.snapshot() img.binary([rgb565_thres]) img.erode(30) for i in range(20): img = sensor.snapshot() img.binary([rgb565_thres]) img.dilate(2) sensor.skip_frames(time = 2000) clock = time.clock() while(True): clock.tick() img = sensor.snapshot().lens_corr(strength = 1.8, zoom = 1.0) print(clock.fps())
-
你sensor.snapshot出来的图片是什么?
-
@kidswong999 这是自己截的图,主要原因是黑色和白色反复颠倒,焦距也在一直变,是哪里的问题
-
因为你程序有问题,你在第一个死循环里,invert = 1就是取反了。