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

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>
            久久亚洲视频| 欧美二区在线| 久久国产毛片| 国产一区日韩欧美| 国产人成精品一区二区三| 亚洲性xxxx| 亚洲欧美在线播放| 激情五月***国产精品| 麻豆国产精品va在线观看不卡| 久久精品国产一区二区电影| 亚洲大片免费看| 亚洲精品一区二区三区婷婷月 | 久久免费黄色| 亚洲激情二区| 一区二区三区视频在线播放| 国产精品亚洲产品| 免费欧美在线视频| 欧美日韩久久精品| 久久av一区二区三区| 久久一区亚洲| 亚洲欧美日韩国产一区二区三区 | 亚洲第一精品福利| 欧美午夜不卡在线观看免费| 欧美一区二区三区婷婷月色| 久久阴道视频| 亚洲欧美日本国产有色| 久久精品一区蜜桃臀影院| 亚洲人成在线播放| 午夜精品999| 一本色道久久88综合亚洲精品ⅰ | 另类av一区二区| 亚洲中无吗在线| 乱码第一页成人| 午夜精品久久久久久99热软件| 久久噜噜亚洲综合| 亚洲欧美日本在线| 欧美精品一区二区三区蜜桃| 久久爱www| 欧美午夜不卡| 亚洲国产精品久久久久婷婷老年 | 性视频1819p久久| 欧美二区乱c少妇| 久久久久久亚洲精品中文字幕| 欧美精品999| 女同一区二区| 国产一区二区在线免费观看| 99精品国产福利在线观看免费| 亚洲国产高清在线观看视频| 亚洲欧美日韩国产另类专区| 中文在线资源观看网站视频免费不卡| 久久精选视频| 久久久精品视频成人| 国产精品久久久久久亚洲毛片| 亚洲国产精品小视频| 精品粉嫩aⅴ一区二区三区四区| 亚洲一区精品电影| 亚洲一级特黄| 欧美午夜国产| 一本大道久久a久久精二百| 亚洲精品乱码久久久久| 久久性天堂网| 欧美国产第一页| 亚洲国产二区| 美女图片一区二区| 欧美黄色片免费观看| 亚洲第一区在线| 久久综合给合久久狠狠狠97色69| 久久先锋影音| 在线欧美日韩国产| 免费欧美在线| 亚洲激情影视| 亚洲五月婷婷| 国产精品综合| 久久www成人_看片免费不卡| 久久久久久久久久久久久久一区| 国产欧美日韩另类一区| 欧美一级精品大片| 你懂的成人av| 亚洲乱码国产乱码精品精天堂| 欧美精品观看| 亚洲特级毛片| 久久影院午夜论| 亚洲精选在线观看| 欧美香蕉大胸在线视频观看| 亚洲综合另类| 免费成人黄色av| 日韩一级大片在线| 国产精品一区亚洲| 久久久免费精品视频| 亚洲欧洲一区二区天堂久久| 亚洲一区在线视频| 韩日欧美一区二区三区| 欧美大胆成人| 亚洲尤物精选| 欧美电影在线观看完整版| 一区二区高清在线观看| 国产精品人成在线观看免费| 久久精品日韩欧美| 亚洲精品午夜| 久久一区亚洲| 亚洲一区二区视频| 精品电影在线观看| 国产精品vvv| 久久视频在线视频| 一本色道久久综合亚洲精品高清| 久久天天躁夜夜躁狠狠躁2022| 亚洲美女网站| 激情成人综合网| 国产精品久久| 欧美大胆a视频| 久久国产精品99国产精| 99re6这里只有精品视频在线观看| 久久精品99| 亚洲丝袜av一区| 亚洲电影av| 国产一区二区三区日韩| 欧美三级欧美一级| 欧美成黄导航| 久久精品噜噜噜成人av农村| 亚洲神马久久| 亚洲欧洲精品一区二区三区波多野1战4| 欧美一级播放| 亚洲一区二区在线观看视频| 亚洲高清在线播放| 国产一区二区精品| 国产精品久久久久久久久久久久 | 久久久一区二区三区| 亚洲一区久久久| 日韩一级网站| 亚洲国产精品一区二区www在线| 久久久999精品| 欧美一区二区黄| 亚洲综合第一页| 亚洲一二三四久久| 一区二区三区免费在线观看| 亚洲国产天堂久久国产91| 在线播放亚洲一区| 黄色在线一区| 玉米视频成人免费看| 精品av久久707| 激情久久综合| 在线播放日韩| 亚洲福利视频专区| 在线精品视频在线观看高清| 韩日成人在线| 在线看视频不卡| 亚洲国产精品女人久久久| 在线视频成人| 亚洲精品一区久久久久久| 亚洲日本中文字幕区| 亚洲精品国产精品国自产在线 | 久久久一本精品99久久精品66| 欧美在线看片| 久久手机免费观看| 免费久久精品视频| 亚洲国产精品va在线观看黑人| 欧美激情一区二区三区高清视频| 欧美黄色免费网站| 日韩视频一区二区| 中文国产成人精品| 欧美一级淫片aaaaaaa视频| 欧美一区二区三区视频在线| 久久久国产午夜精品| 久热国产精品视频| 欧美片第一页| 国产精品自拍小视频| 精久久久久久| 日韩午夜av电影| 亚洲欧美电影在线观看| 久久久久国色av免费观看性色| 欧美.www| 99综合视频| 久久国产日本精品| 欧美精品手机在线| 国产欧美一区二区三区在线老狼| 一区精品在线| 在线视频亚洲一区| 久久久xxx| 最近中文字幕日韩精品| 亚洲免费人成在线视频观看| 久久嫩草精品久久久久| 欧美日韩高清一区| 狠狠爱综合网| 亚洲婷婷在线| 欧美二区在线看| 亚洲男女自偷自拍| 欧美精品亚洲二区| 精品av久久707| 亚洲影院在线| 亚洲国产二区| 久久精品国产一区二区电影| 欧美日韩三区四区| 亚洲国产成人久久综合| 亚洲欧美在线另类| 亚洲欧洲精品一区二区三区波多野1战4 | 欧美电影在线观看| 午夜久久久久久久久久一区二区| 欧美成ee人免费视频| 狠狠久久亚洲欧美| 午夜免费电影一区在线观看|