{"id":332957,"date":"2022-05-10T15:00:28","date_gmt":"2022-05-10T15:00:28","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=332957"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=332957","title":{"rendered":"<span>\u0423\u0440\u043e\u043a\u0438 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043d\u043e\u0433\u043e \u0437\u0440\u0435\u043d\u0438\u044f \u043d\u0430 Python + OpenCV \u0441 \u0441\u0430\u043c\u044b\u0445 \u0430\u0437\u043e\u0432. \u0427\u0430\u0441\u0442\u044c 6<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041d\u0430 <a href=\"https:\/\/habr.com\/ru\/post\/661663\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u043e\u0448\u043b\u043e\u043c \u0443\u0440\u043e\u043a\u0435<\/a> \u043c\u044b \u043d\u0430\u0443\u0447\u0438\u043b\u0438\u0441\u044c \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043d\u0430\u0431\u043e\u0440 \u043e\u0441\u043e\u0431\u044b\u0445 \u0442\u043e\u0447\u0435\u043a, \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0445 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u043c \u0434\u0435\u0442\u0435\u043a\u0442\u043e\u0440\u043e\u043c \u043e\u0441\u043e\u0431\u044b\u0445 \u0442\u043e\u0447\u0435\u043a, \u0432 \u0433\u0440\u0430\u0444. \u0422\u0430\u043c \u0436\u0435 \u044f \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u043b, \u0437\u0430\u0447\u0435\u043c \u044d\u0442\u043e \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0430\u0434\u043e. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0437\u0443\u0447\u0430\u0442\u044c \u0442\u0430\u043a\u0443\u044e \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u043d\u0430\u0443\u043a\u0438 \u043e \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043d\u043e\u043c \u0437\u0440\u0435\u043d\u0438\u0438, \u043a\u0430\u043a \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u043e\u0431\u043b\u0430\u0441\u0442\u0435\u0439 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0430 \u043d\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0438. \u041a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u044d\u0442\u043e \u0432\u0442\u043e\u0440\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u044d\u0442\u0430\u043f\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 (\u0441\u043c. <a href=\"https:\/\/habr.com\/ru\/post\/540166\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0435\u0440\u0432\u044b\u0439 \u0443\u0440\u043e\u043a<\/a>). \u0418 \u0442\u0430\u043a, \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u043d\u0430\u0439\u0442\u0438 \u043d\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0438 \u0434\u043e\u0440\u043e\u0436\u043d\u044b\u0439 \u0437\u043d\u0430\u043a. \u041f\u0443\u0441\u0442\u044c \u043c\u044b \u043f\u043e\u043a\u0430 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u043c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0438\u0441\u043a\u043e\u043c \u0437\u043d\u0430\u043a\u043e\u0432 \u00ab\u043a\u0438\u0440\u043f\u0438\u0447\u00bb. \u0412\u043e\u0442 \u043d\u0430\u0448\u0430 \u0440\u0430\u0431\u043e\u0447\u0430\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/13a\/8bb\/bb5\/13a8bbbb52f60bad2637a2fb6fd3c725.png\" width=\"592\" height=\"393\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/13a\/8bb\/bb5\/13a8bbbb52f60bad2637a2fb6fd3c725.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041a\u0430\u043a \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0443\u0437\u0438\u0442\u044c \u043c\u0435\u0441\u0442\u043e \u043f\u043e\u0438\u0441\u043a\u0430, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0439\u0442\u0438 \u0437\u043d\u0430\u043a \u00ab\u043a\u0438\u0440\u043f\u0438\u0447\u00bb. \u0411\u0440\u043e\u0441\u0430\u0435\u0442\u0441\u044f \u0432 \u0433\u043b\u0430\u0437\u0430, \u0447\u0442\u043e \u043e\u043d \u044f\u0440\u043a\u043e \u043a\u0440\u0430\u0441\u043d\u044b\u0439. \u041c\u043e\u0436\u0435\u0442, \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u0440\u0430\u0441\u043d\u044b\u0439 \u043a\u0430\u043d\u0430\u043b (\u043d\u0438\u0436\u0435 \u0432\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435, \u043f\u043e\u0447\u0435\u043c\u0443 \u0442\u0430\u043a \u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435 \u043d\u0430\u0434\u043e):<\/p>\n<pre><code class=\"python\">import cv2 my_photo = cv2.imread('bricks\\\\dsc_0263.jpg') red_channel = my_photo[:,:,2] cv2.imshow('MyPhoto', red_channel) cv2.waitKey(0)  cv2.destroyAllWindows()<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0442\u0430\u043a\u0443\u044e \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/452\/783\/cf3\/452783cf3eb4e1d8f78b00bb968b5e37.png\" width=\"663\" height=\"454\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/452\/783\/cf3\/452783cf3eb4e1d8f78b00bb968b5e37.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0427\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u043c \u0434\u0430\u043b\u044c\u0448\u0435? \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043f\u043e\u0440\u043e\u0433:<\/p>\n<pre><code class=\"python\">import cv2 import numpy as np my_photo = cv2.imread('bricks\\\\dsc_0263.jpg') red_channel = my_photo[:,:,2] bin_img = np.zeros(my_photo.shape) bin_img[red_channel > 200] = [0, 0, 255] cv2.imshow('MyPhoto', bin_img) cv2.waitKey(0)  cv2.destroyAllWindows()<\/code><\/pre>\n<p>\u0418 \u0447\u0442\u043e \u0436\u0435 \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c? \u0410 \u0432\u043e\u0442 \u0447\u0442\u043e:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/8cb\/014\/f55\/8cb014f55d76ce55c68254bc3c61d771.png\" width=\"657\" height=\"451\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8cb\/014\/f55\/8cb014f55d76ce55c68254bc3c61d771.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u0443\u0440\u0430, \u043c\u044b \u043d\u0430\u0448\u043b\u0438 \u0437\u043d\u0430\u043a. \u041a\u0430\u043a \u043b\u043e\u043a\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043a\u043e\u043f\u043b\u0435\u043d\u0438\u0435 \u044f\u0440\u043a\u0438\u0445 \u0442\u043e\u0447\u0435\u043a, \u0434\u0440\u0443\u0433\u043e\u0439 \u0432\u043e\u043f\u0440\u043e\u0441. \u0422\u0443\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432 \u0434\u0440\u0443\u0433\u043e\u043c. \u0421\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043b\u0438 \u043d\u0430\u0448 \u043c\u0435\u0442\u043e\u0434 \u0442\u0430\u043a \u0436\u0435 \u0445\u043e\u0440\u043e\u0448\u043e \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043e\u0442 \u043d\u0430 \u0442\u0430\u043a\u043e\u0439:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/cc2\/a6a\/679\/cc2a6a679de23ddb153a686bcde33671.png\" width=\"642\" height=\"483\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cc2\/a6a\/679\/cc2a6a679de23ddb153a686bcde33671.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u0442\u0443 \u0436\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u0441 \u0442\u0435\u043c \u0436\u0435 \u044d\u043c\u043f\u0438\u0440\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u043c \u043f\u043e\u0440\u043e\u0433\u043e\u043c:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/843\/8b4\/811\/8438b4811b04315cb74d1029514ea93b.png\" width=\"653\" height=\"265\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/843\/8b4\/811\/8438b4811b04315cb74d1029514ea93b.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412\u043e\u0442 \u044d\u0442\u043e \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u0430, \u0434\u0430? \u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0441\u0440\u0435\u0430\u0433\u0438\u0440\u043e\u0432\u0430\u043b\u0430 \u043d\u0430 \u0448\u0443\u043c, \u043d\u043e \u043d\u0435 \u00ab\u0443\u0432\u0438\u0434\u0435\u043b\u0430\u00bb \u0437\u043d\u0430\u043a. <\/p>\n<p>\u0410 \u0435\u0441\u043b\u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0444\u043e\u0440\u043c\u0430\u0442 HSV \u0438 \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u0438\u043c\u0435\u043d\u043d\u043e \u043a\u0440\u0430\u0441\u043d\u044b\u0439 \u0446\u0432\u0435\u0442? \u041d\u0430\u043f\u043e\u043c\u043d\u044e, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 \u044d\u0442\u043e\u0442 \u0444\u043e\u0440\u043c\u0430\u0442. \u041a\u0430\u043d\u0430\u043b H \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0446\u0432\u0435\u0442. \u0412 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0447\u0438\u0441\u043b\u0430 \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043e\u0442\u0442\u0435\u043d\u043e\u043a. \u041a\u0430\u043d\u0430\u043b S \u2013 \u043d\u0430\u0441\u044b\u0449\u0435\u043d\u043d\u043e\u0441\u0442\u044c, \u043f\u0440\u0438 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0438 \u044d\u0442\u043e \u0431\u0435\u043b\u044b\u0439 \u0446\u0432\u0435\u0442, \u043f\u0440\u0438 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u043c \u2013 \u0446\u0432\u0435\u0442, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e \u043a\u0430\u043d\u0430\u043b\u0430 H. \u041a\u0430\u043d\u0430\u043b V \u2013 \u044d\u0442\u043e \u044f\u0440\u043a\u043e\u0441\u0442\u044c. \u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u2013 \u0447\u0435\u0440\u043d\u044b\u0439, \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u2013 \u0446\u0432\u0435\u0442, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 H \u0438 S.<\/p>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u0430\u043d\u0430\u043b H:<\/p>\n<pre><code class=\"python\">import cv2 import numpy as np my_photo = cv2.imread('bricks\\\\White1.jpg') img = cv2.cvtColor(my_photo, cv2.COLOR_BGR2HSV) h_channel = my_photo[:,:,0] bin_img = np.zeros(my_photo.shape) bin_img[(h_channel &lt; 40) * (h_channel > 20)] = [0, 0, 255] cv2.imshow('h_channel', h_channel) cv2.imshow('result', bin_img) cv2.waitKey(0)  cv2.destroyAllWindows()<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e6d\/9e7\/f3b\/e6d9e7f3b192207e2392861284b1412f.png\" width=\"693\" height=\"279\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e6d\/9e7\/f3b\/e6d9e7f3b192207e2392861284b1412f.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0423 \u043d\u0430\u0441 \u043f\u043e\u043f\u0430\u043b\u0438 \u0432 \u043d\u0430\u0448 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d \u0447\u0435\u0440\u043d\u044b\u0435 \u0441\u0442\u0432\u043e\u043b\u044b \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432, \u0432\u0438\u0434\u0438\u043c\u043e, \u043e\u043d\u0438 \u0438\u043c\u0435\u044e\u0442 \u0447\u0443\u0442\u044c \u0437\u0430\u043c\u0435\u0442\u043d\u044b\u0439 \u043a\u0440\u0430\u0441\u043d\u043e\u0432\u0430\u0442\u044b\u0439 \u043e\u0442\u0442\u0435\u043d\u043e\u043a. \u041c\u043e\u0436\u043d\u043e \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u043e \u044f\u0440\u043a\u043e\u0441\u0442\u0438:<\/p>\n<pre><code class=\"python\">import cv2 import numpy as np #my_photo = cv2.imread('bricks\\\\dsc_0263.jpg') my_photo = cv2.imread('bricks\\\\White1.jpg') #my_photo = cv2.imread('bricks\\\\videlenka(24).jpg') img = cv2.cvtColor(my_photo, cv2.COLOR_BGR2HSV) h_channel = my_photo[:,:,0] v_channel = my_photo[:,:,2] bin_img = np.zeros(my_photo.shape) bin_img[(h_channel &lt; 70) * (h_channel > 20) * (v_channel>100)] = [0, 0, 255] cv2.imshow('v_channel', v_channel) cv2.imshow('result', bin_img) cv2.waitKey(0)  cv2.destroyAllWindows()<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/34b\/d73\/83a\/34bd7383aaed1885c64a8ec876c19831.png\" width=\"608\" height=\"486\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/34b\/d73\/83a\/34bd7383aaed1885c64a8ec876c19831.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0435\u043f\u043b\u043e\u0445\u043e. \u00ab\u0414\u044b\u0440\u044b\u00bb \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0435\u043b\u0430\u0442\u044c \u043c\u043e\u0440\u0444\u043e\u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u043c\u0438 (\u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0435):<\/p>\n<pre><code class=\"python\">kernel = np.ones((5,5),np.uint8) closing = cv2.morphologyEx(bin_img, cv2.MORPH_CLOSE, kernel)<\/code><\/pre>\n<p>\u0418 \u0432\u043e\u0442 \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0432 \u0438\u0442\u043e\u0433\u0435:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e69\/731\/aba\/e69731aba32f1fed7eb774e409039a70.png\" width=\"603\" height=\"484\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e69\/731\/aba\/e69731aba32f1fed7eb774e409039a70.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0423 \u043d\u0430\u0441 \u043e\u0441\u0442\u0430\u043b\u0441\u044f \u0448\u0443\u043c. \u0422\u043e\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u0431\u0440\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u043c\u043e\u0440\u0444\u043e\u043b\u043e\u0433\u0438\u0438, \u043d\u0430 \u044d\u0442\u043e \u0440\u0430\u0437 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0435:<\/p>\n<pre><code class=\"python\">opening = cv2.morphologyEx(bin_img, cv2.MORPH_OPEN, kernel)<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0435, \u0430 \u043f\u043e\u0442\u043e\u043c \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0435, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0432\u043e\u0442 \u0447\u0442\u043e:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/47f\/187\/3ec\/47f1873ec62193db126f1a9d59d4ffc1.png\" width=\"608\" height=\"488\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/47f\/187\/3ec\/47f1873ec62193db126f1a9d59d4ffc1.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0428\u0443\u043c \u0438\u0441\u0447\u0435\u0437, \u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043a\u0440\u0430\u0441\u0438\u0432\u043e. \u0410 \u0435\u0441\u043b\u0438 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/790\/4b6\/2c5\/7904b62c5051278f3feef6e63b3cc5af.png\" width=\"607\" height=\"487\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/790\/4b6\/2c5\/7904b62c5051278f3feef6e63b3cc5af.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0443\u0442 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0443\u0431\u0440\u0430\u0442\u044c \u0448\u0443\u043c. <\/p>\n<p>\u041b\u0430\u0434\u043d\u043e, \u0448\u0443\u043c, \u0435\u0441\u043b\u0438 \u0447\u0442\u043e, \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0443\u0431\u0440\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c. \u0412\u043e\u0442 \u043f\u043e\u043b\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b:<\/p>\n<pre><code class=\"python\">import cv2 import numpy as np my_photo = cv2.imread('bricks\\\\1.jpg') img = cv2.cvtColor(my_photo, cv2.COLOR_BGR2HSV) h_channel = my_photo[:,:,0] v_channel = my_photo[:,:,2] bin_img = np.zeros(my_photo.shape) bin_img[(h_channel &lt; 70) * (h_channel > 20) * (v_channel>100)] = [0, 0, 255] cv2.imshow('h_channel', h_channel) cv2.imshow('v_channel', v_channel) cv2.imshow('my_photo', my_photo)  kernel = np.ones((5,5),np.uint8) opening = cv2.morphologyEx(bin_img, cv2.MORPH_OPEN, kernel) closing = cv2.morphologyEx(opening, cv2.MORPH_CLOSE, kernel)  cv2.imshow('result', closing) cv2.waitKey(0)  cv2.destroyAllWindows()<\/code><\/pre>\n<p>\u0410 \u0441\u0435\u0439\u0447\u0430\u0441 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043c, \u0430 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043b\u0438 \u043d\u0430\u0448 \u043c\u0435\u0442\u043e\u0434 \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/419\/555\/c4e\/419555c4ea48ecd6861c611ee1d165b2.png\" width=\"693\" height=\"327\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/419\/555\/c4e\/419555c4ea48ecd6861c611ee1d165b2.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u043c, \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b. \u0415\u0449\u0435 \u043e\u0434\u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/78e\/ce5\/183\/78ece5183be7b674d1eb57aa88095f86.png\" width=\"693\" height=\"211\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/78e\/ce5\/183\/78ece5183be7b674d1eb57aa88095f86.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0410 \u0442\u0443\u0442 \u043d\u0435 \u0443\u0432\u0438\u0434\u0435\u043b. \u0417\u0430\u0442\u043e \u0441\u0440\u0435\u0430\u0433\u0438\u0440\u043e\u0432\u0430\u043b \u043d\u0430 \u0437\u043d\u0430\u043a \u00ab\u041e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u043f\u0440\u0435\u0449\u0435\u043d\u0430\u00bb. \u041a\u0441\u0442\u0430\u0442\u0438, \u0430 \u043a\u0430\u043a \u0431\u044b\u0442\u044c, \u0435\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043d\u0435 \u00ab\u041a\u0438\u0440\u043f\u0438\u0447\u00bb \u0434\u0435\u0442\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u0437\u043d\u0430\u043a? \u041c\u043e\u0436\u0435\u0442, \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a-\u0442\u043e \u0440\u0435\u0430\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u0444\u043e\u0440\u043c\u0443? \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u043e\u0438\u0441\u043a\u0430\u0442\u044c \u043a\u0440\u0443\u0433\u043b\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b. <\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430, \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u043c, \u043a\u0430\u043a \u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c \u043a\u043e\u043d\u0442\u0443\u0440:<\/p>\n<pre><code class=\"python\">import cv2 import numpy as np  my_photo = cv2.imread('bricks\\\\White1.jpg') img_grey = cv2.cvtColor(my_photo,cv2.COLOR_BGR2GRAY)  #set a thresh thresh = 100  #get threshold image ret,thresh_img = cv2.threshold(img_grey, thresh, 255, cv2.THRESH_BINARY)  #find contours contours, hierarchy = cv2.findContours(thresh_img, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)  #create an empty image for contours img_contours = np.zeros(my_photo.shape)  # draw the contours on the empty image cv2.drawContours(img_contours, contours, -1, (255,255,255), 1)  cv2.imshow('origin', my_photo) # \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0438\u0442\u043e\u0433\u043e\u0432\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0432 \u043e\u043a\u043d\u043e cv2.imshow('contours', img_contours) # \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0438\u0442\u043e\u0433\u043e\u0432\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0432 \u043e\u043a\u043d\u043e  cv2.waitKey() cv2.destroyAllWindows()<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c\u0441\u044f \u043a\u043e\u043d\u0442\u0443\u0440 \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430\u0445:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/252\/3ea\/9db\/2523ea9dbe5ad91ecf0d71e1938d236b.png\" width=\"693\" height=\"210\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/252\/3ea\/9db\/2523ea9dbe5ad91ecf0d71e1938d236b.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/7ad\/ea6\/49f\/7adea649fa58ae975f661f5cbee7e621.png\" width=\"693\" height=\"279\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7ad\/ea6\/49f\/7adea649fa58ae975f661f5cbee7e621.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u043e\u0431\u043e\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043e\u043a\u0440\u0443\u0436\u043d\u043e\u0441\u0442\u044c \u0432\u0438\u0434\u043d\u0430, \u043d\u043e \u043c\u043d\u043e\u0433\u043e \u0448\u0443\u043c\u0430. \u041a\u0430\u043a \u043e\u0442\u0434\u0435\u043b\u0438\u0442\u044c \u043e\u0442 \u0448\u0443\u043c\u0430? \u0412 OpenCV \u0435\u0441\u0442\u044c \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f HoughCircles (\u0432 \u043d\u0435\u0435, \u0441\u0443\u0434\u044f \u043f\u043e \u0432\u0441\u0435\u043c\u0443, \u0443\u0436\u0435 \u0432\u0441\u0442\u0440\u043e\u0435\u043d \u0434\u0435\u0442\u0435\u043a\u0442\u043e\u0440 \u043a\u043e\u043d\u0442\u0443\u0440\u043e\u0432, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u0441\u0430\u043c\u0438\u043c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c):<\/p>\n<pre><code class=\"python\">import cv2 import numpy as np  my_photo = cv2.imread('bricks\\\\1.jpg') #my_photo = cv2.imread('bricks\\\\White1.jpg') img_grey = cv2.cvtColor(my_photo,cv2.COLOR_BGR2GRAY)  rows = img_grey.shape[0] circles = cv2.HoughCircles(img_grey, cv2.HOUGH_GRADIENT, 1, rows \/ 8,                           param1=100, param2=30,                           minRadius=1, maxRadius=100)  res = np.zeros(my_photo.shape) if circles is not None:     circles = np.uint16(np.around(circles))     for i in circles[0, :]:         center = (i[0], i[1])         # circle center         cv2.circle(res, center, 1, (0, 100, 100), 3)         # circle outline         radius = i[2]         cv2.circle(res, center, radius, (255, 0, 255), 3)  cv2.imshow('origin', my_photo) # \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0438\u0442\u043e\u0433\u043e\u0432\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0432 \u043e\u043a\u043d\u043e cv2.imshow('res', res) # \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0438\u0442\u043e\u0433\u043e\u0432\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0432 \u043e\u043a\u043d\u043e  cv2.waitKey() cv2.destroyAllWindows()<\/code><\/pre>\n<p>\u0414\u0430\u043d\u043d\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043d\u0430\u0448\u043b\u0430 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u043e\u043a\u0440\u0443\u0436\u043d\u043e\u0441\u0442\u0435\u0439:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/1ee\/e9e\/4b9\/1eee9e4b989ba756fed76893d7e44992.png\" width=\"693\" height=\"213\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1ee\/e9e\/4b9\/1eee9e4b989ba756fed76893d7e44992.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u0440\u0435\u0433\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0440\u043e\u0433\u0430\u043c\u0438, \u0437\u0430\u0434\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 param1 \u0438 param2:<\/p>\n<pre><code class=\"python\">circles = cv2.HoughCircles(img_grey, cv2.HOUGH_GRADIENT, 1, rows \/ 8,                           param1=150, param2=50,                           minRadius=1, maxRadius=100)<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d55\/8dd\/00a\/d558dd00a04c931a68fc22e014b6feee.png\" width=\"693\" height=\"213\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d55\/8dd\/00a\/d558dd00a04c931a68fc22e014b6feee.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0411\u043e\u043b\u0435\u0435 \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e \u0431\u0443\u0434\u0435\u0442, \u0435\u0441\u043b\u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0435 \u043e\u043a\u0440\u0443\u0436\u043d\u043e\u0441\u0442\u0438 \u043d\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0438:<\/p>\n<pre><code class=\"python\">res = np.zeros(my_photo.shape) if circles is not None:     circles = np.uint16(np.around(circles))     for i in circles[0, :]:         center = (i[0], i[1])         # circle center         cv2.circle(my_photo, center, 1, (0, 100, 100), 3)         # circle outline         radius = i[2]         cv2.circle(my_photo, center, radius, (255, 0, 255), 3)  cv2.imshow('origin', my_photo) # \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0438\u0442\u043e\u0433\u043e\u0432\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0432 \u043e\u043a\u043d\u043e<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/9f1\/8c0\/4b4\/9f18c04b4ef9b63612bf29a2d34b74ca.png\" width=\"693\" height=\"421\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9f1\/8c0\/4b4\/9f18c04b4ef9b63612bf29a2d34b74ca.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0410 \u043a\u0430\u043a \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435?<\/p>\n<p>\u0421\u043c\u043e\u0442\u0440\u0438\u043c:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/abc\/04f\/9ea\/abc04f9ea3aaac3e0a3e70760c9e978e.png\" width=\"607\" height=\"486\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/abc\/04f\/9ea\/abc04f9ea3aaac3e0a3e70760c9e978e.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0417\u0434\u0435\u0441\u044c, \u043a\u0430\u043a \u0432\u0438\u0434\u0438\u043c, \u0448\u0443\u043c\u0430 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u043d\u043e\u0433\u043e. \u041d\u043e \u043e\u0434\u0438\u043d \u0438\u0437 \u043a\u0440\u0443\u0433\u043e\u0432 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0438\u0441\u043a\u043e\u043c\u044b\u0439 \u0437\u043d\u0430\u043a. <\/p>\n<p>\u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043c\u0435\u0442\u043e\u0434 \u043f\u043e\u0438\u0441\u043a\u0430 \u043a\u0440\u0443\u0433\u0430 \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0442\u043e\u0436\u0435 \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430. \u0412\u043e\u0442 \u043d\u0430 \u044d\u0442\u043e\u0439 \u0444\u043e\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043d\u0430\u0448\u043b\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0448\u0443\u043c:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/428\/567\/5a4\/4285675a45490f74d80e8cadae4588a1.png\" width=\"570\" height=\"399\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/428\/567\/5a4\/4285675a45490f74d80e8cadae4588a1.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043c\u043e\u0447\u044c \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438?<\/p>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u00ab\u043f\u043e\u0434\u0441\u0443\u043d\u0443\u0442\u044c\u00bb\u00a0 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 HoughCircles \u043d\u0435 \u0446\u0435\u043b\u0443\u044e \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443, \u0430 \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u043a\u043e\u043d\u0442\u0443\u0440. \u0422\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u043d\u0442\u0443\u0440 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043d\u0430\u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c \u0432 \u043c\u0430\u0442\u0440\u0438\u0446\u0435 \u0442\u0438\u043f\u0430 uint8, \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"python\">#create an empty image for contours img_contours = np.uint8(np.zeros((my_photo.shape[0],my_photo.shape[1])))<\/code><\/pre>\n<p>\u0418 \u0447\u0442\u043e \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c? \u0412\u043e\u0442 \u0447\u0442\u043e (\u0437\u043d\u0430\u043a\u0438 \u043d\u0430\u0448\u0435\u043b, \u043d\u043e \u0448\u0443\u043c \u043e\u0441\u0442\u0430\u043b\u0441\u044f):<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/cbc\/ca1\/c9d\/cbcca1c9d23b280bc1beb8553b17615b.png\" width=\"643\" height=\"450\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cbc\/ca1\/c9d\/cbcca1c9d23b280bc1beb8553b17615b.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0414\u0440\u0443\u0433\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u2013 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f (\u043a\u0442\u043e \u0442\u0430\u043c \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0445 \u0432\u043e\u0437\u043c\u0443\u0449\u0430\u043b\u0441\u044f, \u0437\u0430\u0447\u0435\u043c \u044f \u043f\u0438\u0448\u0443 \u043f\u0440\u043e \u0444\u0438\u043b\u044c\u0442\u0440\u044b?):<\/p>\n<pre><code class=\"python\">filterd_image  = cv2.medianBlur(my_photo,7)<\/code><\/pre>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0431\u044b\u043b\u0430 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0430 \u043c\u0435\u0434\u0438\u0430\u043d\u043d\u0430\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f (\u043d\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 HoughCircles \u0431\u044b\u043b\u0430 \u00ab\u0441\u043a\u043e\u0440\u043c\u043b\u0435\u043d\u0430\u00bb \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430) \u0438 \u0432\u043e\u0442 \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/4ac\/544\/5f9\/4ac5445f966ff6e0c1781b6923a5bd23.png\" width=\"625\" height=\"438\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4ac\/544\/5f9\/4ac5445f966ff6e0c1781b6923a5bd23.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0443\u0440\u043e\u043a \u0437\u0430\u043a\u043e\u043d\u0447\u0435\u043d, \u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0435\u0449\u0435. \u0414\u043e \u043d\u043e\u0432\u044b\u0445 \u0432\u0441\u0442\u0440\u0435\u0447.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/664984\/\"> https:\/\/habr.com\/ru\/post\/664984\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041d\u0430 <a href=\"https:\/\/habr.com\/ru\/post\/661663\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u043e\u0448\u043b\u043e\u043c \u0443\u0440\u043e\u043a\u0435<\/a> \u043c\u044b \u043d\u0430\u0443\u0447\u0438\u043b\u0438\u0441\u044c \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043d\u0430\u0431\u043e\u0440 \u043e\u0441\u043e\u0431\u044b\u0445 \u0442\u043e\u0447\u0435\u043a, \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0445 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u043c \u0434\u0435\u0442\u0435\u043a\u0442\u043e\u0440\u043e\u043c \u043e\u0441\u043e\u0431\u044b\u0445 \u0442\u043e\u0447\u0435\u043a, \u0432 \u0433\u0440\u0430\u0444. \u0422\u0430\u043c \u0436\u0435 \u044f \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u043b, \u0437\u0430\u0447\u0435\u043c \u044d\u0442\u043e \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0430\u0434\u043e. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0437\u0443\u0447\u0430\u0442\u044c \u0442\u0430\u043a\u0443\u044e \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u043d\u0430\u0443\u043a\u0438 \u043e \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043d\u043e\u043c \u0437\u0440\u0435\u043d\u0438\u0438, \u043a\u0430\u043a \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u043e\u0431\u043b\u0430\u0441\u0442\u0435\u0439 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0430 \u043d\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0438. \u041a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u044d\u0442\u043e \u0432\u0442\u043e\u0440\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u044d\u0442\u0430\u043f\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 (\u0441\u043c. <a href=\"https:\/\/habr.com\/ru\/post\/540166\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0435\u0440\u0432\u044b\u0439 \u0443\u0440\u043e\u043a<\/a>). \u0418 \u0442\u0430\u043a, \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u043d\u0430\u0439\u0442\u0438 \u043d\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0438 \u0434\u043e\u0440\u043e\u0436\u043d\u044b\u0439 \u0437\u043d\u0430\u043a. \u041f\u0443\u0441\u0442\u044c \u043c\u044b \u043f\u043e\u043a\u0430 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u043c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0438\u0441\u043a\u043e\u043c \u0437\u043d\u0430\u043a\u043e\u0432 \u00ab\u043a\u0438\u0440\u043f\u0438\u0447\u00bb. \u0412\u043e\u0442 \u043d\u0430\u0448\u0430 \u0440\u0430\u0431\u043e\u0447\u0430\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041a\u0430\u043a \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0443\u0437\u0438\u0442\u044c \u043c\u0435\u0441\u0442\u043e \u043f\u043e\u0438\u0441\u043a\u0430, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0439\u0442\u0438 \u0437\u043d\u0430\u043a \u00ab\u043a\u0438\u0440\u043f\u0438\u0447\u00bb. \u0411\u0440\u043e\u0441\u0430\u0435\u0442\u0441\u044f \u0432 \u0433\u043b\u0430\u0437\u0430, \u0447\u0442\u043e \u043e\u043d \u044f\u0440\u043a\u043e \u043a\u0440\u0430\u0441\u043d\u044b\u0439. \u041c\u043e\u0436\u0435\u0442, \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u0440\u0430\u0441\u043d\u044b\u0439 \u043a\u0430\u043d\u0430\u043b (\u043d\u0438\u0436\u0435 \u0432\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435, \u043f\u043e\u0447\u0435\u043c\u0443 \u0442\u0430\u043a \u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435 \u043d\u0430\u0434\u043e):<\/p>\n<pre><code class=\"python\">import cv2 my_photo = cv2.imread('bricks\\\\dsc_0263.jpg') red_channel = my_photo[:,:,2] cv2.imshow('MyPhoto', red_channel) cv2.waitKey(0)  cv2.destroyAllWindows()<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0442\u0430\u043a\u0443\u044e \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0427\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u043c \u0434\u0430\u043b\u044c\u0448\u0435? \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043f\u043e\u0440\u043e\u0433:<\/p>\n<pre><code class=\"python\">import cv2 import numpy as np my_photo = cv2.imread('bricks\\\\dsc_0263.jpg') red_channel = my_photo[:,:,2] bin_img = np.zeros(my_photo.shape) bin_img[red_channel > 200] = [0, 0, 255] cv2.imshow('MyPhoto', bin_img) cv2.waitKey(0)  cv2.destroyAllWindows()<\/code><\/pre>\n<p>\u0418 \u0447\u0442\u043e \u0436\u0435 \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c? \u0410 \u0432\u043e\u0442 \u0447\u0442\u043e:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u0443\u0440\u0430, \u043c\u044b \u043d\u0430\u0448\u043b\u0438 \u0437\u043d\u0430\u043a. \u041a\u0430\u043a \u043b\u043e\u043a\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043a\u043e\u043f\u043b\u0435\u043d\u0438\u0435 \u044f\u0440\u043a\u0438\u0445 \u0442\u043e\u0447\u0435\u043a, \u0434\u0440\u0443\u0433\u043e\u0439 \u0432\u043e\u043f\u0440\u043e\u0441. \u0422\u0443\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432 \u0434\u0440\u0443\u0433\u043e\u043c. \u0421\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043b\u0438 \u043d\u0430\u0448 \u043c\u0435\u0442\u043e\u0434 \u0442\u0430\u043a \u0436\u0435 \u0445\u043e\u0440\u043e\u0448\u043e \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043e\u0442 \u043d\u0430 \u0442\u0430\u043a\u043e\u0439:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u0442\u0443 \u0436\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u0441 \u0442\u0435\u043c \u0436\u0435 \u044d\u043c\u043f\u0438\u0440\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u043c \u043f\u043e\u0440\u043e\u0433\u043e\u043c:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0412\u043e\u0442 \u044d\u0442\u043e \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u0430, \u0434\u0430? \u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0441\u0440\u0435\u0430\u0433\u0438\u0440\u043e\u0432\u0430\u043b\u0430 \u043d\u0430 \u0448\u0443\u043c, \u043d\u043e \u043d\u0435 \u00ab\u0443\u0432\u0438\u0434\u0435\u043b\u0430\u00bb \u0437\u043d\u0430\u043a. <\/p>\n<p>\u0410 \u0435\u0441\u043b\u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0444\u043e\u0440\u043c\u0430\u0442 HSV \u0438 \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u0438\u043c\u0435\u043d\u043d\u043e \u043a\u0440\u0430\u0441\u043d\u044b\u0439 \u0446\u0432\u0435\u0442? \u041d\u0430\u043f\u043e\u043c\u043d\u044e, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 \u044d\u0442\u043e\u0442 \u0444\u043e\u0440\u043c\u0430\u0442. \u041a\u0430\u043d\u0430\u043b H \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0446\u0432\u0435\u0442. \u0412 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0447\u0438\u0441\u043b\u0430 \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043e\u0442\u0442\u0435\u043d\u043e\u043a. \u041a\u0430\u043d\u0430\u043b S \u2013 \u043d\u0430\u0441\u044b\u0449\u0435\u043d\u043d\u043e\u0441\u0442\u044c, \u043f\u0440\u0438 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0438 \u044d\u0442\u043e \u0431\u0435\u043b\u044b\u0439 \u0446\u0432\u0435\u0442, \u043f\u0440\u0438 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u043c \u2013 \u0446\u0432\u0435\u0442, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e \u043a\u0430\u043d\u0430\u043b\u0430 H. \u041a\u0430\u043d\u0430\u043b V \u2013 \u044d\u0442\u043e \u044f\u0440\u043a\u043e\u0441\u0442\u044c. \u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u2013 \u0447\u0435\u0440\u043d\u044b\u0439, \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u2013 \u0446\u0432\u0435\u0442, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 H \u0438 S.<\/p>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u0430\u043d\u0430\u043b H:<\/p>\n<pre><code class=\"python\">import cv2 import numpy as np my_photo = cv2.imread('bricks\\\\White1.jpg') img = cv2.cvtColor(my_photo, cv2.COLOR_BGR2HSV) h_channel = my_photo[:,:,0] bin_img = np.zeros(my_photo.shape) bin_img[(h_channel &lt; 40) * (h_channel > 20)] = [0, 0, 255] cv2.imshow('h_channel', h_channel) cv2.imshow('result', bin_img) cv2.waitKey(0)  cv2.destroyAllWindows()<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0423 \u043d\u0430\u0441 \u043f\u043e\u043f\u0430\u043b\u0438 \u0432 \u043d\u0430\u0448 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d \u0447\u0435\u0440\u043d\u044b\u0435 \u0441\u0442\u0432\u043e\u043b\u044b \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432, \u0432\u0438\u0434\u0438\u043c\u043e, \u043e\u043d\u0438 \u0438\u043c\u0435\u044e\u0442 \u0447\u0443\u0442\u044c \u0437\u0430\u043c\u0435\u0442\u043d\u044b\u0439 \u043a\u0440\u0430\u0441\u043d\u043e\u0432\u0430\u0442\u044b\u0439 \u043e\u0442\u0442\u0435\u043d\u043e\u043a. \u041c\u043e\u0436\u043d\u043e \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u043e \u044f\u0440\u043a\u043e\u0441\u0442\u0438:<\/p>\n<pre><code class=\"python\">import cv2 import numpy as np #my_photo = cv2.imread('bricks\\\\dsc_0263.jpg') my_photo = cv2.imread('bricks\\\\White1.jpg') #my_photo = cv2.imread('bricks\\\\videlenka(24).jpg') img = cv2.cvtColor(my_photo, cv2.COLOR_BGR2HSV) h_channel = my_photo[:,:,0] v_channel = my_photo[:,:,2] bin_img = np.zeros(my_photo.shape) bin_img[(h_channel &lt; 70) * (h_channel > 20) * (v_channel>100)] = [0, 0, 255] cv2.imshow('v_channel', v_channel) cv2.imshow('result', bin_img) cv2.waitKey(0)  cv2.destroyAllWindows()<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0435\u043f\u043b\u043e\u0445\u043e. \u00ab\u0414\u044b\u0440\u044b\u00bb \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0435\u043b\u0430\u0442\u044c \u043c\u043e\u0440\u0444\u043e\u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u043c\u0438 (\u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0435):<\/p>\n<pre><code class=\"python\">kernel = np.ones((5,5),np.uint8) closing = cv2.morphologyEx(bin_img, cv2.MORPH_CLOSE, kernel)<\/code><\/pre>\n<p>\u0418 \u0432\u043e\u0442 \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0432 \u0438\u0442\u043e\u0433\u0435:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0423 \u043d\u0430\u0441 \u043e\u0441\u0442\u0430\u043b\u0441\u044f \u0448\u0443\u043c. \u0422\u043e\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u0431\u0440\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u043c\u043e\u0440\u0444\u043e\u043b\u043e\u0433\u0438\u0438, \u043d\u0430 \u044d\u0442\u043e \u0440\u0430\u0437 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0435:<\/p>\n<pre><code class=\"python\">opening = cv2.morphologyEx(bin_img, cv2.MORPH_OPEN, kernel)<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0435, \u0430 \u043f\u043e\u0442\u043e\u043c \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0435, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0432\u043e\u0442 \u0447\u0442\u043e:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0428\u0443\u043c \u0438\u0441\u0447\u0435\u0437, \u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043a\u0440\u0430\u0441\u0438\u0432\u043e. \u0410 \u0435\u0441\u043b\u0438 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0443\u0442 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0443\u0431\u0440\u0430\u0442\u044c \u0448\u0443\u043c. <\/p>\n<p>\u041b\u0430\u0434\u043d\u043e, \u0448\u0443\u043c, \u0435\u0441\u043b\u0438 \u0447\u0442\u043e, \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0443\u0431\u0440\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c. \u0412\u043e\u0442 \u043f\u043e\u043b\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b:<\/p>\n<pre><code class=\"python\">import cv2 import numpy as np my_photo = cv2.imread('bricks\\\\1.jpg') img = cv2.cvtColor(my_photo, cv2.COLOR_BGR2HSV) h_channel = my_photo[:,:,0] v_channel = my_photo[:,:,2] bin_img = np.zeros(my_photo.shape) bin_img[(h_channel &lt; 70) * (h_channel > 20) * (v_channel>100)] = [0, 0, 255] cv2.imshow('h_channel', h_channel) cv2.imshow('v_channel', v_channel) cv2.imshow('my_photo', my_photo)  kernel = np.ones((5,5),np.uint8) opening = cv2.morphologyEx(bin_img, cv2.MORPH_OPEN, kernel) closing = cv2.morphologyEx(opening, cv2.MORPH_CLOSE, kernel)  cv2.imshow('result', closing) cv2.waitKey(0)  cv2.destroyAllWindows()<\/code><\/pre>\n<p>\u0410 \u0441\u0435\u0439\u0447\u0430\u0441 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043c, \u0430 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043b\u0438 \u043d\u0430\u0448 \u043c\u0435\u0442\u043e\u0434 \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u043c, \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b. \u0415\u0449\u0435 \u043e\u0434\u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0410 \u0442\u0443\u0442 \u043d\u0435 \u0443\u0432\u0438\u0434\u0435\u043b. \u0417\u0430\u0442\u043e \u0441\u0440\u0435\u0430\u0433\u0438\u0440\u043e\u0432\u0430\u043b \u043d\u0430 \u0437\u043d\u0430\u043a \u00ab\u041e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u043f\u0440\u0435\u0449\u0435\u043d\u0430\u00bb. \u041a\u0441\u0442\u0430\u0442\u0438, \u0430 \u043a\u0430\u043a \u0431\u044b\u0442\u044c, \u0435\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043d\u0435 \u00ab\u041a\u0438\u0440\u043f\u0438\u0447\u00bb \u0434\u0435\u0442\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u0437\u043d\u0430\u043a? \u041c\u043e\u0436\u0435\u0442, \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a-\u0442\u043e \u0440\u0435\u0430\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u0444\u043e\u0440\u043c\u0443? \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u043e\u0438\u0441\u043a\u0430\u0442\u044c \u043a\u0440\u0443\u0433\u043b\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b. <\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430, \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u043c, \u043a\u0430\u043a \u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c \u043a\u043e\u043d\u0442\u0443\u0440:<\/p>\n<pre><code class=\"python\">import cv2 import numpy as np  my_photo = cv2.imread('bricks\\\\White1.jpg') img_grey = cv2.cvtColor(my_photo,cv2.COLOR_BGR2GRAY)  #set a thresh thresh = 100  #get threshold image ret,thresh_img = cv2.threshold(img_grey, thresh, 255, cv2.THRESH_BINARY)  #find contours contours, hierarchy = cv2.findContours(thresh_img, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)  #create an empty image for contours img_contours = np.zeros(my_photo.shape)  # draw the contours on the empty image cv2.drawContours(img_contours, contours, -1, (255,255,255), 1)  cv2.imshow('origin', my_photo) # \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0438\u0442\u043e\u0433\u043e\u0432\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0432 \u043e\u043a\u043d\u043e cv2.imshow('contours', img_contours) # \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0438\u0442\u043e\u0433\u043e\u0432\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0432 \u043e\u043a\u043d\u043e  cv2.waitKey() cv2.destroyAllWindows()<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c\u0441\u044f \u043a\u043e\u043d\u0442\u0443\u0440 \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430\u0445:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u043e\u0431\u043e\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043e\u043a\u0440\u0443\u0436\u043d\u043e\u0441\u0442\u044c \u0432\u0438\u0434\u043d\u0430, \u043d\u043e \u043c\u043d\u043e\u0433\u043e \u0448\u0443\u043c\u0430. \u041a\u0430\u043a \u043e\u0442\u0434\u0435\u043b\u0438\u0442\u044c \u043e\u0442 \u0448\u0443\u043c\u0430? \u0412 OpenCV \u0435\u0441\u0442\u044c \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f HoughCircles (\u0432 \u043d\u0435\u0435, \u0441\u0443\u0434\u044f \u043f\u043e \u0432\u0441\u0435\u043c\u0443, \u0443\u0436\u0435 \u0432\u0441\u0442\u0440\u043e\u0435\u043d \u0434\u0435\u0442\u0435\u043a\u0442\u043e\u0440 \u043a\u043e\u043d\u0442\u0443\u0440\u043e\u0432, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u0441\u0430\u043c\u0438\u043c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c):<\/p>\n<pre><code class=\"python\">import cv2 import numpy as np  my_photo = cv2.imread('bricks\\\\1.jpg') #my_photo = cv2.imread('bricks\\\\White1.jpg') img_grey = cv2.cvtColor(my_photo,cv2.COLOR_BGR2GRAY)  rows = img_grey.shape[0] circles = cv2.HoughCircles(img_grey, cv2.HOUGH_GRADIENT, 1, rows \/ 8,                           param1=100, param2=30,                           minRadius=1, maxRadius=100)  res = np.zeros(my_photo.shape) if circles is not None:     circles = np.uint16(np.around(circles))     for i in circles[0, :]:         center = (i[0], i[1])         # circle center         cv2.circle(res, center, 1, (0, 100, 100), 3)         # circle outline         radius = i[2]         cv2.circle(res, center, radius, (255, 0, 255), 3)  cv2.imshow('origin', my_photo) # \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0438\u0442\u043e\u0433\u043e\u0432\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0432 \u043e\u043a\u043d\u043e cv2.imshow('res', res) # \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0438\u0442\u043e\u0433\u043e\u0432\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0432 \u043e\u043a\u043d\u043e  cv2.waitKey() cv2.destroyAllWindows()<\/code><\/pre>\n<p>\u0414\u0430\u043d\u043d\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043d\u0430\u0448\u043b\u0430 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u043e\u043a\u0440\u0443\u0436\u043d\u043e\u0441\u0442\u0435\u0439:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u0440\u0435\u0433\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0440\u043e\u0433\u0430\u043c\u0438, \u0437\u0430\u0434\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 param1 \u0438 param2:<\/p>\n<pre><code class=\"python\">circles = cv2.HoughCircles(img_grey, cv2.HOUGH_GRADIENT, 1, rows \/ 8,                           param1=150, param2=50,                           minRadius=1, maxRadius=100)<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0411\u043e\u043b\u0435\u0435 \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e \u0431\u0443\u0434\u0435\u0442, \u0435\u0441\u043b\u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0435 \u043e\u043a\u0440\u0443\u0436\u043d\u043e\u0441\u0442\u0438 \u043d\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0438:<\/p>\n<pre><code class=\"python\">res = np.zeros(my_photo.shape) if circles is not None:     circles = np.uint16(np.around(circles))     for i in circles[0, :]:         center = (i[0], i[1])         # circle center         cv2.circle(my_photo, center, 1, (0, 100, 100), 3)         # circle outline         radius = i[2]         cv2.circle(my_photo, center, radius, (255, 0, 255), 3)  cv2.imshow('origin', my_photo) # \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0438\u0442\u043e\u0433\u043e\u0432\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0432 \u043e\u043a\u043d\u043e<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0410 \u043a\u0430\u043a \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435?<\/p>\n<p>\u0421\u043c\u043e\u0442\u0440\u0438\u043c:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0417\u0434\u0435\u0441\u044c, \u043a\u0430\u043a \u0432\u0438\u0434\u0438\u043c, \u0448\u0443\u043c\u0430 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u043d\u043e\u0433\u043e. \u041d\u043e \u043e\u0434\u0438\u043d \u0438\u0437 \u043a\u0440\u0443\u0433\u043e\u0432 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0438\u0441\u043a\u043e\u043c\u044b\u0439 \u0437\u043d\u0430\u043a. <\/p>\n<p>\u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043c\u0435\u0442\u043e\u0434 \u043f\u043e\u0438\u0441\u043a\u0430 \u043a\u0440\u0443\u0433\u0430 \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0442\u043e\u0436\u0435 \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430. \u0412\u043e\u0442 \u043d\u0430 \u044d\u0442\u043e\u0439 \u0444\u043e\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043d\u0430\u0448\u043b\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0448\u0443\u043c:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043c\u043e\u0447\u044c \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438?<\/p>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u00ab\u043f\u043e\u0434\u0441\u0443\u043d\u0443\u0442\u044c\u00bb\u00a0 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 HoughCircles \u043d\u0435 \u0446\u0435\u043b\u0443\u044e \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443, \u0430 \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u043a\u043e\u043d\u0442\u0443\u0440. \u0422\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u043d\u0442\u0443\u0440 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043d\u0430\u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c \u0432 \u043c\u0430\u0442\u0440\u0438\u0446\u0435 \u0442\u0438\u043f\u0430 uint8, \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"python\">#create an empty image for contours img_contours = np.uint8(np.zeros((my_photo.shape[0],my_photo.shape[1])))<\/code><\/pre>\n<p>\u0418 \u0447\u0442\u043e \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c? \u0412\u043e\u0442 \u0447\u0442\u043e (\u0437\u043d\u0430\u043a\u0438 \u043d\u0430\u0448\u0435\u043b, \u043d\u043e \u0448\u0443\u043c \u043e\u0441\u0442\u0430\u043b\u0441\u044f):<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0414\u0440\u0443\u0433\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u2013 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f (\u043a\u0442\u043e \u0442\u0430\u043c \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0445 \u0432\u043e\u0437\u043c\u0443\u0449\u0430\u043b\u0441\u044f, \u0437\u0430\u0447\u0435\u043c \u044f \u043f\u0438\u0448\u0443 \u043f\u0440\u043e \u0444\u0438\u043b\u044c\u0442\u0440\u044b?):<\/p>\n<pre><code class=\"python\">filterd_image  = cv2.medianBlur(my_photo,7)<\/code><\/pre>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0431\u044b\u043b\u0430 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0430 \u043c\u0435\u0434\u0438\u0430\u043d\u043d\u0430\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f (\u043d\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 HoughCircles \u0431\u044b\u043b\u0430 \u00ab\u0441\u043a\u043e\u0440\u043c\u043b\u0435\u043d\u0430\u00bb \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430) \u0438 \u0432\u043e\u0442 \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0443\u0440\u043e\u043a \u0437\u0430\u043a\u043e\u043d\u0447\u0435\u043d, \u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0435\u0449\u0435. \u0414\u043e \u043d\u043e\u0432\u044b\u0445 \u0432\u0441\u0442\u0440\u0435\u0447.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/664984\/\"> https:\/\/habr.com\/ru\/post\/664984\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-332957","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/332957","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=332957"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/332957\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=332957"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=332957"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=332957"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}