日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

輪廓尋找算法(contour find)

 印度阿三17 2019-07-12

輪廓尋找算法建立在斑(blob)尋找基礎(chǔ)之上,這個(gè)算法有參考楊淑瑩的圖像處理,有兩個(gè)版本,第一版本c#代碼如下:

?private void SingleTrack(ref byte[] image, int w, int h, ref List<Point> list, int i, int j, uint threshold)
? ? ? ? {
? ? ? ? ? ? CPointNode1[] direct = new CPointNode1[8];
? ? ? ? ? ? direct[0].x = 1; direct[0].y = 0;
? ? ? ? ? ? direct[1].x = 1; direct[1].y = -1;
? ? ? ? ? ? direct[2].x = 0; direct[2].y = -1;
? ? ? ? ? ? direct[3].x = -1; direct[3].y = -1;
? ? ? ? ? ? direct[4].x = -1; direct[4].y = 0;
? ? ? ? ? ? direct[5].x = -1; direct[5].y = 1;
? ? ? ? ? ? direct[6].x = 0; direct[6].y = 1;
? ? ? ? ? ? direct[7].x = 1; direct[7].y = 1;
? ? ? ? ? ? Point temppt = new Point();
? ? ? ? ? ? int nx = i, ny = j; int indexindex = 0;
? ? ? ? ? ? temppt.X = nx;
? ? ? ? ? ? temppt.Y = ny;
? ? ? ? ? ? list.Add(temppt);
? ? ? ? ? ? do
? ? ? ? ? ? {
? ? ? ? ? ? ? ? indexindex = NextcontourPoint(ref image, w, h, nx, ny, indexindex, ref list, threshold);
? ? ? ? ? ? ? ? if (indexindex == 9) break;
? ? ? ? ? ? ? ? nx = direct[indexindex].x;
? ? ? ? ? ? ? ? ny = direct[indexindex].y;
? ? ? ? ? ? }
? ? ? ? ? ? while (nx != i || ny != j);
? ? ? ? }

? ? ?private int NextcontourPoint(ref byte[] image, int w, int h, int i, int j, int entrelinkcode, ref List<Point> list, uint threshold)
? ? ? ? {
? ? ? ? ? ? ?CPointNode1[] direct = new CPointNode1[8];
? ? ? ? ? ? direct[0].x = 1; direct[0].y = 0;
? ? ? ? ? ? direct[1].x = 1; direct[1].y = -1;
? ? ? ? ? ? direct[2].x =0; direct[2].y = -1;
? ? ? ? ? ? direct[3].x = -1; direct[3].y = -1;
? ? ? ? ? ? direct[4].x = -1; direct[4].y = 0;
? ? ? ? ? ? direct[5].x = -1; direct[5].y = 1;
? ? ? ? ? ? direct[6].x = 0; direct[6].y = 1;
? ? ? ? ? ? direct[7].x = 1; direct[7].y = 1;
? ? ? ? ? ? int startindex = entrelinkcode 3 8;
? ? ? ? ? // ?int i = 0;
? ? ? ? ? ? for (int ii = 0; ii <= 7; ii )
? ? ? ? ? ? {
? ? ? ? ? ? ? ? int indexindex = (startindex - ii) % 8;
? ? ? ? ? ? ? ? int nx = i direct[indexindex].x;
? ? ? ? ? ? ? ? int ny = j direct[indexindex].y;
? ? ? ? ? ? ? ? if (image[nx * w ny] == threshold)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? Point temppt = new Point();
? ? ? ? ? ? ? ? ? ? temppt.X = nx;
? ? ? ? ? ? ? ? ? ? temppt.Y = ny;
? ? ? ? ? ? ? ? ? ? list.Add(temppt);
? ? ? ? ? ? ? ? ? ? return indexindex;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? return 9;
? ? ? ? }

第二版本c#代碼如下:

? ? private void FindContinueFigure2(ref byte[] image, int w, int h, ref List<Point> list, int i, int j, uint threshold)//threshold //default=255
? ? ? ? {
? ? ? ? ? ? Point startpoint = new Point();
? ? ? ? ? ? Point currentpoint = new Point();
? ? ? ? ? ? CPointNode1[] direct = new CPointNode1[8];
? ? ? ? ? ? direct[0].x = -1; direct[0].y = 1;
? ? ? ? ? ? direct[1].x = -1; direct[1].y = 0;
? ? ? ? ? ? direct[2].x = -1; direct[2].y = -1;
? ? ? ? ? ? direct[3].x = 0; direct[3].y = -1;
? ? ? ? ? ? direct[4].x = 1; direct[4].y = -1;
? ? ? ? ? ? direct[5].x = 1; direct[5].y = 0;
? ? ? ? ? ? direct[6].x = 1; direct[6].y = 1;
? ? ? ? ? ? direct[7].x = 0; direct[7].y = 1;
? ??
? ? ? ? ? ? int startdirect = 3; ? ? ??
? ? ? ? ? ? bool findstartpoint = false;

? ? ? ? ? ? Point temppt = new Point();

? ? ? ? ? ? temppt.X = startpoint.X = i;
? ? ? ? ? ? temppt.Y = startpoint.Y = j;
? ? ? ? ? ? list.Add(temppt);

? ? ? ? ? ? currentpoint.X = startpoint.X;
? ? ? ? ? ? currentpoint.Y = startpoint.Y;

? ? ? ? ? ? while (!findstartpoint)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? bool findpoint = false;
? ? ? ? ? ? ? ? while (!findpoint)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? int ay = (currentpoint.Y direct[startdirect].y);
? ? ? ? ? ? ? ? ? ? int ax=currentpoint.X direct[startdirect].x;
? ? ? ? ? ? ? ? ? // ?if(ax>0&&ax<w&&ay>0&&ay<h)
? ? ? ? ? ? ? ? ? ? if (image[ay * w ax] == threshold)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? findpoint = true;
? ? ? ? ? ? ? ? ? ? ? ? // ?image[(currentpoint.Y direct[startdirect].y) * w currentpoint.X direct[startdirect].x] = 0;
? ? ? ? ? ? ? ? ? ? ? ? temppt.X = currentpoint.X = currentpoint.X direct[startdirect].x;
? ? ? ? ? ? ? ? ? ? ? ? temppt.Y = currentpoint.Y = currentpoint.Y direct[startdirect].y;
? ? ? ? ? ? ? ? ? ? ? ? list.Add(temppt);

? ? ? ? ? ? ? ? ? ? ? ? if (currentpoint.X == startpoint.X &&
? ? ? ? ? ? ? ? ? ? ? ? ? ? currentpoint.Y == startpoint.Y)
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? findstartpoint = true;

? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? startdirect--;
? ? ? ? ? ? ? ? ? ? ? ? if (startdirect == -1)
? ? ? ? ? ? ? ? ? ? ? ? ? ? startdirect = 7;
? ? ? ? ? ? ? ? ? ? ? ? startdirect--;
? ? ? ? ? ? ? ? ? ? ? ? if (startdirect == -1)
? ? ? ? ? ? ? ? ? ? ? ? ? ? startdirect = 7;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? startdirect ;
? ? ? ? ? ? ? ? ? ? ? ? if (startdirect == 8)
? ? ? ? ? ? ? ? ? ? ? ? ? ? startdirect = 0;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }

? public struct CPointNode1
? ? {
? ? ? ? public int x;
? ? ? ? public int y;

? ? };

考慮為什么會(huì)使用第二版本?答案是,第一版本極少數(shù)的結(jié)果讓人驚詫,明明有輪廓,卻只找到一個(gè)小圈圈,用了一兩年才發(fā)現(xiàn),不知道是什么原因,后來又參考左飛的數(shù)字圖像處理,才發(fā)現(xiàn)是進(jìn)入鏈碼的值不對(duì)導(dǎo)致的。

關(guān)于斑和輪廓不想再立篇探討匹配的應(yīng)用了,因?yàn)樵谶@兩篇中,斑和輪廓已經(jīng)為你提供了用來匹配的足夠多的信息特征,關(guān)于質(zhì)心,周長(zhǎng),面積,最遠(yuǎn)矩,最短矩,凸多邊形,外接圓,外接矩形,外接橢圓,以及Hu不變矩的計(jì)算......等等,根據(jù)個(gè)人愛好和具體項(xiàng)目實(shí)踐應(yīng)用,任意想象,任意發(fā)揮。輪廓與斑,一對(duì)孿生姊妹,相輔相成,機(jī)器視覺處理基礎(chǔ)必備。

待續(xù)(慢慢來!...........)每天一點(diǎn)小改變?

來源:https://www./content-1-321251.html

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多