{"id":397457,"date":"2024-06-29T13:27:33","date_gmt":"2024-06-29T13:27:33","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=397457"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-06-29T13:27:33","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=397457","title":{"rendered":"<span>\u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0430\u043d\u0430\u043b\u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432<\/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>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0438  \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u0440\u0443\u043a\u043e\u043f\u0438\u0441\u043d\u044b\u0435 \u0447\u0438\u0441\u043b\u0430 \u0438\u0437 \u043e\u0442\u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u043b\u0430\u043d\u0430:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/5ec\/7ec\/123\/5ec7ec123ea67e585e18601f43881e56.png\" width=\"620\" height=\"293\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5ec\/7ec\/123\/5ec7ec123ea67e585e18601f43881e56.png\"\/><figcaption><\/figcaption><\/figure>\n<h3>\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c<\/h3>\n<p> \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 , \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0432\u044b\u0448\u0435, \u0438 \u0432 \u043d\u0451\u043c  \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0442\u0435\u0445 \u044f\u0447\u0435\u0435\u043a, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0438\u043c\u0435\u044e\u0442\u0441\u044f \u0447\u0438\u0441\u043b\u0430. \u042f\u0447\u0435\u0439\u043a\u0438, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u043e\u0433\u0443\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c\u0441\u044f \u0447\u0438\u0441\u043b\u0430 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u044b \u043a\u0440\u0430\u0441\u043d\u044b\u043c \u0446\u0432\u0435\u0442\u043e\u043c:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/33d\/c65\/ecb\/33dc65ecba4d9461ce618ba24047d301.png\" width=\"1269\" height=\"653\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/33d\/c65\/ecb\/33dc65ecba4d9461ce618ba24047d301.png\"\/><figcaption><\/figcaption><\/figure>\n<p>  \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0432 \u044f\u0447\u0435\u0439\u043a\u0430\u0445, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0448\u0430\u0433\u0438:<\/p>\n<ol>\n<li>\n<p> \u041a\u043e\u0440\u0440\u0435\u043a\u0446\u0438\u044f \u043f\u0435\u0440\u0435\u043a\u043e\u0441\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u2014 \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u043d\u0435 \u0442\u0430\u043a \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u0443 \u043d\u0430\u0441 \u0443\u0433\u043e\u043b \u043f\u0435\u0440\u0435\u043a\u043e\u0441\u0430 \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0439, \u043d\u043e \u0435\u0441\u043b\u0438 \u0443\u0433\u043e\u043b \u043f\u0435\u0440\u0435\u043a\u043e\u0441\u0430 \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0439(\u043e\u0442 10 \u0433\u0440\u0430\u0434\u0443\u0441\u043e\u0432), \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0442\u0440\u0443\u0434\u043d\u043e\u0441\u0442\u0435\u0439 \u043f\u0440\u0438 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438.<\/p>\n<\/li>\n<li>\n<p> \u0412\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0442\u043e \u0435\u0441\u0442\u044c \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0440\u0430\u043c\u043e\u043a \u043a\u0430\u0436\u0434\u043e\u0439 \u044f\u0447\u0435\u0439\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p> \u041f\u043e\u0438\u0441\u043a \u043d\u0443\u0436\u043d\u044b\u0445 \u043f\u043e\u043b\u0435\u0439 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435, \u0442\u043e \u0435\u0441\u0442\u044c \u0442\u0435\u0445 \u043f\u043e\u043b\u0435\u0439, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0435\u0441\u0442\u044c \u0447\u0438\u0441\u043b\u0430.<\/p>\n<\/li>\n<li>\n<p> \u0420\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u0435 \u0440\u0443\u043a\u043e\u043f\u0438\u0441\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u0432 \u044f\u0447\u0435\u0439\u043a\u0430\u0445.<\/p>\n<\/li>\n<\/ol>\n<h3>\u041a\u043e\u0440\u0440\u0435\u043a\u0446\u0438\u044f \u043f\u0435\u0440\u0435\u043a\u043e\u0441\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u044b<\/h3>\n<pre><code class=\"python\">img = cv2.imread(image_name) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) _, img_bin = cv2.threshold(gray, 128, 255,                            cv2.THRESH_BINARY_INV)<\/code><\/pre>\n<p> \u041f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c \u043c\u044b \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u043c \u043d\u0430\u0448\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0432 \u043e\u0442\u0442\u0435\u043d\u043a\u0438 \u0441\u0435\u0440\u043e\u0433\u043e \u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u0441\u0435\u0440\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0432 \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 threshold(), \u043f\u0440\u043e \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u044f \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043f\u0438\u0441\u0430\u043b <a href=\"https:\/\/habr.com\/ru\/post\/547218\/\" rel=\"noopener noreferrer nofollow\">\u0442\u0443\u0442<\/a> .<\/p>\n<pre><code class=\"python\">coords = np.column_stack(np.where(img_bin == 255)) angle = cv2.minAreaRect(coords)[-1]<\/code><\/pre>\n<p> \u0422\u0435\u043f\u0435\u0440\u044c \u0432  \u0444\u0443\u043d\u043a\u0446\u0438\u044e where() \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0447\u0451\u0440\u043d\u043e-\u0431\u0435\u043b\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435, \u0438 \u0431\u0435\u0440\u0451\u043c \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u0442\u0435\u0445 \u043f\u0438\u043a\u0441\u0435\u043b\u0435\u0439, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0440\u0430\u0432\u043d\u044b<em> <\/em>255 . \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u0430\u043c \u0434\u0432\u0430 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u2014 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u043f\u043e \u043e\u0441\u0438 y \u0438 x \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 column_stack() \u043c\u044b \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u043c \u0434\u0432\u0430 \u043e\u0434\u043d\u043e\u043c\u0435\u0440\u043d\u044b\u0445 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u0434\u0438\u043d \u0434\u0432\u0443\u043c\u0435\u0440\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432. \u0414\u0430\u043b\u0435\u0435 \u044d\u0442\u043e\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e minAreaRect(), \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u043f\u043b\u043e\u0449\u0430\u0434\u044c \u043f\u043e\u0432\u0451\u0440\u043d\u0443\u0442\u043e\u0433\u043e \u043f\u0440\u044f\u043c\u043e\u0443\u0433\u043e\u043b\u044c\u043d\u0438\u043a\u0430 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0443\u0433\u043e\u043b \u043f\u043e\u0432\u043e\u0440\u043e\u0442\u0430. \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043d \u0443\u0433\u043e\u043b \u043d\u0430\u043a\u043b\u043e\u043d\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u0430\u0444\u0444\u0438\u043d\u043d\u043e\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u043b\u044f \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043a\u043e\u0441\u0430:  <\/p>\n<pre><code class=\"python\">(h, w) = img.shape[:2] center = (w \/\/ 2, h \/\/ 2) rotation_matrix = cv2.getRotationMatrix2D(center, angle, 1.0) rotated = cv2.warpAffine(img, rotation_matrix, (w, h),           flags=cv2.INTER_CUBIC, borderMode=cv2.BORDER_REPLICATE)<\/code><\/pre>\n<p> \u041c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u0442\u043e\u0447\u043a\u0438 \u0432\u043e\u043a\u0440\u0443\u0433 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0435\u043c \u0432\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f, \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u044d\u0442\u043e \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u0446\u0435\u043d\u0442\u0440\u0430, \u0443\u0433\u043e\u043b \u043d\u0430\u043a\u043b\u043e\u043d\u0430 \u0438 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e getRotationMatrix2D(). \u0414\u0430\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 numpy, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0432\u0442\u043e\u0440\u044b\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e warpAffine(), \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435. \u0421\u0432\u0435\u0440\u0445\u0443 \u2014 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0434\u043e, \u0441\u043d\u0438\u0437\u0443 \u2014 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u043b\u0435:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/9a2\/845\/8d2\/9a28458d2600f2dd7078825333992c38.png\" width=\"1016\" height=\"1100\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9a2\/845\/8d2\/9a28458d2600f2dd7078825333992c38.png\"\/><figcaption><\/figcaption><\/figure>\n<h3>\u0412\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0442\u0430\u0431\u043b\u0438\u0446\u044b<\/h3>\n<p>  \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043c\u043e\u0440\u0444\u043e\u043b\u043e\u0433\u0438\u0438 \u0442\u0430\u043a\u0438\u043c\u0438 \u043a\u0430\u043a \u044d\u0440\u043e\u0437\u0438\u044f \u0438 \u043d\u0430\u0440\u0430\u0449\u0438\u0432\u0430\u043d\u0438\u0435:<\/p>\n<pre><code class=\"python\">if type == 'h':     structuring_element = np.ones((1, 50), np.uint8) elif type == 'v':     structuring_element = np.ones((50, 1), np.uint8) erode_image = cv2.erode(img_bin, structuring_element, iterations=1) dilate_image = cv2.dilate(erode_image, structuring_element, iterations=1)<\/code><\/pre>\n<p> \u042d\u0440\u043e\u0437\u0438\u044f(erode): \u043f\u0440\u0438\u043b\u0430\u0433\u0430\u0435\u043c \u043a \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u043e\u0447\u043a\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u043c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u043b \u0446\u0435\u043d\u0442\u0440 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0438 \u0442\u043e\u0447\u043a\u0430 \u043d\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0438, \u0435\u0441\u043b\u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442  \u043e\u0431\u044a\u0435\u043a\u0442\u0443, \u0442\u043e \u0442\u0430\u043a\u0430\u044f \u0442\u043e\u0447\u043a\u0430 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f => \u0443\u0434\u0430\u043b\u044f\u044e\u0442\u0441\u044f \u0434\u0435\u0442\u0430\u043b\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u0435\u043d\u044c\u0448\u0435 \u0447\u0435\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0442\u043e\u043d\u044c\u0448\u0435.<\/p>\n<p> \u041d\u0430\u0440\u0430\u0449\u0438\u0432\u0430\u043d\u0438\u0435 (dilate): \u043d\u0430 \u043a\u0430\u0436\u0434\u0443\u044e \u0442\u043e\u0447\u043a\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043d\u0430\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u0430 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u044e\u0449\u0438\u0435 \u0442\u043e\u0447\u043a\u0438 \u0434\u043e\u0440\u0438\u0441\u043e\u0432\u044b\u0432\u0430\u044e\u0442\u0441\u044f => \u0437\u0430\u043a\u0440\u0430\u0448\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0434\u044b\u0440\u043a\u0438 \u043c\u0435\u043d\u044c\u0448\u0438\u0435, \u0447\u0435\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u0430 \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 \u0446\u0435\u043b\u043e\u043c \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0442\u043e\u043b\u0449\u0435.<\/p>\n<p> \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438\u0441\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u0438 \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043b\u0438\u043d\u0438\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/bea\/0f9\/b67\/bea0f9b6778bac34e34b577fd7662457.png\" width=\"1755\" height=\"1240\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/bea\/0f9\/b67\/bea0f9b6778bac34e34b577fd7662457.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/6fc\/c39\/44a\/6fcc3944a5251efcf56fd5c3cf426fff.png\" width=\"1755\" height=\"1240\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/6fc\/c39\/44a\/6fcc3944a5251efcf56fd5c3cf426fff.png\"\/><figcaption><\/figcaption><\/figure>\n<p> \u0414\u0430\u043b\u0435\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u043b\u0438\u043d\u0438\u0438 \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u043c \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u043a \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u043c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e dilate():<\/p>\n<pre><code class=\"python\">def merge_lines(horizontal_lines, vertical_lines):     structuring_element = np.ones((3, 3), np.uint8)     merge_image = horizontal_lines + vertical_lines     merge_image = cv2.dilate(merge_image, structuring_element, iterations=2)     return merge_image<\/code><\/pre>\n<p> \u0412 \u0438\u0442\u043e\u0433\u0435  \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0443\u0434\u0430\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\/f47\/62f\/07b\/f4762f07b12f06422bbf1aba89c5f28e.png\" width=\"1755\" height=\"1240\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f47\/62f\/07b\/f4762f07b12f06422bbf1aba89c5f28e.png\"\/><figcaption><\/figcaption><\/figure>\n<h3>\u041f\u043e\u0438\u0441\u043a \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u043f\u043e\u043b\u0435\u0439 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435<\/h3>\n<p> \u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u044c, \u0433\u0434\u0435 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043b\u044e\u0447\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0442\u044c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043b\u043e\u043d\u043a\u0438, <em>\u0430 <\/em>\u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f<em>&#8212;  <\/em>True\/False , True \u2014 \u0442\u0435 \u044f\u0447\u0435\u0439\u043a\u0438, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u043e\u0433\u0443\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c\u0441\u044f \u0447\u0438\u0441\u043b\u0430, False \u2014 \u044d\u0442\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0442\u0435 \u043f\u043e\u043b\u044f, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043c\u044b \u043d\u0435 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u0442\u044c. \u0412 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u0434\u043b\u044f \u043a\u043b\u044e\u0447\u0435\u0439, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 True, \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0431\u0443\u0434\u0435\u043c \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u043d\u043d\u044b\u043c\u0438 \u0447\u0438\u0441\u043b\u0430\u043c\u0438:<\/p>\n<pre><code class=\"python\">document_columns_dict = {     \"Name_0\": False, \"Account_0\": False, \"Account_1\": True,     \"Adress_0\": False, \"Adress_1\": False, \"Number_GVS_0\": False,     \"Number_GVS_1\": True, \"Number_GVS_2\": True, \"Number_GVS_3\": True,     \"GVS_0\": False, \"GVS_1\": True, \"GVS_2\": True, \"GVS_3\": True,     \"NUMBER_XVS_0\": False, \"NUMBER_XVS_1\": True, \"NUMBER_XVS_2\": True,     \"NUMBER_XVS_3\": True, \"XVS_0\": False, \"XVS_1\": True, \"XVS_2\": True,     \"XVS_3\": True, \"Date&amp;Phone_0\": False, \"Date&amp;Phone_1\": False,     \"Date&amp;Phone_2\": False, \"Date&amp;Phone_3\": False}<\/code><\/pre>\n<p> \u0414\u0430\u043b\u0435\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u0439\u0442\u0438 \u043a\u043e\u043d\u0442\u0443\u0440\u044b \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043e\u043b\u043e\u043d\u043a\u0438, \u0447\u0442\u043e \u043c\u044b \u0438  \u0434\u0435\u043b\u0430\u0435\u043c  \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 findContours(). \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u043a\u043e\u043d\u0442\u0443\u0440\u044b \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u0442\u0430\u043a\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0438\u0434\u0443\u0442 \u043f\u0430\u0440\u044b \u00ab\u043a\u043b\u044e\u0447-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u00bb \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435, \u0442\u043e \u0435\u0441\u0442\u044c \u0441\u0432\u0435\u0440\u0445\u0443 \u0432\u043d\u0438\u0437 \u0438 \u0441\u043b\u0435\u0432\u0430 \u043d\u0430\u043f\u0440\u0430\u0432\u043e:<\/p>\n<pre><code class=\"python\">bounding_boxes = [cv2.boundingRect(c) for c in cnts] if method == \"top-to-right\":     bounding_boxes.sort(key=functools.cmp_to_key(lambda s,                                                   t: custom_tuple_sorting(s, t, 4)))<\/code><\/pre>\n<p> \u0421\u043f\u0435\u0440\u0432\u0430  \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 boundingRect() \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0440\u0430\u043c\u043a\u0438 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0443\u0440\u0430: \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0435 x \u0438 y \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b, \u0437\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0442 \u0448\u0438\u0440\u0438\u043d\u0430 \u0438 \u0432\u044b\u0441\u043e\u0442\u0430 \u0440\u0430\u043c\u043a\u0438. \u0412 3 \u0441\u0442\u0440\u043e\u0447\u043a\u0435 \u043a\u043e\u0434\u0430 \u043c\u044b \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u043d\u0442\u0443\u0440\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 custom_tuple_sorting(), \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 <a href=\"https:\/\/github.com\/wb-08\/DocumentRecognize\/blob\/main\/document_recognize.py#L68\" rel=\"noopener noreferrer nofollow\">github<\/a><em> <\/em>. \u0414\u0430\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442 \u043a\u043e\u043d\u0442\u0443\u0440\u044b \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e \u0443, \u0430 \u043f\u043e\u0442\u043e\u043c \u043f\u043e x. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0435\u0440\u0432\u044b\u0445 \u0434\u0432\u0443\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044f  \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u043a\u043e\u043d\u0442\u0443\u0440\u0430, \u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c \u2014 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u044f\u0447\u0435\u0439\u043a\u0438 \u043c\u043e\u0433\u0443\u0442 \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c\u0441\u044f \u0432 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435, \u043d\u043e \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u043f\u043e y \u043c\u043e\u0433\u0443\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443, \u0435\u0441\u043b\u0438 \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430\u043c\u0438 \u043c\u0435\u043d\u044c\u0448\u0435 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044f, \u0442\u043e \u043c\u044b \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0442\u0430\u043a\u0438\u0435 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u0440\u0430\u0432\u043d\u044b\u043c\u0438 \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439. \u0422\u043e \u0435\u0441\u0442\u044c, \u0435\u0441\u043b\u0438 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0440\u0430\u0432\u043d\u043e 3, \u0442\u043e 34=35=36.  <\/p>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0448\u0430\u0433\u043e\u043c \u043c\u044b \u0432\u044b\u0440\u0435\u0437\u0430\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0443 \u044f\u0447\u0435\u0439\u043a\u0443 \u0441 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435 True:  <\/p>\n<pre><code class=\"python\">if list(document_columns_dict.values())[count]:     img_crop = rotated_image[y - 12:y + h + 12,                              x - 6:x + w + 6]<\/code><\/pre>\n<p> \u041d\u0430\u0445\u043e\u0434\u0438\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0440\u0430\u043c\u043a\u0438 \u0447\u0438\u0441\u0435\u043b:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/285\/d3b\/608\/285d3b608075eb0d60309634ef6d6306.png\" width=\"928\" height=\"83\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/285\/d3b\/608\/285d3b608075eb0d60309634ef6d6306.png\"\/><figcaption><\/figcaption><\/figure>\n<p> \u041a\u0430\u043a \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u0432\u0438\u0434\u0435\u0442\u044c, \u0443 \u043d\u0430\u0441 \u043f\u043e\u044f\u0432\u0438\u043b\u043e\u0441\u044c \u0434\u0432\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b:<\/p>\n<ul>\n<li>\n<p> \u041d\u0430\u0448\u043b\u0438\u0441\u044c \u043d\u0435 \u0432\u0441\u0435 \u043a\u043e\u043d\u0442\u0443\u0440\u044b \u0447\u0438\u0441\u0435\u043b. \u042d\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u0447\u0438\u0441\u043b\u0430 \u0431\u044b\u043b\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u044b \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0431\u043b\u0438\u0437\u043a\u043e \u043a \u043d\u0438\u0436\u043d\u0435\u0439 \u043b\u0438\u043d\u0438\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u043c\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p> \u0423 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0446\u0438\u0444\u0440\u044b \u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u0434\u0432\u0430 \u043a\u043e\u043d\u0442\u0443\u0440\u0430.<\/p>\n<\/li>\n<\/ul>\n<p> \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0440\u0435\u0448\u0438\u0442\u044c \u043f\u0435\u0440\u0432\u0443\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443  \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u0439\u0442\u0438 \u0438 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0432\u0441\u0435 \u043f\u0438\u043a\u0441\u0435\u043b\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u043c\u043a\u0438 \u044f\u0447\u0435\u0439\u043a\u0438 \u0431\u0435\u043b\u044b\u043c\u0438 \u043f\u0438\u043a\u0441\u0435\u043b\u044f\u043c\u0438. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0432\u044b\u0440\u0435\u0437\u0430\u0435\u043c \u0442\u0430\u043a\u043e\u0439 \u0436\u0435 \u043a\u0443\u0441\u043e\u043a \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043d\u0430\u043c \u0432\u0435\u0440\u043d\u0443\u043b\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f merge_lines(), \u0433\u0434\u0435 \u043b\u0438\u043d\u0438\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u043c\u043a\u0438 \u0431\u0435\u043b\u043e\u0433\u043e \u0446\u0432\u0435\u0442\u0430:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/bfc\/5f7\/2b9\/bfc5f72b95a5cf422facf14366e46aae.png\" width=\"928\" height=\"83\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/bfc\/5f7\/2b9\/bfc5f72b95a5cf422facf14366e46aae.png\"\/><figcaption><\/figcaption><\/figure>\n<p> \u0414\u0430\u043d\u043d\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e find_cell_contours(), \u0433\u0434\u0435 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435, \u0430 \u0432\u0442\u043e\u0440\u044b\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u2014 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u044b\u043b\u043e \u0432\u044b\u0440\u0435\u0437\u0430\u043d\u043e \u0441 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f. \u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u0447\u043a\u0435 \u043a\u043e\u0434\u0430 \u043c\u044b \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u0432\u0441\u0435\u0445 \u0431\u0435\u043b\u044b\u0445 \u043f\u0438\u043a\u0441\u0435\u043b\u0435\u0439 \u0443 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u044b\u043b\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043e \u043f\u0435\u0440\u0432\u044b\u043c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e  \u0438 \u0432 \u0446\u0438\u043a\u043b\u0435 \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u043c \u0446\u0432\u0435\u0442 \u043d\u0430 \u0431\u0435\u043b\u044b\u0439 \u0443 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u044b\u043b\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430, \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0442\u0435\u0445 \u043f\u0438\u043a\u0441\u0435\u043b\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u044b\u043b\u0438 \u0431\u0435\u043b\u044b\u043c\u0438 \u0443 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"python\">def find_cell_contours(frame_image, crop_image):     white_pixels = np.where(frame_image == 255)     y = white_pixels[0]     x = white_pixels[1]     for i in range(len(y)):         crop_image[y[i]][x[i]] = 255     return crop_image<\/code><\/pre>\n<p> \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0440\u0435\u0448\u0438\u0442\u044c \u0432\u0442\u043e\u0440\u0443\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u043c\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 permutations() \u043c\u043e\u0434\u0443\u043b\u044f itertools \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u0441\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u043a\u043e\u043d\u0442\u0443\u0440\u043e\u0432 \u0438 \u0435\u0441\u043b\u0438 \u043e\u043d\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0443\u0441\u043b\u043e\u0432\u0438\u044e \u0432 3 \u0441\u0442\u0440\u043e\u0447\u043a\u0435 \u043a\u043e\u0434\u0430 => \u043a\u043e\u043d\u0442\u0443\u0440 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043e\u043d\u0442\u0443\u0440\u0430 \u0438 \u043c\u044b \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u043d\u0442\u0443\u0440 \u0443\u0434\u0430\u043b\u044f\u0435\u043c:<\/p>\n<pre><code class=\"python\">def detect_contour_in_contours(all_contours):     for rec1, rec2 in itertools.permutations(all_contours, 2):         if rec2[0] >= rec1[0] and rec2[1] >= rec1[1]          and rec2[2] &lt;= rec1[2] and rec2[3] &lt;= rec1[3]:             in_rec = [rec2[0], rec2[1], rec2[2], rec2[3]]             all_contours.remove(in_rec)     return all_contours<\/code><\/pre>\n<p> \u041f\u043e\u0441\u043b\u0435 \u0432\u0441\u0435\u0445 \u0432\u044b\u0448\u0435\u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0440\u0435\u0448\u0438\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/ac7\/c31\/ff6\/ac7c31ff6dc24a563ea1581476af1989.png\" width=\"928\" height=\"83\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ac7\/c31\/ff6\/ac7c31ff6dc24a563ea1581476af1989.png\"\/><figcaption><\/figcaption><\/figure>\n<p><strong>\u0420\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u0435 \u0440\u0443\u043a\u043e\u043f\u0438\u0441\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u0432 \u044f\u0447\u0435\u0439\u043a\u0430\u0445<\/strong><\/p>\n<p> \u041d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u044f \u043d\u0435 \u0431\u0443\u0434\u0443 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e. \u0411\u044b\u043b\u0430 \u043e\u0431\u0443\u0447\u0435\u043d\u0430 \u0441\u0432\u0451\u0440\u0442\u043e\u0447\u043d\u0430\u044f <a href=\"https:\/\/github.com\/wb-08\/DocumentRecognize\/blob\/main\/network\/neural_network.py\" rel=\"noopener noreferrer nofollow\">\u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0430\u044f \u0441\u0435\u0442\u044c<\/a> . \u0414\u0430\u0442\u0430\u0441\u0435\u0442 \u0431\u044b\u043b \u0432\u0437\u044f\u0442 <a href=\"https:\/\/github.com\/kensanata\/numbers\" rel=\"noopener noreferrer nofollow\">\u043e\u0442\u0441\u044e\u0434\u0430<\/a> .  \u0412 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435, \u0434\u043b\u044f \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u044b\u043b\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043e \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0439 \u0441\u043b\u043e\u0432\u0430\u0440\u0438\u043a:  <\/p>\n<pre><code class=\"python\">{'Name_0': False, 'Account_0': False, 'Account_1': '4204351220',   'Adress_0': False, 'Adress_1': False, 'Number_GVS_0': False,   'Number_GVS_1': '2353777',  'Number_GVS_2': '', 'Number_GVS_3': '',  'GVS_0': False, 'GVS_1': '16', 'GVS_2': '', 'GVS_3': '',  'NUMBER_XVS_0': False, 'NUMBER_XVS_1': '803',  'NUMBER_XVS_2': '',   'NUMBER_XVS_3': '', 'XVS_0': False, 'XVS_1': '41', 'XVS_2': '',   'XVS_3': '', 'Date&amp;Phone_0': False, 'Date&amp;Phone_1': False,   'Date&amp;Phone_2': False, 'Date&amp;Phone_3': False}<\/code><\/pre>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p> \u042f \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0432\u0430\u043c \u043f\u043e\u043d\u0440\u0430\u0432\u0438\u043b\u0430\u0441\u044c \u043c\u043e\u044f \u0441\u0442\u0430\u0442\u044c\u044f, \u0430 \u0437\u043d\u0430\u043d\u0438\u044f \u043f\u0440\u0438\u0433\u043e\u0434\u044f\u0442\u0441\u044f \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043f\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0443 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432. \u041a\u043e\u0434, \u043a\u0430\u043a \u0432\u0441\u0435\u0433\u0434\u0430, \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043d\u0430 <a href=\"https:\/\/github.com\/wb-08\/DocumentRecognize\" rel=\"noopener noreferrer nofollow\">github<\/a>.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/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\/articles\/568990\/\"> https:\/\/habr.com\/ru\/articles\/568990\/<\/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>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0438  \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u0440\u0443\u043a\u043e\u043f\u0438\u0441\u043d\u044b\u0435 \u0447\u0438\u0441\u043b\u0430 \u0438\u0437 \u043e\u0442\u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u043b\u0430\u043d\u0430:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h3>\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c<\/h3>\n<p> \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 , \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0432\u044b\u0448\u0435, \u0438 \u0432 \u043d\u0451\u043c  \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0442\u0435\u0445 \u044f\u0447\u0435\u0435\u043a, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0438\u043c\u0435\u044e\u0442\u0441\u044f \u0447\u0438\u0441\u043b\u0430. \u042f\u0447\u0435\u0439\u043a\u0438, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u043e\u0433\u0443\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c\u0441\u044f \u0447\u0438\u0441\u043b\u0430 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u044b \u043a\u0440\u0430\u0441\u043d\u044b\u043c \u0446\u0432\u0435\u0442\u043e\u043c:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>  \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0432 \u044f\u0447\u0435\u0439\u043a\u0430\u0445, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0448\u0430\u0433\u0438:<\/p>\n<ol>\n<li>\n<p> \u041a\u043e\u0440\u0440\u0435\u043a\u0446\u0438\u044f \u043f\u0435\u0440\u0435\u043a\u043e\u0441\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u2014 \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u043d\u0435 \u0442\u0430\u043a \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u0443 \u043d\u0430\u0441 \u0443\u0433\u043e\u043b \u043f\u0435\u0440\u0435\u043a\u043e\u0441\u0430 \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0439, \u043d\u043e \u0435\u0441\u043b\u0438 \u0443\u0433\u043e\u043b \u043f\u0435\u0440\u0435\u043a\u043e\u0441\u0430 \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0439(\u043e\u0442 10 \u0433\u0440\u0430\u0434\u0443\u0441\u043e\u0432), \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0442\u0440\u0443\u0434\u043d\u043e\u0441\u0442\u0435\u0439 \u043f\u0440\u0438 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438.<\/p>\n<\/li>\n<li>\n<p> \u0412\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0442\u043e \u0435\u0441\u0442\u044c \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0440\u0430\u043c\u043e\u043a \u043a\u0430\u0436\u0434\u043e\u0439 \u044f\u0447\u0435\u0439\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p> \u041f\u043e\u0438\u0441\u043a \u043d\u0443\u0436\u043d\u044b\u0445 \u043f\u043e\u043b\u0435\u0439 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435, \u0442\u043e \u0435\u0441\u0442\u044c \u0442\u0435\u0445 \u043f\u043e\u043b\u0435\u0439, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0435\u0441\u0442\u044c \u0447\u0438\u0441\u043b\u0430.<\/p>\n<\/li>\n<li>\n<p> \u0420\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u0435 \u0440\u0443\u043a\u043e\u043f\u0438\u0441\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u0432 \u044f\u0447\u0435\u0439\u043a\u0430\u0445.<\/p>\n<\/li>\n<\/ol>\n<h3>\u041a\u043e\u0440\u0440\u0435\u043a\u0446\u0438\u044f \u043f\u0435\u0440\u0435\u043a\u043e\u0441\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u044b<\/h3>\n<pre><code class=\"python\">img = cv2.imread(image_name) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) _, img_bin = cv2.threshold(gray, 128, 255,                            cv2.THRESH_BINARY_INV)<\/code><\/pre>\n<p> \u041f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c \u043c\u044b \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u043c \u043d\u0430\u0448\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0432 \u043e\u0442\u0442\u0435\u043d\u043a\u0438 \u0441\u0435\u0440\u043e\u0433\u043e \u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u0441\u0435\u0440\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0432 \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 threshold(), \u043f\u0440\u043e \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u044f \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043f\u0438\u0441\u0430\u043b <a href=\"https:\/\/habr.com\/ru\/post\/547218\/\" rel=\"noopener noreferrer nofollow\">\u0442\u0443\u0442<\/a> .<\/p>\n<pre><code class=\"python\">coords = np.column_stack(np.where(img_bin == 255)) angle = cv2.minAreaRect(coords)[-1]<\/code><\/pre>\n<p> \u0422\u0435\u043f\u0435\u0440\u044c \u0432  \u0444\u0443\u043d\u043a\u0446\u0438\u044e where() \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0447\u0451\u0440\u043d\u043e-\u0431\u0435\u043b\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435, \u0438 \u0431\u0435\u0440\u0451\u043c \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u0442\u0435\u0445 \u043f\u0438\u043a\u0441\u0435\u043b\u0435\u0439, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0440\u0430\u0432\u043d\u044b<em> <\/em>255 . \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u0430\u043c \u0434\u0432\u0430 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u2014 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u043f\u043e \u043e\u0441\u0438 y \u0438 x \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 column_stack() \u043c\u044b \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u043c \u0434\u0432\u0430 \u043e\u0434\u043d\u043e\u043c\u0435\u0440\u043d\u044b\u0445 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u0434\u0438\u043d \u0434\u0432\u0443\u043c\u0435\u0440\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432. \u0414\u0430\u043b\u0435\u0435 \u044d\u0442\u043e\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e minAreaRect(), \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u043f\u043b\u043e\u0449\u0430\u0434\u044c \u043f\u043e\u0432\u0451\u0440\u043d\u0443\u0442\u043e\u0433\u043e \u043f\u0440\u044f\u043c\u043e\u0443\u0433\u043e\u043b\u044c\u043d\u0438\u043a\u0430 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0443\u0433\u043e\u043b \u043f\u043e\u0432\u043e\u0440\u043e\u0442\u0430. \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043d \u0443\u0433\u043e\u043b \u043d\u0430\u043a\u043b\u043e\u043d\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u0430\u0444\u0444\u0438\u043d\u043d\u043e\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u043b\u044f \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043a\u043e\u0441\u0430:  <\/p>\n<pre><code class=\"python\">(h, w) = img.shape[:2] center = (w \/\/ 2, h \/\/ 2) rotation_matrix = cv2.getRotationMatrix2D(center, angle, 1.0) rotated = cv2.warpAffine(img, rotation_matrix, (w, h),           flags=cv2.INTER_CUBIC, borderMode=cv2.BORDER_REPLICATE)<\/code><\/pre>\n<p> \u041c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u0442\u043e\u0447\u043a\u0438 \u0432\u043e\u043a\u0440\u0443\u0433 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0435\u043c \u0432\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f, \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u044d\u0442\u043e \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u0446\u0435\u043d\u0442\u0440\u0430, \u0443\u0433\u043e\u043b \u043d\u0430\u043a\u043b\u043e\u043d\u0430 \u0438 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e getRotationMatrix2D(). \u0414\u0430\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 numpy, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0432\u0442\u043e\u0440\u044b\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e warpAffine(), \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435. \u0421\u0432\u0435\u0440\u0445\u0443 \u2014 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0434\u043e, \u0441\u043d\u0438\u0437\u0443 \u2014 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u043b\u0435:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h3>\u0412\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0442\u0430\u0431\u043b\u0438\u0446\u044b<\/h3>\n<p>  \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043c\u043e\u0440\u0444\u043e\u043b\u043e\u0433\u0438\u0438 \u0442\u0430\u043a\u0438\u043c\u0438 \u043a\u0430\u043a \u044d\u0440\u043e\u0437\u0438\u044f \u0438 \u043d\u0430\u0440\u0430\u0449\u0438\u0432\u0430\u043d\u0438\u0435:<\/p>\n<pre><code class=\"python\">if type == 'h':     structuring_element = np.ones((1, 50), np.uint8) elif type == 'v':     structuring_element = np.ones((50, 1), np.uint8) erode_image = cv2.erode(img_bin, structuring_element, iterations=1) dilate_image = cv2.dilate(erode_image, structuring_element, iterations=1)<\/code><\/pre>\n<p> \u042d\u0440\u043e\u0437\u0438\u044f(erode): \u043f\u0440\u0438\u043b\u0430\u0433\u0430\u0435\u043c \u043a \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u043e\u0447\u043a\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u043c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u043b \u0446\u0435\u043d\u0442\u0440 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0438 \u0442\u043e\u0447\u043a\u0430 \u043d\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0438, \u0435\u0441\u043b\u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442  \u043e\u0431\u044a\u0435\u043a\u0442\u0443, \u0442\u043e \u0442\u0430\u043a\u0430\u044f \u0442\u043e\u0447\u043a\u0430 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f => \u0443\u0434\u0430\u043b\u044f\u044e\u0442\u0441\u044f \u0434\u0435\u0442\u0430\u043b\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u0435\u043d\u044c\u0448\u0435 \u0447\u0435\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0442\u043e\u043d\u044c\u0448\u0435.<\/p>\n<p> \u041d\u0430\u0440\u0430\u0449\u0438\u0432\u0430\u043d\u0438\u0435 (dilate): \u043d\u0430 \u043a\u0430\u0436\u0434\u0443\u044e \u0442\u043e\u0447\u043a\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043d\u0430\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u0430 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u044e\u0449\u0438\u0435 \u0442\u043e\u0447\u043a\u0438 \u0434\u043e\u0440\u0438\u0441\u043e\u0432\u044b\u0432\u0430\u044e\u0442\u0441\u044f => \u0437\u0430\u043a\u0440\u0430\u0448\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0434\u044b\u0440\u043a\u0438 \u043c\u0435\u043d\u044c\u0448\u0438\u0435, \u0447\u0435\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u0430 \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 \u0446\u0435\u043b\u043e\u043c \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0442\u043e\u043b\u0449\u0435.<\/p>\n<p> \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438\u0441\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u0438 \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043b\u0438\u043d\u0438\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p> \u0414\u0430\u043b\u0435\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u043b\u0438\u043d\u0438\u0438 \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u043c \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u043a \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u043c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e dilate():<\/p>\n<pre><code class=\"python\">def merge_lines(horizontal_lines, vertical_lines):     structuring_element = np.ones((3, 3), np.uint8)     merge_image = horizontal_lines + vertical_lines     merge_image = cv2.dilate(merge_image, structuring_element, iterations=2)     return merge_image<\/code><\/pre>\n<p> \u0412 \u0438\u0442\u043e\u0433\u0435  \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0443\u0434\u0430\u043b\u043e\u0441\u044c:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h3>\u041f\u043e\u0438\u0441\u043a \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u043f\u043e\u043b\u0435\u0439 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435<\/h3>\n<p> \u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u044c, \u0433\u0434\u0435 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043b\u044e\u0447\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0442\u044c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043b\u043e\u043d\u043a\u0438, <em>\u0430 <\/em>\u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f<em>&#8212;  <\/em>True\/False , True \u2014 \u0442\u0435 \u044f\u0447\u0435\u0439\u043a\u0438, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u043e\u0433\u0443\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c\u0441\u044f \u0447\u0438\u0441\u043b\u0430, False \u2014 \u044d\u0442\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0442\u0435 \u043f\u043e\u043b\u044f, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043c\u044b \u043d\u0435 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u0442\u044c. \u0412 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u0434\u043b\u044f \u043a\u043b\u044e\u0447\u0435\u0439, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 True, \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0431\u0443\u0434\u0435\u043c \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u043d\u043d\u044b\u043c\u0438 \u0447\u0438\u0441\u043b\u0430\u043c\u0438:<\/p>\n<pre><code class=\"python\">document_columns_dict = {     \"Name_0\": False, \"Account_0\": False, \"Account_1\": True,     \"Adress_0\": False, \"Adress_1\": False, \"Number_GVS_0\": False,     \"Number_GVS_1\": True, \"Number_GVS_2\": True, \"Number_GVS_3\": True,     \"GVS_0\": False, \"GVS_1\": True, \"GVS_2\": True, \"GVS_3\": True,     \"NUMBER_XVS_0\": False, \"NUMBER_XVS_1\": True, \"NUMBER_XVS_2\": True,     \"NUMBER_XVS_3\": True, \"XVS_0\": False, \"XVS_1\": True, \"XVS_2\": True,     \"XVS_3\": True, \"Date&amp;Phone_0\": False, \"Date&amp;Phone_1\": False,     \"Date&amp;Phone_2\": False, \"Date&amp;Phone_3\": False}<\/code><\/pre>\n<p> \u0414\u0430\u043b\u0435\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u0439\u0442\u0438 \u043a\u043e\u043d\u0442\u0443\u0440\u044b \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043e\u043b\u043e\u043d\u043a\u0438, \u0447\u0442\u043e \u043c\u044b \u0438  \u0434\u0435\u043b\u0430\u0435\u043c  \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 findContours(). \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u043a\u043e\u043d\u0442\u0443\u0440\u044b \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u0442\u0430\u043a\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0438\u0434\u0443\u0442 \u043f\u0430\u0440\u044b \u00ab\u043a\u043b\u044e\u0447-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u00bb \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435, \u0442\u043e \u0435\u0441\u0442\u044c \u0441\u0432\u0435\u0440\u0445\u0443 \u0432\u043d\u0438\u0437 \u0438 \u0441\u043b\u0435\u0432\u0430 \u043d\u0430\u043f\u0440\u0430\u0432\u043e:<\/p>\n<pre><code class=\"python\">bounding_boxes = [cv2.boundingRect(c) for c in cnts] if method == \"top-to-right\":     bounding_boxes.sort(key=functools.cmp_to_key(lambda s,                                                   t: custom_tuple_sorting(s, t, 4)))<\/code><\/pre>\n<p> \u0421\u043f\u0435\u0440\u0432\u0430  \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 boundingRect() \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0440\u0430\u043c\u043a\u0438 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0443\u0440\u0430: \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0435 x \u0438 y \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b, \u0437\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0442 \u0448\u0438\u0440\u0438\u043d\u0430 \u0438 \u0432\u044b\u0441\u043e\u0442\u0430 \u0440\u0430\u043c\u043a\u0438. \u0412 3 \u0441\u0442\u0440\u043e\u0447\u043a\u0435 \u043a\u043e\u0434\u0430 \u043c\u044b \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u043d\u0442\u0443\u0440\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 custom_tuple_sorting(), \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 <a href=\"https:\/\/github.com\/wb-08\/DocumentRecognize\/blob\/main\/document_recognize.py#L68\" rel=\"noopener noreferrer nofollow\">github<\/a><em> <\/em>. \u0414\u0430\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442 \u043a\u043e\u043d\u0442\u0443\u0440\u044b \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e \u0443, \u0430 \u043f\u043e\u0442\u043e\u043c \u043f\u043e x. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0435\u0440\u0432\u044b\u0445 \u0434\u0432\u0443\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044f  \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u043a\u043e\u043d\u0442\u0443\u0440\u0430, \u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c \u2014 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u044f\u0447\u0435\u0439\u043a\u0438 \u043c\u043e\u0433\u0443\u0442 \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c\u0441\u044f \u0432 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435, \u043d\u043e \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u043f\u043e y \u043c\u043e\u0433\u0443\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443, \u0435\u0441\u043b\u0438 \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430\u043c\u0438 \u043c\u0435\u043d\u044c\u0448\u0435 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044f, \u0442\u043e \u043c\u044b \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0442\u0430\u043a\u0438\u0435 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u0440\u0430\u0432\u043d\u044b\u043c\u0438 \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439. \u0422\u043e \u0435\u0441\u0442\u044c, \u0435\u0441\u043b\u0438 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0440\u0430\u0432\u043d\u043e 3, \u0442\u043e 34=35=36.  <\/p>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0448\u0430\u0433\u043e\u043c \u043c\u044b \u0432\u044b\u0440\u0435\u0437\u0430\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0443 \u044f\u0447\u0435\u0439\u043a\u0443 \u0441 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435 True:  <\/p>\n<pre><code class=\"python\">if list(document_columns_dict.values())[count]:     img_crop = rotated_image[y - 12:y + h + 12,                              x - 6:x + w + 6]<\/code><\/pre>\n<p> \u041d\u0430\u0445\u043e\u0434\u0438\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0440\u0430\u043c\u043a\u0438 \u0447\u0438\u0441\u0435\u043b:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p> \u041a\u0430\u043a \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u0432\u0438\u0434\u0435\u0442\u044c, \u0443 \u043d\u0430\u0441 \u043f\u043e\u044f\u0432\u0438\u043b\u043e\u0441\u044c \u0434\u0432\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b:<\/p>\n<ul>\n<li>\n<p> \u041d\u0430\u0448\u043b\u0438\u0441\u044c \u043d\u0435 \u0432\u0441\u0435 \u043a\u043e\u043d\u0442\u0443\u0440\u044b \u0447\u0438\u0441\u0435\u043b. \u042d\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u0447\u0438\u0441\u043b\u0430 \u0431\u044b\u043b\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u044b \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0431\u043b\u0438\u0437\u043a\u043e \u043a \u043d\u0438\u0436\u043d\u0435\u0439 \u043b\u0438\u043d\u0438\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u043c\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p> \u0423 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0446\u0438\u0444\u0440\u044b \u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u0434\u0432\u0430 \u043a\u043e\u043d\u0442\u0443\u0440\u0430.<\/p>\n<\/li>\n<\/ul>\n<p> \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0440\u0435\u0448\u0438\u0442\u044c \u043f\u0435\u0440\u0432\u0443\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443  \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u0439\u0442\u0438 \u0438 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0432\u0441\u0435 \u043f\u0438\u043a\u0441\u0435\u043b\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u043c\u043a\u0438 \u044f\u0447\u0435\u0439\u043a\u0438 \u0431\u0435\u043b\u044b\u043c\u0438 \u043f\u0438\u043a\u0441\u0435\u043b\u044f\u043c\u0438. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0432\u044b\u0440\u0435\u0437\u0430\u0435\u043c \u0442\u0430\u043a\u043e\u0439 \u0436\u0435 \u043a\u0443\u0441\u043e\u043a \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043d\u0430\u043c \u0432\u0435\u0440\u043d\u0443\u043b\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f merge_lines(), \u0433\u0434\u0435 \u043b\u0438\u043d\u0438\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u043c\u043a\u0438 \u0431\u0435\u043b\u043e\u0433\u043e \u0446\u0432\u0435\u0442\u0430:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p> \u0414\u0430\u043d\u043d\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e find_cell_contours(), \u0433\u0434\u0435 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435, \u0430 \u0432\u0442\u043e\u0440\u044b\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u2014 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u044b\u043b\u043e \u0432\u044b\u0440\u0435\u0437\u0430\u043d\u043e \u0441 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f. \u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u0447\u043a\u0435 \u043a\u043e\u0434\u0430 \u043c\u044b \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u0432\u0441\u0435\u0445 \u0431\u0435\u043b\u044b\u0445 \u043f\u0438\u043a\u0441\u0435\u043b\u0435\u0439 \u0443 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u044b\u043b\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043e \u043f\u0435\u0440\u0432\u044b\u043c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e  \u0438 \u0432 \u0446\u0438\u043a\u043b\u0435 \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u043c \u0446\u0432\u0435\u0442 \u043d\u0430 \u0431\u0435\u043b\u044b\u0439 \u0443 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u044b\u043b\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430, \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0442\u0435\u0445 \u043f\u0438\u043a\u0441\u0435\u043b\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u044b\u043b\u0438 \u0431\u0435\u043b\u044b\u043c\u0438 \u0443 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"python\">def find_cell_contours(frame_image, crop_image):     white_pixels = np.where(frame_image == 255)     y = white_pixels[0]     x = white_pixels[1]     for i in range(len(y)):         crop_image[y[i]][x[i]] = 255     return crop_image<\/code><\/pre>\n<p> \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0440\u0435\u0448\u0438\u0442\u044c \u0432\u0442\u043e\u0440\u0443\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u043c\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 permutations() \u043c\u043e\u0434\u0443\u043b\u044f itertools \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u0441\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u043a\u043e\u043d\u0442\u0443\u0440\u043e\u0432 \u0438 \u0435\u0441\u043b\u0438 \u043e\u043d\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0443\u0441\u043b\u043e\u0432\u0438\u044e \u0432 3 \u0441\u0442\u0440\u043e\u0447\u043a\u0435 \u043a\u043e\u0434\u0430 => \u043a\u043e\u043d\u0442\u0443\u0440 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043e\u043d\u0442\u0443\u0440\u0430 \u0438 \u043c\u044b \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u043d\u0442\u0443\u0440 \u0443\u0434\u0430\u043b\u044f\u0435\u043c:<\/p>\n<pre><code class=\"python\">def detect_contour_in_contours(all_contours):     for rec1, rec2 in itertools.permutations(all_contours, 2):         if rec2[0] >= rec1[0] and rec2[1] >= rec1[1]          and rec2[2] &lt;= rec1[2] and rec2[3] &lt;= rec1[3]:             in_rec = [rec2[0], rec2[1], rec2[2], rec2[3]]             all_contours.remove(in_rec)     return all_contours<\/code><\/pre>\n<p> \u041f\u043e\u0441\u043b\u0435 \u0432\u0441\u0435\u0445 \u0432\u044b\u0448\u0435\u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0440\u0435\u0448\u0438\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p><strong>\u0420\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u0435 \u0440\u0443\u043a\u043e\u043f\u0438\u0441\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u0432 \u044f\u0447\u0435\u0439\u043a\u0430\u0445<\/strong><\/p>\n<p> \u041d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u044f \u043d\u0435 \u0431\u0443\u0434\u0443 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e. \u0411\u044b\u043b\u0430 \u043e\u0431\u0443\u0447\u0435\u043d\u0430 \u0441\u0432\u0451\u0440\u0442\u043e\u0447\u043d\u0430\u044f <a href=\"https:\/\/github.com\/wb-08\/DocumentRecognize\/blob\/main\/network\/neural_network.py\" rel=\"noopener noreferrer nofollow\">\u043d\u0435\u0439\u0440\u043e\u043d\u043d\u0430\u044f \u0441\u0435\u0442\u044c<\/a> . \u0414\u0430\u0442\u0430\u0441\u0435\u0442 \u0431\u044b\u043b \u0432\u0437\u044f\u0442 <a href=\"https:\/\/github.com\/kensanata\/numbers\" rel=\"noopener noreferrer nofollow\">\u043e\u0442\u0441\u044e\u0434\u0430<\/a> .  \u0412 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435, \u0434\u043b\u044f \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u044b\u043b\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043e \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0439 \u0441\u043b\u043e\u0432\u0430\u0440\u0438\u043a:  <\/p>\n<pre><code class=\"python\">{'Name_0': False, 'Account_0': False, 'Account_1': '4204351220',   'Adress_0': False, 'Adress_1': False, 'Number_GVS_0': False,   'Number_GVS_1': '2353777',  'Number_GVS_2': '', 'Number_GVS_3': '',  'GVS_0': False, 'GVS_1': '16', 'GVS_2': '', 'GVS_3': '',  'NUMBER_XVS_0': False, 'NUMBER_XVS_1': '803',  'NUMBER_XVS_2': '',   'NUMBER_XVS_3': '', 'XVS_0': False, 'XVS_1': '41', 'XVS_2': '',   'XVS_3': '', 'Date&amp;Phone_0': False, 'Date&amp;Phone_1': False,   'Date&amp;Phone_2': False, 'Date&amp;Phone_3': False}<\/code><\/pre>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p> \u042f \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0432\u0430\u043c \u043f\u043e\u043d\u0440\u0430\u0432\u0438\u043b\u0430\u0441\u044c \u043c\u043e\u044f \u0441\u0442\u0430\u0442\u044c\u044f, \u0430 \u0437\u043d\u0430\u043d\u0438\u044f \u043f\u0440\u0438\u0433\u043e\u0434\u044f\u0442\u0441\u044f \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043f\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0443 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432. \u041a\u043e\u0434, \u043a\u0430\u043a \u0432\u0441\u0435\u0433\u0434\u0430, \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043d\u0430 <a href=\"https:\/\/github.com\/wb-08\/DocumentRecognize\" rel=\"noopener noreferrer nofollow\">github<\/a>.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/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\/articles\/568990\/\"> https:\/\/habr.com\/ru\/articles\/568990\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-397457","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/397457","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=397457"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/397457\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=397457"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=397457"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=397457"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}