交通標誌紅孔檢測法

2021-06-22 02:49:11 字數 3910 閱讀 4044

哈工大博士王剛毅**中提到紅孔檢測法,**描述其檢測效果很好,用opencv實現了一下可能是他描述的不夠詳細,也可能本人理解有偏差,實現方法不一致,導致我的檢測效果很一般。

// blue.cpp : 定義控制台應用程式的入口點。

////

#include "stdafx.h"

#include #include #include #include #include #include#include using namespace std;

using namespace cv;

#define pi 3.1415926

int _tmain(int argc, _tchar* argv)

/*cvnamedwindow("test");

imshow("test",img);

cvwaitkey(0);*/

//轉到hsv

mat hsv_base;

mat how_red;

cvtcolor(img, hsv_base, cv_bgr2hsv );

/*cvnamedwindow("hsv");

imshow("hsv",hsv_base);

cvwaitkey(0);*/

mat colorcut;

colorcut.create(img.rows,img.cols,cv_32f);

how_red.create(img.rows,img.cols,cv_32f);

//顏色分割

for(int x=0;x(x,y)[0];

h_src =h_src/255.0*360;

double s_src=hsv_base.at(x,y)[1];

s_src=s_src/255;

double v_src= hsv_base.at(x,y)[2];

if ( h_src>=300&&h_src<360)

else if (h_src>=0&&h_src<=60)

else

colorcut.at(x,y)=0;

if (h_src>330||(h_src<=30&&s_src>=0.2))

}} double *max_value ;

double *min_value ;

double maxval=0;

double minval =0;

max_value =&maxval;

min_value =&minval;

minmaxloc(how_red, min_value, max_value);

/*cvnamedwindow("how");

imshow("how",how_red);

cvwaitkey(0);*/

// //紅色位圖均值濾波//

//紅色程度圖濾波//

mat blueredimg ;

mat blueredhowred;

blueredimg.create(colorcut.rows,colorcut.cols,cv_32f);

blueredhowred.create(colorcut.rows,colorcut.cols,cv_32f);

colorcut/=255.;

blur(colorcut,blueredimg,size(7,7));

minmaxloc(blueredimg, min_value, max_value);

blur(how_red,blueredhowred,size(7,7));

//cvnamedwindow("blur");

//imshow("blur",blueredimg);

//cvwaitkey(0);

// //得到最終細化後要提取區域的影象

// //開閉運算//

dilate(refinedimg,refinedimg,cv::mat());

erode(refinedimg,refinedimg,cv::mat());

//dilate(refinedimg,refinedimg,cv::mat());

cvnamedwindow("bbbb");

imshow("bbbb",refinedimg);

cvwaitkey(0);

// //提取區域尋找紅孔//

vector> contours;

findcontours(refinedimg,

contours, // a vector of contours

cv_retr_external, // retrieve the external contours

//篩選區域,太大的太小的去除//

mat resultt(colorcut.rows,colorcut.cols,cv_8u,scalar(0));

int cmin= 100; // minimum contour length

int cmax= 1000; // maximum contour length

vector>::const_iterator itc= contours.begin();

while (itc!=contours.end())

//// draw contours on the original image//

//對篩選後的區域求外接多凸邊形//

vectorhull;

vector>::const_iterator itc1=contours.begin();

while (itc1!=contours.end())

line(resultt,*(hull.begin()),*(hull.end()-1),scalar(255),3);

++itc1;

} vector> contours2;

findcontours(resultt,

contours2, // a vector of contours

cv_retr_external, // retrieve the external contours

drawcontours(resultt,contours2, -1 , scalar(255),cv_filled); //填充區域。//

namedwindow("ddddd");

imshow("ddddd",resultt);

cvwaitkey(0);

minmaxloc(resultt, min_value, max_value);

cout<<"max:"<(x,y);

int ff = refin.at(x,y);

if (rr>ff)

else

}} erode(hole,hole,cv::mat());

namedwindow("dddd");

imshow("dddd",hole);

cvwaitkey(0);

return 0;

}

交通標誌的檢測與識別

正在投稿中,專案已開源在github article,author journal number pages year publisher 如果本文幫助了您,請您引用我們的 本科畢業設計的時候曾經做過交通標誌的檢測與識別,這個作為很好的影象處理與識別領域的入門project還是非常不錯的.交通場景圖...

交通標誌識別

交通標誌識別實際上包括交通標誌的檢測和識別兩個過程,檢測是在影象中尋找到感興趣目標並定位,識別是對感興趣目標進行分類。現在r cnn系列 yolo ssd能夠很好的將檢測和分類兩個過程融合到一起,並且在pascal voc等資料集上取得了很好的效果,但對像交通標誌這種小目標的檢測效果並不好。就交通標...

交通標誌識別 語句筆記

np.unique 該函式是去除陣列中的重複數字,並進行排序之後輸出。計算label個數時適用。from colletions import counter 求陣列中每個數字出現了幾次 from collections import counter a 1,4,2,3,2,3,4,2 b count...