基于OpenMV平台進行開發
運算流程:
1.圖像分割
2.圖像腐蝕
3.圖像膨脹
實驗結果:
圖像腐蝕結果:
圖像膨脹結果:
實驗代碼:
import pyb, sensor, image
sensor.reset()
sensor.set_framesize(sensor.QVGA)
#設定門檻值
grayscale_thres = (170, 255)
while(True):
sensor.set_pixformat(sensor.GRAYSCALE)
img = sensor.snapshot()
#先對圖像進行分割,二值化,将在門檻值内的區域變為白色,門檻值外區域變為黑色
img.binary([grayscale_thres])
#對圖像邊緣進行侵蝕,侵蝕函數erode(size, threshold=Auto),size為
#kernal的大小,去除邊緣相鄰處多餘的點。threshold用來設定去除相鄰點的個數,
#threshold數值越大,被侵蝕掉的邊緣點越多,邊緣旁邊白色雜點少;數值越小,
#被侵蝕掉的邊緣點越少,邊緣旁邊的白色雜點越多。
img.erode(2)
#對圖像邊緣進行膨脹,膨脹函數image.dilate(size, threshold=Auto),size為
#kernal的大小,使邊緣膨脹。threshold用來設定去除相鄰點的個數,threshold數值
#越大,邊緣越膨脹;
#數值越小,邊緣膨脹的小。
img.dilate(2)