I am trying to create an app that could detect the traffic signs from the camera. However, I meet some difficulties about detecting the sign.
Since the traffic signs might be different in color, so I hope to detect the shape of the sign first.
I have tried to find all the contours first and try to detect the shape of each contour. However, the contour of the sign is not clear enough and the tree background contains lots of small contours that would affect the detection. So that the program is not able to find the complete contour of the traffic sign. I know that using fastNlMeansDenoisingColored() from openCV could significantly remove the noise and make to detection become more accurate. But it is too slow for the real time processing.
I am not only checking the circular signs, but also the the triangular or quadrilateral sign. Therefore, I hope to find the contour of all objects first and try to check the shape of the object.
Here is the code I used to find the contours inside the picture, and it's result. I am going to develop an iOS app, so it is in objective-c.
- (cv::Mat)findSigns:(cv::Mat)src {
Mat edge;
Mat src_gray;
cvtColor(src, src_gray, COLOR_RGB2GRAY);
medianBlur(src_gray, src_gray, 5);
Canny(src_gray, edge, 80, 80, 3);
Mat kernel = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(3,3));
Mat dilated;
cv::dilate(edge, dilated, kernel);
std::vector<std::vector<cv::Point>> contours;
std::vector<cv::Vec4i> hierarchy;
RNG rng(12345);
cv::findContours(edge, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
Scalar color = Scalar(255, 0, 255);
for(int i = 0; i<contours.size(); i++){
std::vector<cv::Point> c = contours[i];
double area = cv::contourArea(c);
if (area > 100) {
drawContours(src, contours, i, color, 2, 8, hierarchy);
}
}
edge.release();
src_gray.release();
kernel.release();
dilated.release();
return src;
}
src picture:
Since there are too much contours, so I tried to remove the contours with small area. And here is the result.
Besides, I have also tried to check if hierarchy[i][2] == -1 to see if there is any closed contours. But all of them are equal to -1.
May I know how should I detect the shape of the traffic signs? Should I remove the tree background by removing the green object for easier detection?