青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

Detect red circles in an image using OpenCV

https://solarianprogrammer.com/2015/05/08/detect-red-circles-image-using-opencv/

The code for this post is on GitHub: https://github.com/sol-prog/OpenCV-red-circle-detection.

A few days ago someone asked me, in an email, if it is possible to detect all red circles in an image that contains circles and rectangles of various colors. I thought this problem could be of certain interest to the readers of this blog, hence the present article.

From the many possible approaches to the problem of red circles detection, two seem straightforward:

  • Detect all circles from the input image and keep only the ones that are filled with red.
  • Threshold the input image in order to keep only the red pixels, search for circles in the result.

I found the second approach to be slightly better than the first one (less false positives), so I am going to present it in this post.

I will use the OpenCV library and C++, but you can easily follow along with any of the other OpenCV bindings (C, Python, Java).

Lets start by thresholding the input image for anything that is not red. Instead of the usual RGB color space we are going to use the HSV space, which has the desirable property that allows us to identify a particular color using a single value, the hue, instead of three values. As a side note, in OpenCV H has values from 0 to 180, S and V from 0 to 255. The red color, in OpenCV, has the hue values approximately in the range of 0 to 10 and 160 to 180.

Next piece of code converts a color image from BGR (internally, OpenCV stores a color image in the BGR format rather than RGB) to HSV and thresholds the HSV image for anything that is not red:

 1 	...  2 	// Convert input image to HSV  3 	cv::Mat hsv_image;  4 	cv::cvtColor(bgr_image, hsv_image, cv::COLOR_BGR2HSV);  5   6 	// Threshold the HSV image, keep only the red pixels  7 	cv::Mat lower_red_hue_range;  8 	cv::Mat upper_red_hue_range;  9 	cv::inRange(hsv_image, cv::Scalar(0, 100, 100), cv::Scalar(10, 255, 255), lower_red_hue_range); 10 	cv::inRange(hsv_image, cv::Scalar(160, 100, 100), cv::Scalar(179, 255, 255), upper_red_hue_range); 11 	... 

Take the next input image as an example:

Five colored circles

if we use the above piece of code, this is what we get:

Lower red hue range

Upper red hue range

As you can see, the first threshold image captured the big red circle from the input image, while the second threshold image has captured the smaller red circle. Typically, you won’t see such a clear separation between the two red ranges. I’ve slightly cheated when I filled the circles in GIMP and used hue values from both intervals, in order to show you that a similar situation can arrive in practice.

Next step is to combine the above threshold images and slightly blur the result, in order to avoid false positives:

1 	... 2 	// Combine the above two images 3 	cv::Mat red_hue_image; 4 	cv::addWeighted(lower_red_hue_range, 1.0, upper_red_hue_range, 1.0, 0.0, red_hue_image); 5  6 	cv::GaussianBlur(red_hue_image, red_hue_image, cv::Size(9, 9), 2, 2); 7 	... 

Combined red hue range

Once we have the threshold image that contains only the red pixels from the original image, we can use the circle Hough Transform to detect the circles. In OpenCV this is implemented as HoughCircles:

1 	... 2 	// Use the Hough transform to detect circles in the combined threshold image 3 	std::vector<cv::Vec3f> circles; 4 	cv::HoughCircles(red_hue_image, circles, CV_HOUGH_GRADIENT, 1, red_hue_image.rows/8, 100, 20, 0, 0); 5 	... 

As a side note, parameters 6 and 7 from the HoughCircles must be usually tuned from case to case in order to detect circles. All found circles are stored in the circles vector from the above piece of code, using this information we can outline the detected circles on the original image:

1 	// Loop over all detected circles and outline them on the original image 2 	if(circles.size() == 0) std::exit(-1); 3 	for(size_t current_circle = 0; current_circle < circles.size(); ++current_circle) { 4 		cv::Point center(std::round(circles[current_circle][0]), std::round(circles[current_circle][1])); 5 		int radius = std::round(circles[current_circle][2]); 6  7 		cv::circle(orig_image, center, radius, cv::Scalar(0, 255, 0), 5); 8 	} 

Outline of the detected circles

Lets try the code on a slightly more complex image:

Circles and rectangles input image

and the result:

Circles and rectangles detected red circles

Adding some noise to the same input image as above:

Circles and rectangles input image with noise

and the incredible result:

Circles and rectangles with noise detected red circles

Ouch! Apparently the noise from the input image fooled the Hough detector and now we have more circles than we’ve expected. A simple cure is to filter the input image before the BGR to HSV conversion, for this kind of noise usually a median filter works best:

1 	... 2 	cv::medianBlur(bgr_image, bgr_image, 3); 3  4 	// Convert input image to HSV 5 	cv::Mat hsv_image; 6 	cv::cvtColor(bgr_image, hsv_image, cv::COLOR_BGR2HSV); 7 	... 

and now the result is much improved:

Circles and rectangles with noise median filter detected red circles

posted on 2017-08-29 10:52 zmj 閱讀(650) 評論(0)  編輯 收藏 引用


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲人成精品久久久久| 亚洲一区二区四区| 女同性一区二区三区人了人一| 午夜一区二区三区不卡视频| 91久久夜色精品国产网站| 快射av在线播放一区| 亚洲国产精品久久久久秋霞蜜臀| 欧美大香线蕉线伊人久久国产精品| 老牛国产精品一区的观看方式| 1000部国产精品成人观看| 亚洲第一伊人| 欧美性视频网站| 久久成人一区| 免费观看久久久4p| 国产欧美日韩一区| 美女亚洲精品| 欧美久久99| 欧美一级免费视频| 老司机成人网| 亚洲视频欧洲视频| 欧美在线啊v| 亚洲美女福利视频网站| 亚洲一区日韩在线| 亚洲高清一区二| 亚洲午夜在线观看视频在线| 国产一区二区日韩| 亚洲综合三区| 久久免费高清| 亚洲一区bb| 快she精品国产999| 欧美在线91| 欧美激情a∨在线视频播放| 亚洲欧美日产图| 鲁大师成人一区二区三区 | 久久久久青草大香线综合精品| 亚洲精品一区二区三区在线观看| 在线视频日韩| 最新国产精品拍自在线播放| 亚洲一区中文| av成人激情| 美国三级日本三级久久99| 亚洲欧美国产高清| 欧美成人一区二区三区在线观看 | 欧美国产日韩二区| 欧美日韩亚洲高清| 久久久久欧美| 国产精品久久久久久av下载红粉| 免费看成人av| 国产日韩免费| 亚洲香蕉网站| 99这里只有久久精品视频| 久久精品国产91精品亚洲| 亚洲欧美日韩国产综合在线 | 美女啪啪无遮挡免费久久网站| 亚洲一区二区四区| 欧美区一区二| 亚洲高清在线观看| 一区二区在线观看av| 欧美影院精品一区| 欧美伊人久久久久久午夜久久久久 | 蜜桃久久av| 国产主播一区二区| 欧美一区2区视频在线观看| 亚洲综合国产| 国产精品wwwwww| 这里只有精品电影| 亚洲一区在线播放| 国产精品成人观看视频免费| aaa亚洲精品一二三区| 亚洲婷婷综合久久一本伊一区| 欧美好骚综合网| 亚洲人永久免费| 一本久道久久综合婷婷鲸鱼| 欧美日本中文| 一本色道久久综合一区 | 在线精品一区| 蜜臀av性久久久久蜜臀aⅴ四虎 | 亚洲已满18点击进入久久| 国产精品美女主播| 午夜亚洲影视| 奶水喷射视频一区| 亚洲精品极品| 欧美性做爰毛片| 亚洲欧美成人一区二区在线电影| 欧美在线999| 激情成人在线视频| 欧美sm视频| 一区二区三区导航| 久久精品一区蜜桃臀影院| 一区二区在线观看视频| 欧美波霸影院| 亚洲性线免费观看视频成熟| 久久狠狠一本精品综合网| 久久国内精品自在自线400部| 久久久一区二区三区| 亚洲激情成人在线| 欧美日韩一区二区三区四区五区| 在线一区免费观看| 免费观看日韩av| 在线视频免费在线观看一区二区| 国产酒店精品激情| 久久综合狠狠综合久久综青草| 亚洲美女免费视频| 久久国产天堂福利天堂| 亚洲精品一区在线观看| 国产精品一区在线观看你懂的| 久久免费国产精品1| 一区二区精品在线| 免费成人毛片| 午夜精品福利一区二区蜜股av| 激情小说亚洲一区| 国产精品久久久久久久9999| 久久久久国产精品麻豆ai换脸| 日韩一区二区高清| 蜜臀va亚洲va欧美va天堂| 亚洲线精品一区二区三区八戒| 伊人狠狠色j香婷婷综合| 国产精品久久久久免费a∨大胸 | 夜夜嗨av一区二区三区四季av| 久久亚裔精品欧美| 亚洲一区在线免费| 亚洲精品日韩激情在线电影| 国产自产v一区二区三区c| 欧美日本二区| 免费在线欧美黄色| 久久精品二区亚洲w码| 亚洲视频导航| 亚洲精品永久免费精品| 免费在线观看一区二区| 欧美中文在线视频| 亚洲欧美资源在线| 在线一区二区视频| 亚洲精品资源| 亚洲高清网站| 亚洲高清久久| 亚洲成人在线网| 国语精品一区| 国际精品欧美精品| 国产在线不卡精品| 国产一级久久| 国产日韩欧美在线视频观看| 国产精品老牛| 国产精品永久免费视频| 国产精品久久久久久久电影| 欧美日韩在线观看一区二区| 欧美裸体一区二区三区| 欧美日韩1区2区| 欧美日韩亚洲三区| 国产精品v欧美精品∨日韩| 欧美日韩和欧美的一区二区| 欧美视频一区在线观看| 欧美日韩综合不卡| 国产精品久久久久av免费| 国产精品亚洲不卡a| 国产精品网站在线| 国产综合激情| 1000部精品久久久久久久久| 亚洲二区在线| 日韩特黄影片| 午夜日本精品| 久久久综合精品| 欧美成人精品激情在线观看| 亚洲黄色一区二区三区| 亚洲精品一区二区在线| 亚洲一二三区精品| 欧美在线www| 欧美超级免费视 在线| 欧美日本韩国| 国产视频在线观看一区二区三区 | 国产精品爽爽ⅴa在线观看| 国产日韩欧美一区在线| 亚洲国产岛国毛片在线| 一本大道av伊人久久综合| 亚洲欧美日韩国产综合| 美脚丝袜一区二区三区在线观看| 亚洲国产日韩欧美在线动漫| 一区二区三区免费观看| 欧美一区二区啪啪| 欧美精品性视频| 国产毛片精品国产一区二区三区| 在线观看亚洲精品视频| 一区二区三区欧美在线观看| 久久久精品视频成人| 亚洲国产91精品在线观看| 亚洲一区二区三区影院| 久久久久亚洲综合| 国产精品国产福利国产秒拍 | 欧美日韩大片一区二区三区| 国产乱理伦片在线观看夜一区| 在线观看视频一区二区欧美日韩| 亚洲午夜小视频| 欧美电影美腿模特1979在线看| 在线亚洲欧美| 欧美国产日韩一区二区| 国产亚洲欧美一区在线观看| 99re66热这里只有精品3直播 | 亚洲人人精品| 久久久91精品国产| 中国成人在线视频| 欧美高清日韩|