Using OpenCV to detect traffic signs in different shapes real time
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?
python c++ ios opencv vision
|
show 2 more comments
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?
python c++ ios opencv vision
You noticed that there are various questions on stackoverflow covering that exact topic?
– Swordfish
Nov 13 '18 at 11:52
@Swordfish Yes, I have read this page stackoverflow.com/questions/32797073/…. Someone suggested that ellipse detection could be used, but I am not only detecting the circular sign. I also hope to detect the triangular or quadrilateral sign. Therefore, I hope to find some means that could make the findContours function become more accurate. Such that, I could try to analysis the contours and check the shape of the object. I would try to read more questions on stackoverflow and find the answer. Thank you.
– boboboboboboo
Nov 13 '18 at 12:41
Please, do not add "[solved]" to the question title. Please read the help on how to correctly handle this.
– Dan Mašek
Nov 13 '18 at 16:34
you could try to threshold for red and/or white colors to detect red traffic signs and blue color for blue signs.
– Micka
Nov 13 '18 at 19:57
you could try to use only inner contours, since there is a white area around the red sign
– Micka
Nov 13 '18 at 19:59
|
show 2 more comments
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?
python c++ ios opencv vision
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?
python c++ ios opencv vision
python c++ ios opencv vision
edited Nov 13 '18 at 16:35
Dan Mašek
9,03532647
9,03532647
asked Nov 13 '18 at 11:20
bobobobobobooboboboboboboo
164
164
You noticed that there are various questions on stackoverflow covering that exact topic?
– Swordfish
Nov 13 '18 at 11:52
@Swordfish Yes, I have read this page stackoverflow.com/questions/32797073/…. Someone suggested that ellipse detection could be used, but I am not only detecting the circular sign. I also hope to detect the triangular or quadrilateral sign. Therefore, I hope to find some means that could make the findContours function become more accurate. Such that, I could try to analysis the contours and check the shape of the object. I would try to read more questions on stackoverflow and find the answer. Thank you.
– boboboboboboo
Nov 13 '18 at 12:41
Please, do not add "[solved]" to the question title. Please read the help on how to correctly handle this.
– Dan Mašek
Nov 13 '18 at 16:34
you could try to threshold for red and/or white colors to detect red traffic signs and blue color for blue signs.
– Micka
Nov 13 '18 at 19:57
you could try to use only inner contours, since there is a white area around the red sign
– Micka
Nov 13 '18 at 19:59
|
show 2 more comments
You noticed that there are various questions on stackoverflow covering that exact topic?
– Swordfish
Nov 13 '18 at 11:52
@Swordfish Yes, I have read this page stackoverflow.com/questions/32797073/…. Someone suggested that ellipse detection could be used, but I am not only detecting the circular sign. I also hope to detect the triangular or quadrilateral sign. Therefore, I hope to find some means that could make the findContours function become more accurate. Such that, I could try to analysis the contours and check the shape of the object. I would try to read more questions on stackoverflow and find the answer. Thank you.
– boboboboboboo
Nov 13 '18 at 12:41
Please, do not add "[solved]" to the question title. Please read the help on how to correctly handle this.
– Dan Mašek
Nov 13 '18 at 16:34
you could try to threshold for red and/or white colors to detect red traffic signs and blue color for blue signs.
– Micka
Nov 13 '18 at 19:57
you could try to use only inner contours, since there is a white area around the red sign
– Micka
Nov 13 '18 at 19:59
You noticed that there are various questions on stackoverflow covering that exact topic?
– Swordfish
Nov 13 '18 at 11:52
You noticed that there are various questions on stackoverflow covering that exact topic?
– Swordfish
Nov 13 '18 at 11:52
@Swordfish Yes, I have read this page stackoverflow.com/questions/32797073/…. Someone suggested that ellipse detection could be used, but I am not only detecting the circular sign. I also hope to detect the triangular or quadrilateral sign. Therefore, I hope to find some means that could make the findContours function become more accurate. Such that, I could try to analysis the contours and check the shape of the object. I would try to read more questions on stackoverflow and find the answer. Thank you.
– boboboboboboo
Nov 13 '18 at 12:41
@Swordfish Yes, I have read this page stackoverflow.com/questions/32797073/…. Someone suggested that ellipse detection could be used, but I am not only detecting the circular sign. I also hope to detect the triangular or quadrilateral sign. Therefore, I hope to find some means that could make the findContours function become more accurate. Such that, I could try to analysis the contours and check the shape of the object. I would try to read more questions on stackoverflow and find the answer. Thank you.
– boboboboboboo
Nov 13 '18 at 12:41
Please, do not add "[solved]" to the question title. Please read the help on how to correctly handle this.
– Dan Mašek
Nov 13 '18 at 16:34
Please, do not add "[solved]" to the question title. Please read the help on how to correctly handle this.
– Dan Mašek
Nov 13 '18 at 16:34
you could try to threshold for red and/or white colors to detect red traffic signs and blue color for blue signs.
– Micka
Nov 13 '18 at 19:57
you could try to threshold for red and/or white colors to detect red traffic signs and blue color for blue signs.
– Micka
Nov 13 '18 at 19:57
you could try to use only inner contours, since there is a white area around the red sign
– Micka
Nov 13 '18 at 19:59
you could try to use only inner contours, since there is a white area around the red sign
– Micka
Nov 13 '18 at 19:59
|
show 2 more comments
1 Answer
1
active
oldest
votes
To detect the contours correctly, you need to first smooth the image.
Please check the link for reference.
Link: http://answers.opencv.org/question/164533/how-to-smooth-the-edges-of-a-low-quality-image/
I have tried different blur function in opencv before, but the contours are still not correct. Besides, I have also tried to increase the ksize of medianBlur(src, src_copy, ksize). The results becomes more accurate, but the run time is too slow. Since I am going to detect the sign in real time, so the run time should not be that slow : (
– boboboboboboo
Nov 13 '18 at 13:19
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53279905%2fusing-opencv-to-detect-traffic-signs-in-different-shapes-real-time%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
To detect the contours correctly, you need to first smooth the image.
Please check the link for reference.
Link: http://answers.opencv.org/question/164533/how-to-smooth-the-edges-of-a-low-quality-image/
I have tried different blur function in opencv before, but the contours are still not correct. Besides, I have also tried to increase the ksize of medianBlur(src, src_copy, ksize). The results becomes more accurate, but the run time is too slow. Since I am going to detect the sign in real time, so the run time should not be that slow : (
– boboboboboboo
Nov 13 '18 at 13:19
add a comment |
To detect the contours correctly, you need to first smooth the image.
Please check the link for reference.
Link: http://answers.opencv.org/question/164533/how-to-smooth-the-edges-of-a-low-quality-image/
I have tried different blur function in opencv before, but the contours are still not correct. Besides, I have also tried to increase the ksize of medianBlur(src, src_copy, ksize). The results becomes more accurate, but the run time is too slow. Since I am going to detect the sign in real time, so the run time should not be that slow : (
– boboboboboboo
Nov 13 '18 at 13:19
add a comment |
To detect the contours correctly, you need to first smooth the image.
Please check the link for reference.
Link: http://answers.opencv.org/question/164533/how-to-smooth-the-edges-of-a-low-quality-image/
To detect the contours correctly, you need to first smooth the image.
Please check the link for reference.
Link: http://answers.opencv.org/question/164533/how-to-smooth-the-edges-of-a-low-quality-image/
answered Nov 13 '18 at 12:57
SAIFSAIF
617
617
I have tried different blur function in opencv before, but the contours are still not correct. Besides, I have also tried to increase the ksize of medianBlur(src, src_copy, ksize). The results becomes more accurate, but the run time is too slow. Since I am going to detect the sign in real time, so the run time should not be that slow : (
– boboboboboboo
Nov 13 '18 at 13:19
add a comment |
I have tried different blur function in opencv before, but the contours are still not correct. Besides, I have also tried to increase the ksize of medianBlur(src, src_copy, ksize). The results becomes more accurate, but the run time is too slow. Since I am going to detect the sign in real time, so the run time should not be that slow : (
– boboboboboboo
Nov 13 '18 at 13:19
I have tried different blur function in opencv before, but the contours are still not correct. Besides, I have also tried to increase the ksize of medianBlur(src, src_copy, ksize). The results becomes more accurate, but the run time is too slow. Since I am going to detect the sign in real time, so the run time should not be that slow : (
– boboboboboboo
Nov 13 '18 at 13:19
I have tried different blur function in opencv before, but the contours are still not correct. Besides, I have also tried to increase the ksize of medianBlur(src, src_copy, ksize). The results becomes more accurate, but the run time is too slow. Since I am going to detect the sign in real time, so the run time should not be that slow : (
– boboboboboboo
Nov 13 '18 at 13:19
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53279905%2fusing-opencv-to-detect-traffic-signs-in-different-shapes-real-time%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You noticed that there are various questions on stackoverflow covering that exact topic?
– Swordfish
Nov 13 '18 at 11:52
@Swordfish Yes, I have read this page stackoverflow.com/questions/32797073/…. Someone suggested that ellipse detection could be used, but I am not only detecting the circular sign. I also hope to detect the triangular or quadrilateral sign. Therefore, I hope to find some means that could make the findContours function become more accurate. Such that, I could try to analysis the contours and check the shape of the object. I would try to read more questions on stackoverflow and find the answer. Thank you.
– boboboboboboo
Nov 13 '18 at 12:41
Please, do not add "[solved]" to the question title. Please read the help on how to correctly handle this.
– Dan Mašek
Nov 13 '18 at 16:34
you could try to threshold for red and/or white colors to detect red traffic signs and blue color for blue signs.
– Micka
Nov 13 '18 at 19:57
you could try to use only inner contours, since there is a white area around the red sign
– Micka
Nov 13 '18 at 19:59