{"id":335689,"date":"2022-07-13T21:00:06","date_gmt":"2022-07-13T21:00:06","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=335689"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=335689","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 7<\/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\/664984\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u043e\u0448\u043b\u043e\u043c \u0443\u0440\u043e\u043a\u0435<\/a> \u043c\u044b \u0438\u0437\u0443\u0447\u0438\u043b\u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u043f\u043e\u0438\u0441\u043a\u0430 \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. \u041d\u0430\u043f\u043e\u043c\u043d\u044e, \u0447\u0442\u043e \u043c\u044b \u0434\u0435\u043b\u0430\u043b\u0438:<\/p>\n<p>&#8212; \u043f\u044b\u0442\u0430\u043b\u0438\u0441\u044c \u043d\u0430\u0439\u0442\u0438 \u043f\u043e \u0446\u0432\u0435\u0442\u0443 (\u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0442\u0430\u043a \u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435 \u043d\u0430\u0434\u043e);<\/p>\n<p>&#8212; \u043f\u044b\u0442\u0430\u043b\u0438\u0441\u044c \u043d\u0430\u0439\u0442\u0438 \u043a\u0440\u0443\u0433\u043b\u044b\u0439 \u0437\u043d\u0430\u043a \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 HoughCircles (\u0438\u043d\u043e\u0433\u0434\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442);<\/p>\n<p>&#8212; \u0430 \u0435\u0449\u0435 \u043c\u044b \u0438\u0437\u0443\u0447\u0438\u043b\u0438 \u043c\u043e\u0440\u0444\u043e\u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 (\u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0435 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0435).<\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f\u0448\u043d\u0438\u0439 \u0443\u0440\u043e\u043a \u0431\u0443\u0434\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u0433\u043b\u0443\u0431\u043e\u043a\u043e \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043a\u043e\u043d\u0442\u0443\u0440\u0430\u043c\u0438, \u0442\u0430\u043a \u043a\u0430\u043a \u0447\u0430\u0441\u0442\u043e \u043a\u043e\u043d\u0442\u0443\u0440 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0432\u044b\u0434\u0435\u043b\u0438 \u0444\u0438\u0447\u0438 \u043d\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u0430 \u0442\u0430\u043a \u0436\u0435 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432 (\u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u043a\u043e\u043d\u0442\u0443\u0440\u0443, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0445\u0432\u0430\u0442\u0438\u0442\u044c \u0444\u043e\u0440\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0430).<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u043c, \u043a\u0430\u043a \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u043a\u043e\u043d\u0442\u0443\u0440\u044b:<\/p>\n<pre><code class=\"python\">import cv2 import numpy as np  my_photo = cv2.imread('DSCN1311.JPG') filterd_image  = cv2.medianBlur(my_photo,7) img_grey = cv2.cvtColor(filterd_image,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.uint8(np.zeros((my_photo.shape[0],my_photo.shape[1])))  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('res', 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>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u0434 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c \u043a\u043e\u043d\u0442\u0443\u0440\u043e\u0432 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044e. \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\/fcc\/d02\/c9a\/fccd02c9a92c59b948b48c0656d03cdb.png\" width=\"693\" height=\"275\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/fcc\/d02\/c9a\/fccd02c9a92c59b948b48c0656d03cdb.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0411\u0435\u0437 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u0443 \u043d\u0430\u0441 \u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0432\u043e\u0442 \u0447\u0442\u043e (\u0434\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f, \u0441\u043f\u0440\u0430\u0432\u0430 \u0431\u0435\u0437 \u0444\u0438\u043b\u044c\u0442\u0440\u0430, \u0441\u043b\u0435\u0432\u0430 \u0441 \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u043c):<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b72\/1ce\/4e3\/b721ce4e39478d50239037371b7ff5af.png\" width=\"693\" height=\"275\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b72\/1ce\/4e3\/b721ce4e39478d50239037371b7ff5af.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0430 \u0447\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u0443 \u043d\u0430\u0441 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 findContours \u0438 \u043a\u0430\u043a \u0441 \u044d\u0442\u0438\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c:<\/p>\n<pre><code class=\"python\">contours, hierarchy = cv2.findContours(thresh_img, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) print(type(contours),type(hierarchy))<\/code><\/pre>\n<p>\u041c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0432\u044b\u0432\u043e\u0434: <\/p>\n<blockquote>\n<p>&lt;class &#8216;tuple&#8217;> &lt;class &#8216;numpy.ndarray&#8217;><\/p>\n<\/blockquote>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0441\u0430\u043c \u043a\u043e\u043d\u0442\u0443\u0440 \u2013 \u044d\u0442\u043e \u043e\u0431\u044b\u043a\u043d\u043e\u0432\u0435\u043d\u043d\u044b\u0439 \u0442\u044c\u044e\u043f\u043b, \u0430 \u0432\u0442\u043e\u0440\u043e\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u0430\u0441\u0441\u0438\u0432 numpy. \u0415\u0441\u043b\u0438 \u043c\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u044d\u0442\u043e\u0442 \u0442\u044c\u044e\u043f\u043b \u043e\u0442\u043b\u0430\u0434\u0447\u0438\u043a\u043e\u043c, \u0442\u043e \u0443\u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u044d\u0442\u043e\u0433\u043e \u0442\u044c\u044e\u043f\u043b\u0430 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043c\u0430\u0441\u0441\u0438\u0432 numpy:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/ac7\/a54\/258\/ac7a54258e946c57d84bf09459c5b474.png\" width=\"614\" height=\"331\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ac7\/a54\/258\/ac7a54258e946c57d84bf09459c5b474.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0418\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0446\u0435\u043b\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u043d\u0442\u0443\u0440\u043e\u0432. \u041f\u043e \u0438\u0434\u0435\u0435, \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043a\u0430\u0436\u0434\u044b\u043c \u0438\u0437 \u043a\u043e\u043d\u0442\u0443\u0440\u043e\u0432 \u043f\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u0414\u0430\u0432\u0430\u0439\u0442\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u044b\u0432\u0435\u0434\u0435\u043c \u043d\u0430 \u044d\u043a\u0440\u0430\u043d \u0447\u0435\u0442\u0432\u0435\u0440\u0442\u044b\u0439 (\u043e\u043d \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0434 \u043d\u043e\u043c\u0435\u0440\u043e\u043c 3, \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0436\u0435 \u0441 \u043d\u0443\u043b\u044f) \u043a\u043e\u043d\u0442\u0443\u0440:<\/p>\n<pre><code class=\"python\">img_contours = np.uint8(np.zeros((my_photo.shape[3],my_photo.shape[1])))<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0447\u0442\u043e \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c \u043d\u0430 \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\/3af\/3a2\/7e6\/3af3a27e6179555f093d28138581638b.png\" width=\"693\" height=\"276\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3af\/3a2\/7e6\/3af3a27e6179555f093d28138581638b.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041c\u043e\u0436\u043d\u043e \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0441\u0440\u0430\u0437\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u043d\u0442\u0443\u0440\u043e\u0432:<\/p>\n<pre><code class=\"python\">sel_countours=[] sel_countours.append(contours[3]) sel_countours.append(contours[7]) sel_countours.append(contours[8]) cv2.drawContours(img_contours, sel_countours, -1, (255,255,255), 1)<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0447\u0442\u043e \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/57b\/8c7\/e54\/57b8c7e543c0cb99ef65f31684726884.png\" width=\"693\" height=\"274\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/57b\/8c7\/e54\/57b8c7e543c0cb99ef65f31684726884.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0430\u0439\u0434\u0435\u043c \u0441\u0430\u043c\u044b\u0439 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043a\u043e\u043d\u0442\u0443\u0440:<\/p>\n<pre><code class=\"python\">max=0 sel_countour=None for countour in contours:     if countour.shape[0]>max:         sel_countour=countour         max=countour.shape[0]  cv2.drawContours(img_contours, [sel_countour], -1, (255,255,255), 1)<\/code><\/pre>\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\/fbd\/dc3\/d54\/fbddc3d54aba46bfee1708088d1f8ea7.png\" width=\"693\" height=\"273\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/fbd\/dc3\/d54\/fbddc3d54aba46bfee1708088d1f8ea7.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0430\u0434\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u043a\u043e\u043d\u0442\u0443\u0440 \u043c\u043e\u0436\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u043a\u0430\u043a \u0432 \u0432\u0438\u0434\u0435 \u0442\u043e\u0447\u0435\u043a, \u0442\u0430\u043a \u0438 \u0432 \u0432\u0438\u0434\u0435 \u043e\u0442\u0440\u0435\u0437\u043a\u043e\u0432, \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"python\">contours, hierarchy = cv2.findContours(thresh_img, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)<\/code><\/pre>\n<p>\u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d Simple, \u0437\u043d\u0430\u0447\u0438\u0442, \u043a\u043e\u043d\u0442\u0443\u0440 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u0432\u0438\u0434\u0435 \u043e\u0442\u0440\u0435\u0437\u043a\u043e\u0432, \u0435\u0441\u043b\u0438 \u043c\u044b \u043d\u0430\u0440\u0438\u0441\u0443\u0435\u043c \u043f\u043e \u0442\u043e\u0447\u043a\u0430\u043c, \u0442\u043e \u043a\u043e\u043d\u0442\u0443\u0440\u0430 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c\u0441\u044f:<\/p>\n<pre><code class=\"python\">for point in sel_countour:     y=int(point[0][1])     x=int(point[0][0])     img_contours[y,x]=255<\/code><\/pre>\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\/4ae\/6dd\/8a5\/4ae6dd8a57f7a1ef09071e2b9f38a17f.png\" width=\"693\" height=\"275\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4ae\/6dd\/8a5\/4ae6dd8a57f7a1ef09071e2b9f38a17f.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041d\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u0443\u043a\u0430\u0436\u0435\u0442\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 findContours \u0447\u0442\u043e \u043d\u0430\u0434\u043e \u0438\u0441\u043a\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0443\u0440\u044b \u0431\u0435\u0437 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"python\">contours, hierarchy = cv2.findContours(thresh_img, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)<\/code><\/pre>\n<p>\u0422\u043e \u043a\u043e\u043d\u0442\u0443\u0440 \u0431\u0443\u0434\u0435\u0442 \u043a\u0430\u043a \u043d\u0430 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435. <\/p>\n<p>\u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u044f \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0430, \u0442\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0443\u0440, \u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0432 \u0442\u043e\u0447\u043a\u0438 \u043b\u0438\u043d\u0438\u044f\u043c\u0438:<\/p>\n<pre><code class=\"python\">last_point=None for point in sel_countour:     curr_point=point[0]     if not(last_point is None):         x1=int(last_point[0])         y1=int(last_point[1])         x2=int(curr_point[0])         y2=int(curr_point[1])         cv2.line(img_contours, (x1, y1), (x2, y2), 255, thickness=1)     last_point=curr_point<\/code><\/pre>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u0447\u0442\u043e \u0438 \u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u0439 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435. <\/p>\n<p>\u0418 \u0442\u0430\u043a, \u0444\u0443\u043d\u043a\u0446\u0438\u044f findContours \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043d\u0430\u0431\u043e\u0440\u044b \u0442\u043e\u0447\u0435\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0442\u043e\u0447\u043a\u0430\u043c\u0438 \u043a\u043e\u043d\u0442\u0443\u0440\u0430 (\u0438\u043b\u0438 \u043a\u043e\u043d\u0446\u0430\u043c\u0438 \u043e\u0442\u0440\u0435\u0437\u043a\u043e\u0432 \u043a\u043e\u043d\u0442\u0443\u0440\u0430, \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u0438\u043f\u0430 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0438). <\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0443\u0440 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438 \u0434\u0430\u043b\u0435\u0435 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c:<\/p>\n<pre><code class=\"python\">import cv2 import numpy as np import os img = cv2.imread(\"DSCN1311.JPG\") gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) thresh = 100  #get threshold image ret,thresh_img = cv2.threshold(gray, thresh, 255, cv2.THRESH_BINARY)  # find contours without approx contours,_ = cv2.findContours(thresh_img,cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE)  max=0 sel_countour=None for countour in contours:     if countour.shape[0]>max:         sel_countour=countour         max=countour.shape[0]  # calc arclentgh arclen = cv2.arcLength(sel_countour, True)  # do approx eps = 0.0005 epsilon = arclen * eps approx = cv2.approxPolyDP(sel_countour, epsilon, True)  # draw the result canvas = img.copy() for pt in approx:     cv2.circle(canvas, (pt[0][0], pt[0][1]), 7, (0,255,0), -1)  cv2.drawContours(canvas, [approx], -1, (0,0,255), 2, cv2.LINE_AA)  img_contours = np.uint8(np.zeros((img.shape[0],img.shape[1]))) cv2.drawContours(img_contours, [approx], -1, (255,255,255), 1)   cv2.imshow('origin', canvas) # \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', 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>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c\u0441\u044f:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e06\/f9b\/7d6\/e06f9b7d681be936abd4003cf3595d4b.png\" width=\"693\" height=\"277\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e06\/f9b\/7d6\/e06f9b7d681be936abd4003cf3595d4b.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0438, \u043c\u0435\u043d\u044f\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 eps. \u041f\u043e\u0441\u0442\u0430\u0432\u0438\u043c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043c\u0435\u0441\u0442\u043e 0.0005 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 0.005 \u0438 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0443\u0436\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u0434\u0440\u0443\u0433\u043e\u0439:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/aa8\/3ea\/1e4\/aa83ea1e426bbbac5d5408f1c5c67174.png\" width=\"693\" height=\"277\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/aa8\/3ea\/1e4\/aa83ea1e426bbbac5d5408f1c5c67174.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0431\u043e\u043b\u0435\u0435 \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0443\u0441\u043e\u043a \u043a\u043e\u0434\u0430, \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0437\u0430 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u044e:<\/p>\n<pre><code class=\"python\"># calc arclentgh arclen = cv2.arcLength(sel_countour, True)  # do approx eps = 0.0005 epsilon = arclen * eps approx = cv2.approxPolyDP(sel_countour, epsilon, True)<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f arcLength \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0434\u043b\u0438\u043d\u0443 \u0434\u0443\u0433\u0438 \u043a\u043e\u043d\u0442\u0443\u0440\u0430. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0434\u043b\u0438\u043d\u044b \u0440\u0430\u0437\u043d\u044b\u0445 \u043a\u043e\u043d\u0442\u0443\u0440\u043e\u0432.\u00a0 \u0422\u043e\u043b\u044c\u043a\u043e \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u043d\u0442\u0443\u0440\u044b \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u044f \u0438\u0445 \u0434\u043b\u0438\u043d. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043a\u0430\u0441\u0442\u043c\u043d\u0443\u044e \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043e\u0447\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e:<\/p>\n<pre><code class=\"python\">def custom_sort(countour):     return -countour.shape[0]<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0443\u0440\u044b:<\/p>\n<pre><code class=\"python\">contours=list(contours) contours.sort(key=custom_sort)<\/code><\/pre>\n<p>\u0421\u0430\u043c\u044b\u0439 \u0434\u043b\u0438\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0443\u0440 \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0432\u044b\u043c:<\/p>\n<pre><code class=\"python\">sel_countour=contours[0]  # calc arclentgh arclen = cv2.arcLength(sel_countour, True) print(arclen)<\/code><\/pre>\n<p>\u041e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043a\u043e\u043d\u0442\u0443\u0440\u044b \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u043c\u0435\u043d\u044c\u0448\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043e\u0442 \u043a\u043e\u043d\u0442\u0443\u0440 \u043f\u043e\u0434 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c 5:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/324\/0d0\/160\/3240d0160ad8500fbf39170f0e67ccda.png\" width=\"693\" height=\"277\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/324\/0d0\/160\/3240d0160ad8500fbf39170f0e67ccda.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0418\u0434\u0435\u043c \u0434\u0430\u043b\u044c\u0448\u0435. \u041f\u043e\u043b\u0443\u0447\u0438\u0432 \u0434\u043b\u0438\u043d\u0443 \u0434\u0443\u0433\u0438 \u043a\u043e\u043d\u0442\u0443\u0440\u0430, \u043c\u044b \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 \u044d\u043f\u0441\u0438\u043b\u043e\u043d \u2013 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440, \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0437\u0443\u044e\u0449\u0438\u0439 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0438. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u043a\u0440\u0438\u0432\u043e\u0439 \u0438 \u0435\u0435 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0435\u0439.<\/p>\n<p>\u0410\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043a\u043e\u043d\u0442\u0443\u0440 \u2013 \u044d\u0442\u043e, \u043f\u043e \u0441\u0443\u0442\u0438 \u0442\u0435 \u0436\u0435 \u0442\u043e\u0447\u043a\u0438, \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u043d\u044b\u0435 \u043e\u0442\u0440\u0435\u0437\u043a\u0430\u043c\u0438, \u0442\u0430\u043a \u0447\u0442\u043e \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0438 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"python\">last_point=None for point in approx:     curr_point=point[0]     if not(last_point is None):         x1=int(last_point[0])         y1=int(last_point[1])         x2=int(curr_point[0])         y2=int(curr_point[1])         cv2.line(img_contours, (x1, y1), (x2, y2), 255, thickness=1)     last_point=curr_point<\/code><\/pre>\n<p>\u0418 \u0442\u0430\u043a, \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0437\u043d\u0430\u0435\u043c, \u0447\u0442\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0443\u0440 \u2013 \u044d\u0442\u043e \u043e\u0442\u0440\u0435\u0437\u043a\u0438. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u0430\u0436\u0435 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0438 \u043e\u0442\u0440\u0435\u0437\u043a\u0438, \u043f\u043e\u043b\u0443\u0447\u0438\u0432 \u0431\u043e\u043b\u0435\u0435 \u0433\u0440\u0443\u0431\u044b\u0439 \u043a\u043e\u043d\u0442\u0443\u0440, \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u043e\u0442 \u043c\u0435\u043b\u043a\u0438\u0445 \u0434\u0435\u0442\u0430\u043b\u0435\u0439. \u041d\u043e \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0434\u0430\u043b\u044c\u0448\u0435? \u041a\u0430\u043a \u044f \u0443\u0436\u0435 \u043f\u0438\u0441\u0430\u043b \u0432 <a href=\"https:\/\/habr.com\/ru\/post\/656489\/\" rel=\"noopener noreferrer nofollow\">\u0447\u0430\u0441\u0442\u0438 4<\/a>, \u043a\u043e\u043d\u0442\u0443\u0440 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u0432 \u0433\u0440\u0430\u0444 \u0438\u043b\u0438 \u0432 \u0433\u0435\u043e\u043c\u0435\u0442\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u044b, \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u043e\u043f\u0438\u0441\u0430\u0432 \u0435\u0433\u043e \u0438\u043d\u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043d\u043e \u043a \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044e, \u043f\u043e\u0432\u043e\u0440\u043e\u0442\u0443 \u0438 \u0434\u0430\u0436\u0435 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e. <\/p>\n<p>\u0421\u0435\u0439\u0447\u0430\u0441 \u043c\u044b \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0435 \u0438\u043d\u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043d\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u041f\u0443\u0441\u0442\u044c \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u044b\u043a\u043d\u043e\u0432\u0435\u043d\u043d\u0430\u044f \u0448\u0430\u0440\u0438\u043a\u043e\u0432\u0430\u044f \u0440\u0443\u0447\u043a\u0430:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a06\/97e\/e54\/a0697ee54da5642fa3d9e12b84bd38ea.png\" width=\"576\" height=\"409\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a06\/97e\/e54\/a0697ee54da5642fa3d9e12b84bd38ea.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041b\u043e\u0433\u0438\u0447\u043d\u043e \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c, \u0447\u0442\u043e \u043d\u0430\u0434\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0441\u0430\u043c\u044b\u043c \u0434\u043b\u0438\u043d\u043d\u044b\u043c \u043a\u043e\u043d\u0442\u0443\u0440\u043e\u043c. \u041d\u0430\u0439\u0434\u0435\u043c, \u0435\u0433\u043e, \u044d\u0442\u043e \u043c\u044b \u0443\u0436\u0435 \u0443\u043c\u0435\u0435\u043c:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/159\/b63\/cbd\/159b63cbda5feb77a6b978e432b05841.png\" width=\"693\" height=\"493\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/159\/b63\/cbd\/159b63cbda5feb77a6b978e432b05841.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0435\u0442, \u043d\u0435 \u0443\u0433\u0430\u0434\u0430\u043b\u0438, \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0442\u044c. \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u043a\u043e\u043d\u0442\u0443\u0440 \u043e\u043a\u0430\u0437\u0430\u043b\u0441\u044f \u0432\u0442\u043e\u0440\u043e\u0439 \u043f\u043e \u0434\u043b\u0438\u043d\u0435:<\/p>\n<pre><code class=\"python\">contours,_ = cv2.findContours(thresh_img,cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE) contours=list(contours) contours.sort(key=custom_sort) sel_countour=contours[1]<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/0fd\/345\/936\/0fd3459366a8b4b7fd64073de1f70251.png\" width=\"587\" height=\"416\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0fd\/345\/936\/0fd3459366a8b4b7fd64073de1f70251.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0410\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0438\u0440\u0443\u0435\u043c \u0435\u0433\u043e:<\/p>\n<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/0db\/fcf\/559\/0dbfcf5594fa0d46d6df553306f5ae52.png\" width=\"694\" height=\"497\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0db\/fcf\/559\/0dbfcf5594fa0d46d6df553306f5ae52.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041a\u0430\u043a \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u043f\u0440\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0438 eps=0.005 \u043a\u043e\u043d\u0442\u0443\u0440 \u0438\u043c\u0435\u0435\u0442 \u0432\u0441\u0435\u0433\u043e 7 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432:<\/p>\n<pre><code class=\"python\">eps = 0.005 epsilon = arclen * eps approx = cv2.approxPolyDP(sel_countour, epsilon, True) print(len(approx))<\/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\u0435\u043d \u043a\u043e\u043d\u0442\u0443\u0440 \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e48\/f30\/f91\/e48f30f91cd6590a1c7a86568ee4cd59.png\" width=\"655\" height=\"464\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e48\/f30\/f91\/e48f30f91cd6590a1c7a86568ee4cd59.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/2cb\/207\/352\/2cb207352b4acff6b18a4c592aac81e1.png\" width=\"652\" height=\"461\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/2cb\/207\/352\/2cb207352b4acff6b18a4c592aac81e1.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438, \u043a\u0441\u0442\u0430\u0442\u0438, \u043d\u0435 7, \u0430 9 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432. \u041a\u043e\u0440\u043e\u0447\u0435, \u0442\u0443\u0442 \u0437\u0430\u0441\u0430\u0434\u0430 \u0441 \u0442\u0435\u043d\u044c\u044e. \u0412 \u043e\u0431\u0449\u0435\u043c, \u043d\u0430\u0434\u043e \u043a\u0430\u043a-\u0442\u043e \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u043c\u0435\u043b\u043a\u0438\u0445 \u0434\u0435\u0442\u0430\u043b\u0435\u0439. \u041d\u043e \u043a\u0430\u043a? \u041f\u043e\u0434\u043d\u044f\u0442\u044c \u043f\u043e\u0440\u043e\u0433 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0438? \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0435\u043c 0.01:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b2d\/ac1\/016\/b2dac10168406d4cb9674757ccedd4e3.png\" width=\"651\" height=\"462\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b2d\/ac1\/016\/b2dac10168406d4cb9674757ccedd4e3.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0441\u0442\u0430\u043b\u043e 6. \u041d\u0430 \u0434\u0440\u0443\u0433\u0438\u0445 \u0444\u043e\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u044f\u0445, \u0442\u043e\u0436\u0435 \u043a\u0441\u0442\u0430\u0442\u0438 6. \u0422\u0430\u043a\u043e\u0439 \u0432\u043e\u0442 \u0448\u0435\u0441\u0442\u0438\u0443\u0433\u043e\u043b\u044c\u043d\u0438\u043a:   <\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/eec\/493\/1bc\/eec4931bc820c82fb6d6d3b49b7bc8f2.png\" width=\"649\" height=\"464\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/eec\/493\/1bc\/eec4931bc820c82fb6d6d3b49b7bc8f2.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0443\u0440 \u0438\u043d\u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043d\u043e. \u041c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0434\u0432\u0443\u043c\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438:<\/p>\n<p>&#8212; \u0443\u0433\u043b\u044b \u043c\u0435\u0436\u0434\u0443 \u0433\u0440\u0430\u043d\u044f\u043c\u0438 \u043a\u043e\u043d\u0442\u0443\u0440\u0430;<\/p>\n<p>&#8212; \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0438 \u0434\u043b\u0438\u043d \u0441\u0442\u043e\u0440\u043e\u043d.<\/p>\n<p>\u041e\u0431\u0430 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0431\u0443\u0434\u0443\u0442 \u0438\u043d\u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043d\u044b \u043a \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044e, \u043f\u043e\u0432\u043e\u0440\u043e\u0442\u0443 \u0438 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e. \u041d\u043e \u0432\u043e\u043f\u0440\u043e\u0441: \u0430 \u0441 \u043a\u0430\u043a\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u0441\u0447\u0438\u0442\u0430\u0442\u044c? \u041e\u0434\u0438\u043d \u0438\u0437 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432, \u044d\u0442\u043e \u043d\u0430\u0439\u0442\u0438 \u0446\u0435\u043d\u0442\u0440 \u043a\u043e\u043d\u0442\u0443\u0440\u0430 \u0438 \u0437\u0430 \u043d\u0430\u0447\u0430\u043b\u043e \u0432\u0437\u044f\u0442\u044c \u0441\u0430\u043c\u0443\u044e \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u0443\u044e \u043e\u0442 \u043d\u0435\u0433\u043e \u0442\u043e\u0447\u043a\u0443. \u041a\u0430\u043a \u043d\u0430\u0439\u0442\u0438 \u0446\u0435\u043d\u0442\u0440? \u041a\u0430\u043a \u0441\u0440\u0435\u0434\u043d\u044e\u044e \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0443 \u0432\u0441\u0435\u0445 \u0442\u043e\u0447\u0435\u043a \u043a\u043e\u043d\u0442\u0443\u0440\u0430. <\/p>\n<pre><code class=\"python\">sum_x=0.0 sum_y=0.0 for point in approx:     x = float(point[0][0])     y = float(point[0][1])     sum_x+=x     sum_y+=y xc=sum_x\/float(len((approx))) yc=sum_y\/float(len((approx)))<\/code><\/pre>\n<p>\u041e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u043c \u0446\u0435\u043d\u0442\u0440 \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u0432\u043e\u0434\u0430 \u043a\u043e\u043d\u0442\u0443\u0440\u0430:<\/p>\n<pre><code class=\"python\">cv2.circle(img_contours, (int(xc), int(yc)), 7, (255,255,255), 2)<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/bd0\/3f2\/f99\/bd03f2f996c4ed373ed67faf70aefa07.png\" width=\"657\" height=\"465\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/bd0\/3f2\/f99\/bd03f2f996c4ed373ed67faf70aefa07.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0430\u0439\u0434\u0435\u043c \u0442\u043e\u0447\u043a\u0443, \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u0443\u044e \u043e\u0442 \u0446\u0435\u043d\u0442\u0440\u0430:<\/p>\n<pre><code class=\"python\">max=0 beg_point=-1 for i in range(0,len(approx)):     point=approx[i]     x = float(point[0][0])     y = float(point[0][1])     dx=x-xc     dy=y-yc     r=math.sqrt(dx*dx+dy*dy)     if r>max:         max=r         beg_point=i<\/code><\/pre>\n<p>\u041e\u0442\u0440\u0438\u0441\u0443\u0435\u043c \u0435\u0435:<\/p>\n<pre><code class=\"python\">point=approx[beg_point] x = float(point[0][0]) y = float(point[0][1]) cv2.circle(img_contours, (int(x), int(y)), 7, (255,255,255), 2)<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/407\/f68\/b16\/407f68b163853f9eb5a28b408ecac789.png\" width=\"625\" height=\"441\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/407\/f68\/b16\/407f68b163853f9eb5a28b408ecac789.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0431\u043e\u0439\u0434\u0435\u043c \u043a\u043e\u043d\u0442\u0443\u0440 \u043f\u043e \u0447\u0430\u0441\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u0435\u043b\u043a\u0435, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u0442\u043e\u0447\u0435\u043a \u0432 \u043f\u043e\u043b\u044f\u0440\u043d\u044b\u0435 \u0438 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0438\u0445 \u043f\u043e \u0443\u0433\u043b\u0443. <\/p>\n<p>\u041f\u043e\u043b\u044f\u0440\u043d\u044b\u0435 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u043c \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0439 \u0432\u043e\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439:<\/p>\n<pre><code class=\"python\">def get_polar_coordinates(x0,y0,x,y,xc,yc):     #\u041f\u0435\u0440\u0432\u0430\u044f \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430 \u0432 \u043f\u043e\u043b\u044f\u0440\u043d\u044b\u0445 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430\u0445 - \u0440\u0430\u0434\u0438\u0443\u0441     dx=xc-x     dy=yc-y     r=math.sqrt(dx*dx+dy*dy)      #\u0412\u0442\u043e\u0440\u0430\u044f \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430 \u0432 \u043f\u043e\u043b\u044f\u0440\u043d\u044b\u0445 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430\u0445 - \u0443\u0437\u0435\u043b, \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u043c \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438     dx0=xc-x0     dy0=yc-y0     r0 = math.sqrt(dx0 * dx0 + dy0 * dy0)     scal_mul=dx0*dx+dy0*dy     cos_angle=scal_mul\/r\/r0     sgn=dx0*dy-dx*dy0 #\u043e\u043f\u0440\u0435\u0434\u0435\u0434\u043b\u044f\u0435\u043c, \u0432 \u043a\u0430\u043a\u0443\u044e \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u043f\u043e\u0432\u0435\u0440\u043d\u0443\u0442 \u0432\u0435\u043a\u0442\u043e\u0440     angle=math.acos(cos_angle)     if sgn&lt;0:         angle=2*math.pi-angle     return angle,r<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0437\u0430\u0434\u0430\u0435\u043c \u0442\u043e\u0447\u043a\u0443 \u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u0442\u0447\u0435\u0442\u0430, \u0438\u0441\u043a\u043e\u043c\u0443\u044e \u0442\u043e\u0447\u043a\u0443 \u0438 \u043d\u0430\u0448 \u0446\u0435\u043d\u0442\u0440. \u041f\u0435\u0440\u0432\u0430\u044f \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430, \u044d\u0442\u043e \u0440\u0430\u0434\u0438\u0443\u0441, \u0435\u0433\u043e \u043c\u044b \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u043c \u043f\u043e \u0442\u0435\u043e\u0440\u0435\u043c\u0435 \u041f\u0438\u0444\u0430\u0433\u043e\u0440\u0430. \u0423\u0433\u043e\u043b \u043d\u0430\u0439\u0434\u0435\u043c \u0447\u0435\u0440\u0435\u0437 \u0441\u043a\u0430\u043b\u044f\u0440\u043d\u043e\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435. \u0422\u0443\u0442, \u043f\u0440\u0430\u0432\u0434\u0430, \u0435\u0441\u0442\u044c \u0437\u0430\u0441\u0430\u0434\u0430. \u0427\u0435\u0440\u0435\u0437 \u0441\u043a\u0430\u043b\u044f\u0440\u043d\u043e\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043c\u044b \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u043c \u0443\u0433\u043e\u043b \u043c\u0435\u0436\u0434\u0443 \u0432\u0435\u043a\u0442\u043e\u0440\u0430\u043c\u0438, \u043d\u043e \u043d\u0435 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435. \u0427\u0442\u043e\u0431\u044b \u0435\u0433\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c, \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u043d\u0430\u0439\u0442\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432. \u0417\u043d\u0430\u043a \u044d\u0442\u043e \u0438 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f. \u041d\u043e \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0443\u0433\u043e\u043b, \u0438\u043d\u0430\u0447\u0435 \u043f\u0440\u0438 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0435 \u043f\u0435\u0440\u0432\u0430\u044f \u0442\u043e\u0447\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435 \u043d\u0430\u0447\u0430\u043b\u043e \u043e\u0442\u0447\u0435\u0442\u0430, \u0430 \u0442\u043e\u0447\u043a\u0430 \u0441 \u0441\u0430\u043c\u044b\u043c \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0443\u0433\u043b\u043e\u043c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0441\u043b\u0438 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432 \u0434\u0440\u0443\u0433\u0443\u044e \u0441\u0442\u043e\u0440\u043e\u043d\u0443, \u0442\u043e \u0432\u044b\u0447\u0442\u0435\u043c \u044d\u0442\u043e\u0442 \u0443\u0433\u043e\u043b \u0438\u0437 \u0443\u0433\u043b\u0430 2 \u043f\u0438 \u0440\u0430\u0434\u0438\u0430\u043d (360 \u0433\u0440\u0430\u0434\u0443\u0441\u043e\u0432). <\/p>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0442\u043e \u044f \u0441\u0435\u0439\u0447\u0430\u0441 \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443. \u041d\u043e, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c:<\/p>\n<pre><code class=\"python\">polar_coordinates=[] x0=approx[beg_point][0][0] y0=approx[beg_point][0][1] print(x0,y0) for point in approx:     x = int(point[0][0])     y = int(point[0][1])     angle,r=get_polar_coordinates(x0,y0,x,y,xc,yc)     polar_coordinates.append(((angle,r),(x,y))) print(polar_coordinates) polar_coordinates.sort(key=polar_sort)<\/code><\/pre>\n<p>\u0410 \u043f\u043e\u0442\u043e\u043c \u043d\u0430\u0440\u0438\u0441\u0443\u0435\u043c:<\/p>\n<pre><code class=\"python\">img_contours = np.uint8(np.zeros((img.shape[0],img.shape[1]))) size=len(polar_coordinates) for i in range(1,size):     _ , point1=polar_coordinates[i-1]     _, point2 = polar_coordinates[i]     x1,y1=point1     x2,y2=point2     cv2.line(img_contours, (x1, y1), (x2, y2), 255, thickness=i) _ , point1=polar_coordinates[size-1] _, point2 = polar_coordinates[0] x1,y1=point1 x2,y2=point2 cv2.line(img_contours, (x1, y1), (x2, y2), 255, thickness=size)<\/code><\/pre>\n<p>\u0421\u043c\u043e\u0442\u0440\u0438\u043c, \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\/3b8\/31b\/18a\/3b831b18af39e45dc79a75fdf72723b0.png\" width=\"599\" height=\"425\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3b8\/31b\/18a\/3b831b18af39e45dc79a75fdf72723b0.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u043e\u0431\u0445\u043e\u0434, \u044f \u043f\u0435\u0440\u0432\u044b\u0435 \u043b\u0438\u043d\u0438\u0438 \u0441\u0434\u0435\u043b\u0430\u043b \u0442\u043e\u043d\u043a\u0438\u043c\u0438, \u043d\u043e \u043f\u043e \u043c\u0435\u0440\u0435 \u043e\u0431\u0445\u043e\u0434\u0430 \u043e\u043d\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u0442\u043e\u043b\u0449\u0435.<\/p>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0443\u0431\u0435\u0440\u0435\u043c \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430 \u0432 \u043f\u043e\u043b\u044f\u0440\u043d\u044b\u0435 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u043d\u0430\u0448\u0438 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0438 \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"python\">def get_polar_coordinates(x0,y0,x,y,xc,yc):     #\u041f\u0435\u0440\u0432\u0430\u044f \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430 \u0432 \u043f\u043e\u043b\u044f\u0440\u043d\u044b\u0445 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430\u0445 - \u0440\u0430\u0434\u0438\u0443\u0441     dx=xc-x     dy=yc-y     r=math.sqrt(dx*dx+dy*dy)      #\u0412\u0442\u043e\u0440\u0430\u044f \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430 \u0432 \u043f\u043e\u043b\u044f\u0440\u043d\u044b\u0445 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430\u0445 - \u0443\u0437\u0435\u043b, \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u043c \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438     dx0=xc-x0     dy0=yc-y0     r0 = math.sqrt(dx0 * dx0 + dy0 * dy0)     scal_mul=dx0*dx+dy0*dy     cos_angle=scal_mul\/r\/r0     #sgn=dx0*dy-dx*dy0 #\u043e\u043f\u0440\u0435\u0434\u0435\u0434\u043b\u044f\u0435\u043c, \u0432 \u043a\u0430\u043a\u0443\u044e \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u043f\u043e\u0432\u0435\u0440\u043d\u0443\u0442 \u0432\u0435\u043a\u0442\u043e\u0440     angle=math.acos(cos_angle)     #if sgn&lt;0:     #    angle=2*math.pi-angle     return angle,r<\/code><\/pre>\n<p>\u0418 \u0432\u043e\u0442 \u0442\u043e\u0433\u0434\u0430 \u043a\u0430\u043a\u0430\u044f \u0435\u0440\u0443\u043d\u0434\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/2bb\/9a5\/510\/2bb9a551026525f12a10772e0ad4ac59.png\" width=\"625\" height=\"445\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/2bb\/9a5\/510\/2bb9a551026525f12a10772e0ad4ac59.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0430\u043a \u0447\u0442\u043e, \u0432\u0435\u0440\u043d\u0435\u043c \u0447\u0442\u043e \u0437\u0430\u043a\u043e\u043c\u0435\u043d\u0442\u0438\u043b\u0438 \u043d\u0430 \u043c\u0435\u0441\u0442\u043e \u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u043c.<\/p>\n<p>\u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u0438\u043d\u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043d\u043e\u043c\u0443 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044e. \u0423\u0433\u043b\u044b \u043c\u0435\u0436\u0434\u0443 \u0433\u0440\u0430\u043d\u044f\u043c\u0438 \u043a\u043e\u043d\u0442\u0443\u0440\u0430. \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0438\u0437 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0443\u0433\u043b\u044b \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b \u0438 \u043c\u0435\u043d\u044c\u0448\u0435 180 \u0433\u0440\u0430\u0434\u0443\u0441\u043e\u0432, \u0442\u043e \u0435\u0441\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0435\u0445 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0439 \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435. \u0425\u043e\u0442\u044f\u2026 \u043b\u0443\u0447\u0448\u0435 \u0434\u0430\u0436\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0435 \u0443\u0433\u043b\u044b \u0430 \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u044b \u0443\u0433\u043b\u043e\u0432, \u043e\u043d\u0438 \u043f\u0440\u0438\u043c\u0443\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043e\u0442 0 \u0434\u043e 1. \u041f\u043e \u0441\u0443\u0442\u0438, \u044d\u0442\u043e \u0443\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u0432\u0435\u043a\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u0434\u0430\u0442\u044c \u043d\u0430 \u0432\u0445\u043e\u0434 \u043a\u0430\u043a\u043e\u0433\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u044c.<\/p>\n<p>\u0418 \u0442\u0430\u043a, \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u0430 \u0443\u0433\u043b\u0430 \u043c\u0435\u0436\u0434\u0443 \u0433\u0440\u0430\u043d\u044f\u043c\u0438 (!!!!!!!):<\/p>\n<pre><code class=\"python\">def get_cos_edges(edges):     dx1, dy1, dx2, dy2=edges     r1 = math.sqrt(dx1 * dx1 + dy1 * dy1)     r2 = math.sqrt(dx2 * dx2 + dy2 * dy2)     return (dx1*dx2+dy1*dy2)\/r1\/r2<\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043c\u044b \u0437\u0430\u0434\u0430\u0435\u043c \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b, \u0430 \u043d\u0435 \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u044b\u0435. \u0418 \u0438\u0445 \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0435\u0449\u0435 \u043e\u0434\u043d\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e:<\/p>\n<pre><code class=\"python\">def get_coords(item1, item2, item3):     _, point1 = item1     _, point2 = item2     _, point3 = item3     x1, y1 = point1     x2, y2 = point2     x3, y3 = point3     dx1=x1-x2     dy1=y1-y2     dx2=x3-x2     dy2=y3-y2     return dx1,dy1,dx2,dy2<\/code><\/pre>\n<p>\u041d\u0443, \u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043a\u043e\u0434 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0438\u043d\u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043d\u043e\u0433\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"python\">coses=[] coses.append(get_cos_edges(get_coords(polar_coordinates[size-1],polar_coordinates[0],polar_coordinates[1]))) for i in range(1,size-1):     coses.append(get_cos_edges(get_coords(polar_coordinates[i-1], polar_coordinates[i],polar_coordinates[i+1]))) coses.append(get_cos_edges(get_coords(polar_coordinates[size-2], polar_coordinates[size-1],polar_coordinates[0])))  print(coses)<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u044d\u0442\u0438 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0440\u0443\u0447\u043a\u0438:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/38e\/072\/c75\/38e072c75f48250ccaf1b462bda00b0f.png\" width=\"693\" height=\"494\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/38e\/072\/c75\/38e072c75f48250ccaf1b462bda00b0f.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0421\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0432\u0435\u043a\u0442\u043e\u0440:<\/p>\n<blockquote>\n<p>[0.8435094506704439, -0.9679482843035412, -0.7475204740128089, 0.12575426475263257, -0.7530074822433576, -0.9513518107379842]<\/p>\n<\/blockquote>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0438:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/cd2\/577\/641\/cd25776419371f5e5f4b185da5a5d7c6.png\" width=\"693\" height=\"490\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cd2\/577\/641\/cd25776419371f5e5f4b185da5a5d7c6.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0421\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0432\u0435\u043a\u0442\u043e\u0440:<\/p>\n<blockquote>\n<p>[0.8997284651496198, -0.9738348113021638, -0.886281044605172, 0.6119832801209469, -0.9073303511520623, -0.9760783176138438]<\/p>\n<\/blockquote>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u043c, \u043f\u0435\u0440\u0432\u044b\u0435 \u0434\u0432\u0435 \u0446\u0438\u0444\u0440 \u043e\u043a\u0430\u0437\u0430\u043b\u0438\u0441\u044c \u0431\u043b\u0438\u0437\u043a\u0438\u0435, \u0442\u0440\u0435\u0442\u044c\u044f \u0447\u0443\u0442\u044c \u0434\u0430\u043b\u044c\u0448\u0435, \u0447\u0435\u0442\u0432\u0435\u0440\u0442\u0430\u044f \u0441\u0438\u043b\u044c\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0430\u0441\u044c, \u0442\u0430\u043a \u0436\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f, \u0430 \u0432\u043e\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u0442\u043e\u0436\u0435 \u043f\u043e\u0447\u0442\u0438 \u0441\u043e\u0432\u043f\u0430\u043b\u0430. <\/p>\n<p>\u0414\u043b\u044f \u0447\u0438\u0441\u0442\u043e\u0442\u044b \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430, \u0435\u0449\u0435 \u0432 \u043e\u0434\u043d\u043e\u043c \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0438:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/16a\/fb8\/f65\/16afb8f65826e6748c4368fe94166e49.png\" width=\"693\" height=\"496\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/16a\/fb8\/f65\/16afb8f65826e6748c4368fe94166e49.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412\u0435\u043a\u0442\u043e\u0440:<\/p>\n<blockquote>\n<p>[0.8447017514267182, -0.968529494204698, -0.20124730714807806, -0.4685934718394871, -0.7702667523702886, -0.9517100095171195]<\/p>\n<\/blockquote>\n<p>\u0412\u0438\u0434\u0438\u043c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u0443\u044e \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e. <\/p>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u044d\u0442\u043e \u043d\u0435 \u0435\u0441\u0442\u044c \u0445\u043e\u0440\u043e\u0448\u043e, \u0447\u0442\u043e \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0446\u0438\u0444\u0440\u044b \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u0441\u0438\u043b\u044c\u043d\u043e \u00ab\u043f\u043b\u044b\u0432\u0443\u0442\u00bb (\u043e\u043f\u044f\u0442\u044c \u0442\u0435\u043d\u044c \u043c\u0435\u0448\u0430\u0435\u0442, \u0431\u0443\u0434\u044c \u043e\u043d\u0430 \u043d\u0435\u043b\u0430\u0434\u043d\u0430). \u042d\u0442\u043e \u043e\u0441\u043b\u043e\u0436\u043d\u0438\u0442 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e. \u041d\u043e \u0443 \u043d\u0430\u0441 \u0435\u0449\u0435 \u0435\u0441\u0442\u044c \u0434\u0440\u0443\u0433\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0443\u0440\u043e\u043a\u0435. \u0410 \u0441\u0435\u0439\u0447\u0430\u0441, \u0432 \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u0443\u0440\u043e\u043a\u0430, \u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u0432\u0435\u0441\u044c \u043a\u043e\u0434 \u043f\u0440\u0438\u043c\u0435\u0440\u0430:<\/p>\n<pre><code class=\"python\">import cv2 import numpy as np import math import os img = cv2.imread(\"Samples\/1.jpg\") gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) thresh = 100  def custom_sort(countour):     return -countour.shape[0]  def polar_sort(item):     return item[0][0]  def get_cos_edges(edges):     dx1, dy1, dx2, dy2=edges     r1 = math.sqrt(dx1 * dx1 + dy1 * dy1)     r2 = math.sqrt(dx2 * dx2 + dy2 * dy2)     return (dx1*dx2+dy1*dy2)\/r1\/r2  def get_polar_coordinates(x0,y0,x,y,xc,yc):     #\u041f\u0435\u0440\u0432\u0430\u044f \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430 \u0432 \u043f\u043e\u043b\u044f\u0440\u043d\u044b\u0445 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430\u0445 - \u0440\u0430\u0434\u0438\u0443\u0441     dx=xc-x     dy=yc-y     r=math.sqrt(dx*dx+dy*dy)      #\u0412\u0442\u043e\u0440\u0430\u044f \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430 \u0432 \u043f\u043e\u043b\u044f\u0440\u043d\u044b\u0445 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430\u0445 - \u0443\u0437\u0435\u043b, \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u043c \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438     dx0=xc-x0     dy0=yc-y0     r0 = math.sqrt(dx0 * dx0 + dy0 * dy0)     scal_mul=dx0*dx+dy0*dy     cos_angle=scal_mul\/r\/r0     sgn=dx0*dy-dx*dy0 #\u043e\u043f\u0440\u0435\u0434\u0435\u0434\u043b\u044f\u0435\u043c, \u0432 \u043a\u0430\u043a\u0443\u044e \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u043f\u043e\u0432\u0435\u0440\u043d\u0443\u0442 \u0432\u0435\u043a\u0442\u043e\u0440     if cos_angle>1:         if cos_angle>1.0001:             raise Exception(\"\u0427\u0442\u043e-\u0442\u043e \u043f\u043e\u0448\u043b\u043e \u043d\u0435 \u0442\u0430\u043a\")         cos_angle=1     angle=math.acos(cos_angle)     if sgn&lt;0:         angle=2*math.pi-angle     return angle,r  def get_coords(item1, item2, item3):     _, point1 = item1     _, point2 = item2     _, point3 = item3     x1, y1 = point1     x2, y2 = point2     x3, y3 = point3     dx1=x1-x2     dy1=y1-y2     dx2=x3-x2     dy2=y3-y2     return dx1,dy1,dx2,dy2  #get threshold image ret,thresh_img = cv2.threshold(gray, thresh, 255, cv2.THRESH_BINARY)  # find contours without approx contours,_ = cv2.findContours(thresh_img,cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE) contours=list(contours) contours.sort(key=custom_sort) sel_countour=contours[1]  # calc arclentgh arclen = cv2.arcLength(sel_countour, True)  # do approx eps = 0.01 epsilon = arclen * eps approx = cv2.approxPolyDP(sel_countour, epsilon, True)  sum_x=0.0 sum_y=0.0 for point in approx:     x = float(point[0][0])     y = float(point[0][1])     sum_x+=x     sum_y+=y xc=sum_x\/float(len((approx))) yc=sum_y\/float(len((approx)))  max=0 beg_point=-1 for i in range(0,len(approx)):     point=approx[i]     x = float(point[0][0])     y = float(point[0][1])     dx=x-xc     dy=y-yc     r=math.sqrt(dx*dx+dy*dy)     if r>max:         max=r         beg_point=i  polar_coordinates=[] x0=approx[beg_point][0][0] y0=approx[beg_point][0][1]  for point in approx:     x = int(point[0][0])     y = int(point[0][1])     angle,r=get_polar_coordinates(x0,y0,x,y,xc,yc)     polar_coordinates.append(((angle,r),(x,y)))  polar_coordinates.sort(key=polar_sort)  img_contours = np.uint8(np.zeros((img.shape[0],img.shape[1]))) size=len(polar_coordinates) for i in range(1,size):     _ , point1=polar_coordinates[i-1]     _, point2 = polar_coordinates[i]     x1,y1=point1     x2,y2=point2     cv2.line(img_contours, (x1, y1), (x2, y2), 255, thickness=i) _ , point1=polar_coordinates[size-1] _, point2 = polar_coordinates[0] x1,y1=point1 x2,y2=point2 cv2.line(img_contours, (x1, y1), (x2, y2), 255, thickness=size)  cv2.circle(img_contours, (int(xc), int(yc)), 7, (255,255,255), 2)  coses=[] coses.append(get_cos_edges(get_coords(polar_coordinates[size-1],polar_coordinates[0],polar_coordinates[1]))) for i in range(1,size-1):     coses.append(get_cos_edges(get_coords(polar_coordinates[i-1], polar_coordinates[i],polar_coordinates[i+1]))) coses.append(get_cos_edges(get_coords(polar_coordinates[size-2], polar_coordinates[size-1],polar_coordinates[0])))  print(coses)  point=approx[beg_point] x = float(point[0][0]) y = float(point[0][1]) cv2.circle(img_contours, (int(x), int(y)), 7, (255,255,255), 2)  cv2.imshow('origin', img) # \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', 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>\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\/676838\/\"> https:\/\/habr.com\/ru\/post\/676838\/<\/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\/664984\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u043e\u0448\u043b\u043e\u043c \u0443\u0440\u043e\u043a\u0435<\/a> \u043c\u044b \u0438\u0437\u0443\u0447\u0438\u043b\u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u043f\u043e\u0438\u0441\u043a\u0430 \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. \u041d\u0430\u043f\u043e\u043c\u043d\u044e, \u0447\u0442\u043e \u043c\u044b \u0434\u0435\u043b\u0430\u043b\u0438:<\/p>\n<p>&#8212; \u043f\u044b\u0442\u0430\u043b\u0438\u0441\u044c \u043d\u0430\u0439\u0442\u0438 \u043f\u043e \u0446\u0432\u0435\u0442\u0443 (\u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0442\u0430\u043a \u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435 \u043d\u0430\u0434\u043e);<\/p>\n<p>&#8212; \u043f\u044b\u0442\u0430\u043b\u0438\u0441\u044c \u043d\u0430\u0439\u0442\u0438 \u043a\u0440\u0443\u0433\u043b\u044b\u0439 \u0437\u043d\u0430\u043a \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 HoughCircles (\u0438\u043d\u043e\u0433\u0434\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442);<\/p>\n<p>&#8212; \u0430 \u0435\u0449\u0435 \u043c\u044b \u0438\u0437\u0443\u0447\u0438\u043b\u0438 \u043c\u043e\u0440\u0444\u043e\u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 (\u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0435 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0435).<\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f\u0448\u043d\u0438\u0439 \u0443\u0440\u043e\u043a \u0431\u0443\u0434\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u0433\u043b\u0443\u0431\u043e\u043a\u043e \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043a\u043e\u043d\u0442\u0443\u0440\u0430\u043c\u0438, \u0442\u0430\u043a \u043a\u0430\u043a \u0447\u0430\u0441\u0442\u043e \u043a\u043e\u043d\u0442\u0443\u0440 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0432\u044b\u0434\u0435\u043b\u0438 \u0444\u0438\u0447\u0438 \u043d\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u0430 \u0442\u0430\u043a \u0436\u0435 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432 (\u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u043a\u043e\u043d\u0442\u0443\u0440\u0443, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0445\u0432\u0430\u0442\u0438\u0442\u044c \u0444\u043e\u0440\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0430).<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u043c, \u043a\u0430\u043a \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u043a\u043e\u043d\u0442\u0443\u0440\u044b:<\/p>\n<pre><code class=\"python\">import cv2 import numpy as np  my_photo = cv2.imread('DSCN1311.JPG') filterd_image  = cv2.medianBlur(my_photo,7) img_grey = cv2.cvtColor(filterd_image,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.uint8(np.zeros((my_photo.shape[0],my_photo.shape[1])))  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('res', 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>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u0434 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c \u043a\u043e\u043d\u0442\u0443\u0440\u043e\u0432 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044e. \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>\u0411\u0435\u0437 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u0443 \u043d\u0430\u0441 \u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0432\u043e\u0442 \u0447\u0442\u043e (\u0434\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f, \u0441\u043f\u0440\u0430\u0432\u0430 \u0431\u0435\u0437 \u0444\u0438\u043b\u044c\u0442\u0440\u0430, \u0441\u043b\u0435\u0432\u0430 \u0441 \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u043c):<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0430 \u0447\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u0443 \u043d\u0430\u0441 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 findContours \u0438 \u043a\u0430\u043a \u0441 \u044d\u0442\u0438\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c:<\/p>\n<pre><code class=\"python\">contours, hierarchy = cv2.findContours(thresh_img, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) print(type(contours),type(hierarchy))<\/code><\/pre>\n<p>\u041c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0432\u044b\u0432\u043e\u0434: <\/p>\n<blockquote>\n<p>&lt;class &#8216;tuple&#8217;> &lt;class &#8216;numpy.ndarray&#8217;><\/p>\n<\/blockquote>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0441\u0430\u043c \u043a\u043e\u043d\u0442\u0443\u0440 \u2013 \u044d\u0442\u043e \u043e\u0431\u044b\u043a\u043d\u043e\u0432\u0435\u043d\u043d\u044b\u0439 \u0442\u044c\u044e\u043f\u043b, \u0430 \u0432\u0442\u043e\u0440\u043e\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u0430\u0441\u0441\u0438\u0432 numpy. \u0415\u0441\u043b\u0438 \u043c\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u044d\u0442\u043e\u0442 \u0442\u044c\u044e\u043f\u043b \u043e\u0442\u043b\u0430\u0434\u0447\u0438\u043a\u043e\u043c, \u0442\u043e \u0443\u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u044d\u0442\u043e\u0433\u043e \u0442\u044c\u044e\u043f\u043b\u0430 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043c\u0430\u0441\u0441\u0438\u0432 numpy:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0418\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0446\u0435\u043b\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u043d\u0442\u0443\u0440\u043e\u0432. \u041f\u043e \u0438\u0434\u0435\u0435, \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043a\u0430\u0436\u0434\u044b\u043c \u0438\u0437 \u043a\u043e\u043d\u0442\u0443\u0440\u043e\u0432 \u043f\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u0414\u0430\u0432\u0430\u0439\u0442\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u044b\u0432\u0435\u0434\u0435\u043c \u043d\u0430 \u044d\u043a\u0440\u0430\u043d \u0447\u0435\u0442\u0432\u0435\u0440\u0442\u044b\u0439 (\u043e\u043d \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0434 \u043d\u043e\u043c\u0435\u0440\u043e\u043c 3, \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0436\u0435 \u0441 \u043d\u0443\u043b\u044f) \u043a\u043e\u043d\u0442\u0443\u0440:<\/p>\n<pre><code class=\"python\">img_contours = np.uint8(np.zeros((my_photo.shape[3],my_photo.shape[1])))<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0447\u0442\u043e \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041c\u043e\u0436\u043d\u043e \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0441\u0440\u0430\u0437\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u043d\u0442\u0443\u0440\u043e\u0432:<\/p>\n<pre><code class=\"python\">sel_countours=[] sel_countours.append(contours[3]) sel_countours.append(contours[7]) sel_countours.append(contours[8]) cv2.drawContours(img_contours, sel_countours, -1, (255,255,255), 1)<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0447\u0442\u043e \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0430\u0439\u0434\u0435\u043c \u0441\u0430\u043c\u044b\u0439 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043a\u043e\u043d\u0442\u0443\u0440:<\/p>\n<pre><code class=\"python\">max=0 sel_countour=None for countour in contours:     if countour.shape[0]>max:         sel_countour=countour         max=countour.shape[0]  cv2.drawContours(img_contours, [sel_countour], -1, (255,255,255), 1)<\/code><\/pre>\n<p>\u0421\u043c\u043e\u0442\u0440\u0438\u043c:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0430\u0434\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u043a\u043e\u043d\u0442\u0443\u0440 \u043c\u043e\u0436\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u043a\u0430\u043a \u0432 \u0432\u0438\u0434\u0435 \u0442\u043e\u0447\u0435\u043a, \u0442\u0430\u043a \u0438 \u0432 \u0432\u0438\u0434\u0435 \u043e\u0442\u0440\u0435\u0437\u043a\u043e\u0432, \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"python\">contours, hierarchy = cv2.findContours(thresh_img, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)<\/code><\/pre>\n<p>\u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d Simple, \u0437\u043d\u0430\u0447\u0438\u0442, \u043a\u043e\u043d\u0442\u0443\u0440 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u0432\u0438\u0434\u0435 \u043e\u0442\u0440\u0435\u0437\u043a\u043e\u0432, \u0435\u0441\u043b\u0438 \u043c\u044b \u043d\u0430\u0440\u0438\u0441\u0443\u0435\u043c \u043f\u043e \u0442\u043e\u0447\u043a\u0430\u043c, \u0442\u043e \u043a\u043e\u043d\u0442\u0443\u0440\u0430 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c\u0441\u044f:<\/p>\n<pre><code class=\"python\">for point in sel_countour:     y=int(point[0][1])     x=int(point[0][0])     img_contours[y,x]=255<\/code><\/pre>\n<p>\u0421\u043c\u043e\u0442\u0440\u0438\u043c:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u0443\u043a\u0430\u0436\u0435\u0442\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 findContours \u0447\u0442\u043e \u043d\u0430\u0434\u043e \u0438\u0441\u043a\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0443\u0440\u044b \u0431\u0435\u0437 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"python\">contours, hierarchy = cv2.findContours(thresh_img, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)<\/code><\/pre>\n<p>\u0422\u043e \u043a\u043e\u043d\u0442\u0443\u0440 \u0431\u0443\u0434\u0435\u0442 \u043a\u0430\u043a \u043d\u0430 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435. <\/p>\n<p>\u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u044f \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0430, \u0442\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0443\u0440, \u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0432 \u0442\u043e\u0447\u043a\u0438 \u043b\u0438\u043d\u0438\u044f\u043c\u0438:<\/p>\n<pre><code class=\"python\">last_point=None for point in sel_countour:     curr_point=point[0]     if not(last_point is None):         x1=int(last_point[0])         y1=int(last_point[1])         x2=int(curr_point[0])         y2=int(curr_point[1])         cv2.line(img_contours, (x1, y1), (x2, y2), 255, thickness=1)     last_point=curr_point<\/code><\/pre>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u0447\u0442\u043e \u0438 \u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u0439 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435. <\/p>\n<p>\u0418 \u0442\u0430\u043a, \u0444\u0443\u043d\u043a\u0446\u0438\u044f findContours \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043d\u0430\u0431\u043e\u0440\u044b \u0442\u043e\u0447\u0435\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0442\u043e\u0447\u043a\u0430\u043c\u0438 \u043a\u043e\u043d\u0442\u0443\u0440\u0430 (\u0438\u043b\u0438 \u043a\u043e\u043d\u0446\u0430\u043c\u0438 \u043e\u0442\u0440\u0435\u0437\u043a\u043e\u0432 \u043a\u043e\u043d\u0442\u0443\u0440\u0430, \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u0438\u043f\u0430 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0438). <\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0443\u0440 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438 \u0434\u0430\u043b\u0435\u0435 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c:<\/p>\n<pre><code class=\"python\">import cv2 import numpy as np import os img = cv2.imread(\"DSCN1311.JPG\") gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) thresh = 100  #get threshold image ret,thresh_img = cv2.threshold(gray, thresh, 255, cv2.THRESH_BINARY)  # find contours without approx contours,_ = cv2.findContours(thresh_img,cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE)  max=0 sel_countour=None for countour in contours:     if countour.shape[0]>max:         sel_countour=countour         max=countour.shape[0]  # calc arclentgh arclen = cv2.arcLength(sel_countour, True)  # do approx eps = 0.0005 epsilon = arclen * eps approx = cv2.approxPolyDP(sel_countour, epsilon, True)  # draw the result canvas = img.copy() for pt in approx:     cv2.circle(canvas, (pt[0][0], pt[0][1]), 7, (0,255,0), -1)  cv2.drawContours(canvas, [approx], -1, (0,0,255), 2, cv2.LINE_AA)  img_contours = np.uint8(np.zeros((img.shape[0],img.shape[1]))) cv2.drawContours(img_contours, [approx], -1, (255,255,255), 1)   cv2.imshow('origin', canvas) # \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', 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>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c\u0441\u044f:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0438, \u043c\u0435\u043d\u044f\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 eps. \u041f\u043e\u0441\u0442\u0430\u0432\u0438\u043c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043c\u0435\u0441\u0442\u043e 0.0005 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 0.005 \u0438 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0443\u0436\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u0434\u0440\u0443\u0433\u043e\u0439:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0431\u043e\u043b\u0435\u0435 \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0443\u0441\u043e\u043a \u043a\u043e\u0434\u0430, \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0437\u0430 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u044e:<\/p>\n<pre><code class=\"python\"># calc arclentgh arclen = cv2.arcLength(sel_countour, True)  # do approx eps = 0.0005 epsilon = arclen * eps approx = cv2.approxPolyDP(sel_countour, epsilon, True)<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f arcLength \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0434\u043b\u0438\u043d\u0443 \u0434\u0443\u0433\u0438 \u043a\u043e\u043d\u0442\u0443\u0440\u0430. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0434\u043b\u0438\u043d\u044b \u0440\u0430\u0437\u043d\u044b\u0445 \u043a\u043e\u043d\u0442\u0443\u0440\u043e\u0432.\u00a0 \u0422\u043e\u043b\u044c\u043a\u043e \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u043d\u0442\u0443\u0440\u044b \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u044f \u0438\u0445 \u0434\u043b\u0438\u043d. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043a\u0430\u0441\u0442\u043c\u043d\u0443\u044e \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043e\u0447\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e:<\/p>\n<pre><code class=\"python\">def custom_sort(countour):     return -countour.shape[0]<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0443\u0440\u044b:<\/p>\n<pre><code class=\"python\">contours=list(contours) contours.sort(key=custom_sort)<\/code><\/pre>\n<p>\u0421\u0430\u043c\u044b\u0439 \u0434\u043b\u0438\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0443\u0440 \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0432\u044b\u043c:<\/p>\n<pre><code class=\"python\">sel_countour=contours[0]  # calc arclentgh arclen = cv2.arcLength(sel_countour, True) print(arclen)<\/code><\/pre>\n<p>\u041e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043a\u043e\u043d\u0442\u0443\u0440\u044b \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u043c\u0435\u043d\u044c\u0448\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043e\u0442 \u043a\u043e\u043d\u0442\u0443\u0440 \u043f\u043e\u0434 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c 5:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0418\u0434\u0435\u043c \u0434\u0430\u043b\u044c\u0448\u0435. \u041f\u043e\u043b\u0443\u0447\u0438\u0432 \u0434\u043b\u0438\u043d\u0443 \u0434\u0443\u0433\u0438 \u043a\u043e\u043d\u0442\u0443\u0440\u0430, \u043c\u044b \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 \u044d\u043f\u0441\u0438\u043b\u043e\u043d \u2013 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440, \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0437\u0443\u044e\u0449\u0438\u0439 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0438. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u043a\u0440\u0438\u0432\u043e\u0439 \u0438 \u0435\u0435 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0435\u0439.<\/p>\n<p>\u0410\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043a\u043e\u043d\u0442\u0443\u0440 \u2013 \u044d\u0442\u043e, \u043f\u043e \u0441\u0443\u0442\u0438 \u0442\u0435 \u0436\u0435 \u0442\u043e\u0447\u043a\u0438, \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u043d\u044b\u0435 \u043e\u0442\u0440\u0435\u0437\u043a\u0430\u043c\u0438, \u0442\u0430\u043a \u0447\u0442\u043e \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0438 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"python\">last_point=None for point in approx:     curr_point=point[0]     if not(last_point is None):         x1=int(last_point[0])         y1=int(last_point[1])         x2=int(curr_point[0])         y2=int(curr_point[1])         cv2.line(img_contours, (x1, y1), (x2, y2), 255, thickness=1)     last_point=curr_point<\/code><\/pre>\n<p>\u0418 \u0442\u0430\u043a, \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0437\u043d\u0430\u0435\u043c, \u0447\u0442\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0443\u0440 \u2013 \u044d\u0442\u043e \u043e\u0442\u0440\u0435\u0437\u043a\u0438. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u0430\u0436\u0435 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0438 \u043e\u0442\u0440\u0435\u0437\u043a\u0438, \u043f\u043e\u043b\u0443\u0447\u0438\u0432 \u0431\u043e\u043b\u0435\u0435 \u0433\u0440\u0443\u0431\u044b\u0439 \u043a\u043e\u043d\u0442\u0443\u0440, \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u043e\u0442 \u043c\u0435\u043b\u043a\u0438\u0445 \u0434\u0435\u0442\u0430\u043b\u0435\u0439. \u041d\u043e \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0434\u0430\u043b\u044c\u0448\u0435? \u041a\u0430\u043a \u044f \u0443\u0436\u0435 \u043f\u0438\u0441\u0430\u043b \u0432 <a href=\"https:\/\/habr.com\/ru\/post\/656489\/\" rel=\"noopener noreferrer nofollow\">\u0447\u0430\u0441\u0442\u0438 4<\/a>, \u043a\u043e\u043d\u0442\u0443\u0440 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u0432 \u0433\u0440\u0430\u0444 \u0438\u043b\u0438 \u0432 \u0433\u0435\u043e\u043c\u0435\u0442\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u044b, \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u043e\u043f\u0438\u0441\u0430\u0432 \u0435\u0433\u043e \u0438\u043d\u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043d\u043e \u043a \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044e, \u043f\u043e\u0432\u043e\u0440\u043e\u0442\u0443 \u0438 \u0434\u0430\u0436\u0435 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e. <\/p>\n<p>\u0421\u0435\u0439\u0447\u0430\u0441 \u043c\u044b \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0435 \u0438\u043d\u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043d\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u041f\u0443\u0441\u0442\u044c \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u044b\u043a\u043d\u043e\u0432\u0435\u043d\u043d\u0430\u044f \u0448\u0430\u0440\u0438\u043a\u043e\u0432\u0430\u044f \u0440\u0443\u0447\u043a\u0430:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041b\u043e\u0433\u0438\u0447\u043d\u043e \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c, \u0447\u0442\u043e \u043d\u0430\u0434\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0441\u0430\u043c\u044b\u043c \u0434\u043b\u0438\u043d\u043d\u044b\u043c \u043a\u043e\u043d\u0442\u0443\u0440\u043e\u043c. \u041d\u0430\u0439\u0434\u0435\u043c, \u0435\u0433\u043e, \u044d\u0442\u043e \u043c\u044b \u0443\u0436\u0435 \u0443\u043c\u0435\u0435\u043c:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0435\u0442, \u043d\u0435 \u0443\u0433\u0430\u0434\u0430\u043b\u0438, \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0442\u044c. \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u043a\u043e\u043d\u0442\u0443\u0440 \u043e\u043a\u0430\u0437\u0430\u043b\u0441\u044f \u0432\u0442\u043e\u0440\u043e\u0439 \u043f\u043e \u0434\u043b\u0438\u043d\u0435:<\/p>\n<pre><code class=\"python\">contours,_ = cv2.findContours(thresh_img,cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE) contours=list(contours) contours.sort(key=custom_sort) sel_countour=contours[1]<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0410\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0438\u0440\u0443\u0435\u043c \u0435\u0433\u043e:<\/p>\n<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041a\u0430\u043a \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u043f\u0440\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0438 eps=0.005 \u043a\u043e\u043d\u0442\u0443\u0440 \u0438\u043c\u0435\u0435\u0442 \u0432\u0441\u0435\u0433\u043e 7 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432:<\/p>\n<pre><code class=\"python\">eps = 0.005 epsilon = arclen * eps approx = cv2.approxPolyDP(sel_countour, epsilon, True) print(len(approx))<\/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\u0435\u043d \u043a\u043e\u043d\u0442\u0443\u0440 \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438, \u043a\u0441\u0442\u0430\u0442\u0438, \u043d\u0435 7, \u0430 9 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432. \u041a\u043e\u0440\u043e\u0447\u0435, \u0442\u0443\u0442 \u0437\u0430\u0441\u0430\u0434\u0430 \u0441 \u0442\u0435\u043d\u044c\u044e. \u0412 \u043e\u0431\u0449\u0435\u043c, \u043d\u0430\u0434\u043e \u043a\u0430\u043a-\u0442\u043e \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u043c\u0435\u043b\u043a\u0438\u0445 \u0434\u0435\u0442\u0430\u043b\u0435\u0439. \u041d\u043e \u043a\u0430\u043a? \u041f\u043e\u0434\u043d\u044f\u0442\u044c \u043f\u043e\u0440\u043e\u0433 \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0438? \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0435\u043c 0.01:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0441\u0442\u0430\u043b\u043e 6. \u041d\u0430 \u0434\u0440\u0443\u0433\u0438\u0445 \u0444\u043e\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u044f\u0445, \u0442\u043e\u0436\u0435 \u043a\u0441\u0442\u0430\u0442\u0438 6. \u0422\u0430\u043a\u043e\u0439 \u0432\u043e\u0442 \u0448\u0435\u0441\u0442\u0438\u0443\u0433\u043e\u043b\u044c\u043d\u0438\u043a:   <\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0443\u0440 \u0438\u043d\u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043d\u043e. \u041c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0434\u0432\u0443\u043c\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438:<\/p>\n<p>&#8212; \u0443\u0433\u043b\u044b \u043c\u0435\u0436\u0434\u0443 \u0433\u0440\u0430\u043d\u044f\u043c\u0438 \u043a\u043e\u043d\u0442\u0443\u0440\u0430;<\/p>\n<p>&#8212; \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0438 \u0434\u043b\u0438\u043d \u0441\u0442\u043e\u0440\u043e\u043d.<\/p>\n<p>\u041e\u0431\u0430 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0431\u0443\u0434\u0443\u0442 \u0438\u043d\u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043d\u044b \u043a \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044e, \u043f\u043e\u0432\u043e\u0440\u043e\u0442\u0443 \u0438 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e. \u041d\u043e \u0432\u043e\u043f\u0440\u043e\u0441: \u0430 \u0441 \u043a\u0430\u043a\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u0441\u0447\u0438\u0442\u0430\u0442\u044c? \u041e\u0434\u0438\u043d \u0438\u0437 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432, \u044d\u0442\u043e \u043d\u0430\u0439\u0442\u0438 \u0446\u0435\u043d\u0442\u0440 \u043a\u043e\u043d\u0442\u0443\u0440\u0430 \u0438 \u0437\u0430 \u043d\u0430\u0447\u0430\u043b\u043e \u0432\u0437\u044f\u0442\u044c \u0441\u0430\u043c\u0443\u044e \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u0443\u044e \u043e\u0442 \u043d\u0435\u0433\u043e \u0442\u043e\u0447\u043a\u0443. \u041a\u0430\u043a \u043d\u0430\u0439\u0442\u0438 \u0446\u0435\u043d\u0442\u0440? \u041a\u0430\u043a \u0441\u0440\u0435\u0434\u043d\u044e\u044e \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0443 \u0432\u0441\u0435\u0445 \u0442\u043e\u0447\u0435\u043a \u043a\u043e\u043d\u0442\u0443\u0440\u0430. <\/p>\n<pre><code class=\"python\">sum_x=0.0 sum_y=0.0 for point in approx:     x = float(point[0][0])     y = float(point[0][1])     sum_x+=x     sum_y+=y xc=sum_x\/float(len((approx))) yc=sum_y\/float(len((approx)))<\/code><\/pre>\n<p>\u041e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u043c \u0446\u0435\u043d\u0442\u0440 \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u0432\u043e\u0434\u0430 \u043a\u043e\u043d\u0442\u0443\u0440\u0430:<\/p>\n<pre><code class=\"python\">cv2.circle(img_contours, (int(xc), int(yc)), 7, (255,255,255), 2)<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0430\u0439\u0434\u0435\u043c \u0442\u043e\u0447\u043a\u0443, \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u0443\u044e \u043e\u0442 \u0446\u0435\u043d\u0442\u0440\u0430:<\/p>\n<pre><code class=\"python\">max=0 beg_point=-1 for i in range(0,len(approx)):     point=approx[i]     x = float(point[0][0])     y = float(point[0][1])     dx=x-xc     dy=y-yc     r=math.sqrt(dx*dx+dy*dy)     if r>max:         max=r         beg_point=i<\/code><\/pre>\n<p>\u041e\u0442\u0440\u0438\u0441\u0443\u0435\u043c \u0435\u0435:<\/p>\n<pre><code class=\"python\">point=approx[beg_point] x = float(point[0][0]) y = float(point[0][1]) cv2.circle(img_contours, (int(x), int(y)), 7, (255,255,255), 2)<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0431\u043e\u0439\u0434\u0435\u043c \u043a\u043e\u043d\u0442\u0443\u0440 \u043f\u043e \u0447\u0430\u0441\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u0435\u043b\u043a\u0435, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u0442\u043e\u0447\u0435\u043a \u0432 \u043f\u043e\u043b\u044f\u0440\u043d\u044b\u0435 \u0438 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0438\u0445 \u043f\u043e \u0443\u0433\u043b\u0443. <\/p>\n<p>\u041f\u043e\u043b\u044f\u0440\u043d\u044b\u0435 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u043c \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0439 \u0432\u043e\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439:<\/p>\n<pre><code class=\"python\">def get_polar_coordinates(x0,y0,x,y,xc,yc):     #\u041f\u0435\u0440\u0432\u0430\u044f \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430 \u0432 \u043f\u043e\u043b\u044f\u0440\u043d\u044b\u0445 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430\u0445 - \u0440\u0430\u0434\u0438\u0443\u0441     dx=xc-x     dy=yc-y     r=math.sqrt(dx*dx+dy*dy)      #\u0412\u0442\u043e\u0440\u0430\u044f \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430 \u0432 \u043f\u043e\u043b\u044f\u0440\u043d\u044b\u0445 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430\u0445 - \u0443\u0437\u0435\u043b, \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u043c \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438     dx0=xc-x0     <\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\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-335689","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/335689","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=335689"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/335689\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=335689"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=335689"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=335689"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}