{"id":167,"date":"2019-01-15T22:45:13","date_gmt":"2019-01-15T14:45:13","guid":{"rendered":"http:\/\/www.yumefx.com\/?p=167"},"modified":"2021-03-04T11:28:10","modified_gmt":"2021-03-04T03:28:10","slug":"%e5%bc%b9%e5%b9%95%e5%90%9b%ef%bc%8c%e5%88%ab%e6%8c%a1%e7%9d%80%e6%88%91%e7%9c%8b%e5%b0%8f%e5%a7%90%e5%a7%90%ef%bc%81","status":"publish","type":"post","link":"https:\/\/www.yumefx.com\/?p=167","title":{"rendered":"\u5f39\u5e55\u541b\uff0c\u522b\u6321\u7740\u6211\u770b\u5c0f\u59d0\u59d0\uff01"},"content":{"rendered":"\n<h1 style=\"text-align: center;\">\u524d\u8a00<\/h1>\n<p>\u6700\u8fd1\u5728\u8865\u300a\u5410\u69fd\u5927\u4f1a\u300b\u7b2c\u4e09\u5b63\uff0c\u7a81\u7136\u53d1\u73b0\u5f39\u5e55\u4eec\u4f3c\u4e4e\u53d8\u5f97\u667a\u80fd\u4e86\uff0c\u80fd\u591f\u81ea\u52a8\u8bc6\u522b\u4eba\u7269\u524d\u666f\u548c\u80cc\u666f\uff0c\u4e0d\u4f1a\u518d\u906e\u6321\u4f4f\u4eba\u7269\uff0c\u770b\u8d77\u6765\u597d\u50cf\u4ece\u4eba\u7269\u8eab\u540e\u7a7f\u8fc7\u53bb\u4e00\u6837\u3002\u8fd9\u6837\u65e2\u4fdd\u7559\u4e86\u5f39\u5e55\u7684\u8da3\u5473\u6027\uff0c\u4e5f\u4e0d\u4f1a\u88ab\u906e\u4f4f\u753b\u9762\u4e2d\u7684\u91cd\u8981\u5185\u5bb9\u3002<\/p>\n<p><img loading=\"lazy\" class=\"size-full wp-image-1037 aligncenter\" src=\"http:\/\/www.yumefx.com\/wp-content\/uploads\/2019\/01\/zimu.png\" alt=\"\" width=\"1178\" height=\"605\" srcset=\"https:\/\/www.yumefx.com\/wp-content\/uploads\/2019\/01\/zimu.png 1178w, https:\/\/www.yumefx.com\/wp-content\/uploads\/2019\/01\/zimu-300x154.png 300w, https:\/\/www.yumefx.com\/wp-content\/uploads\/2019\/01\/zimu-768x394.png 768w, https:\/\/www.yumefx.com\/wp-content\/uploads\/2019\/01\/zimu-1024x526.png 1024w\" sizes=\"(max-width: 1178px) 100vw, 1178px\" \/><\/p>\n<p>\u672c\u6765\u6211\u4e5f\u53ea\u662f\u611f\u53f9\u4e00\u4e0b\u817e\u8baf\u89c6\u9891\u7684\u529f\u80fd\u5f3a\u5927\uff0c\u7ed3\u679c\u4e4b\u540e\u5728\u901b\u77e5\u4e4e\u65f6\u5076\u7136\u5237\u5230\u4e00\u4f4d\u5927\u4f6cCrossin\u7684\u6587\u7ae0<a href=\"https:\/\/zhuanlan.zhihu.com\/p\/54436238\">\u300a\u5f39\u5e55\u541b\uff0c\u522b\u6321\u7740\u6211\u770b\u5c0f\u59d0\u59d0\uff01\u300b<\/a>\uff08\u662f\u4e0d\u662f\u5f88\u719f\u6089\u7684\u540d\u5b57\uff1f\u6ca1\u9519\uff0c\u6211\u60f3\u4e0d\u5230\u4ec0\u4e48\u66f4\u597d\u7684\u540d\u5b57\uff0c\u5c31\u628a\u8fd9\u4f4d\u5927\u4f6c\u7684\u6587\u7ae0\u6807\u9898\u4e5f\u6284\u8fc7\u6765\u4e86\uff09\uff0c\u8bb2\u89e3\u4e86\u600e\u4e48\u901a\u8fc7Python\u5b9e\u73b0\u89c6\u9891\u7684\u524d\u666f\u8bc6\u522b\u548c\u6587\u5b57\u53e0\u52a0\u7b49\u529f\u80fd\u3002<\/p>\n<p>\u539f\u6765B\u7ad9\u8fd9\u4f4d\u5f39\u5e55\u7956\u5e08\u7f51\u7ad9\u4e5f\u652f\u6301\u4e86\u8fd9\u6837\u7684\u529f\u80fd\uff0c\u867d\u7136\u53ea\u6709\u90e8\u5206\u89c6\u9891\u5f00\u542f\u4e86\u8fd9\u4e2a\u529f\u80fd\uff0c\u4f30\u8ba1\u590d\u6742\u7684\u80cc\u666f\u53ef\u80fd\u4f1a\u5f71\u54cd\u8bc6\u522b\u6548\u679c\u3002<\/p>\n<p><img loading=\"lazy\" class=\"size-full wp-image-817 aligncenter\" src=\"http:\/\/www.yumefx.com\/wp-content\/uploads\/2019\/01\/bilizimu.png\" alt=\"\" width=\"638\" height=\"449\" srcset=\"https:\/\/www.yumefx.com\/wp-content\/uploads\/2019\/01\/bilizimu.png 638w, https:\/\/www.yumefx.com\/wp-content\/uploads\/2019\/01\/bilizimu-300x211.png 300w\" sizes=\"(max-width: 638px) 100vw, 638px\" \/><\/p>\n<h1>\u00a0<\/h1>\n<h1 style=\"text-align: center;\">\u5f00\u53d1\u73af\u5883\u5b89\u88c5<\/h1>\n<p>\u5148\u8bf4\u4e00\u4e0b\u4f1a\u7528\u5230\u54ea\u4e9b\u7b2c\u4e09\u65b9\u5e93\u548c\u4ed6\u4eec\u7684\u90e8\u7f72\u65b9\u6cd5\u5427\uff0c\u4ee5\u4e0b\u57fa\u4e8e<strong>Python3.5.3<\/strong>\u7248\u672c\u3002<\/p>\n<p>OpenCV\uff0c \u4e00\u4e2a\u7528\u4e8e\u56fe\u50cf\u5904\u7406\u3001\u5206\u6790\u3001\u673a\u5668\u89c6\u89c9\u65b9\u9762\u7684\u5f00\u6e90\u51fd\u6570\u5e93 \uff0c\u4e3b\u8981\u62ff\u6765\u63d0\u53d6\u753b\u9762\u5185\u5bb9\u5236\u4f5c\u8499\u7248\u3002<\/p>\n<p>PIL\uff0c\u7528\u4e8e\u7ed9\u56fe\u7247\u52a0\u6587\u5b57\u3002<\/p>\n<p>NumPy\uff0c\u652f\u6301\u5927\u91cf\u7684\u7ef4\u5ea6\u6570\u7ec4\u4e0e\u77e9\u9635\u8fd0\u7b97,\u6b64\u5916\u4e5f\u9488\u5bf9\u6570\u7ec4\u8fd0\u7b97\u63d0\u4f9b\u5927\u91cf\u7684\u6570\u5b66\u51fd\u6570\u5e93\u3002<\/p>\n<p>matplotlib\uff0c\u7528\u4e8e\u56fe\u50cf\u5904\u7406\u3002<\/p>\n\n\n\n<pre>\n<span>pip install opencv-python  <\/span>\n<span>pip install pillow<\/span>\n<span>python -m pip install --user numpy scipy matplotlib ipython jupyter pandas sympy nose<\/span>\n<\/pre>\n\n\n\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff1a<\/p>\n<p>1.PIL \u5e93\u5df2\u505c\u6b62\u7ef4\u62a4\uff0c\u65b0\u7684\u5e93\u53eb Pillow\uff0c\u4f46\u5728\u4f7f\u7528\u65f6\u4ecd\u7136\u662f\u00a0<strong>import PIL<\/strong>\u3002<\/p>\n<p>2.\u9ed8\u8ba4\u7684\u5b57\u4f53<strong>\u4e0d\u652f\u6301\u4e2d\u6587<\/strong>\uff0c\u56e0\u6b64\u9700\u8981\u63d0\u4f9b\u5b57\u4f53\u6587\u4ef6\u5e76\u6307\u5b9a\u3002<strong>py2<\/strong>\u00a0\u4e5f\u4e0d\u652f\u6301\u4e2d\u6587\uff0c\u9700\u8981\u989d\u5916\u4f7f\u7528\u00a0<strong>freetype<\/strong>\u00a0\u5e93\u3002<\/p>\n<p>3.OpenCV \u5e93\u7684 putText \u65b9\u6cd5\u4e5f\u53ef\u4ee5\u5b9e\u73b0\u7ed9\u56fe\u7247\u52a0\u6587\u5b57\uff0c\u4f46<strong>\u7f3a\u5c11\u5bf9\u4e2d\u6587\u7684\u652f\u6301<\/strong>\u3002<\/p>\n<h1>\u00a0<\/h1>\n<h1 style=\"text-align: center;\">\u4ee3\u7801<\/h1>\n<p>\u9996\u5148\u5236\u4f5c\u5f39\u5e55\u65b9\u9762\uff0c\u7ed9\u56fe\u7247\u52a0\u6587\u5b57\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre>\n<span>from PIL import Image, ImageDraw, ImageFont <\/span>\n<span><\/span>\n<span>setFont = ImageFont.truetype(r&quot;HKSNT.TTF&quot;, 50) #\u8bbe\u7f6e\u5b57\u4f53<\/span>\n<span>fillColor = &quot;#ff0000&quot;    #\u8bbe\u7f6e\u6587\u5b57\u989c\u8272 <\/span>\n<span>image = Image.open(&quot;timg.jpg&quot;) <\/span>\n<span>draw = ImageDraw.Draw(image)   #\u521b\u5efa\u7ed8\u56fe\u5bf9\u8c61<\/span>\n<span>width, height = image.size <\/span>\n<span>draw.text((40, height - 90), u&#x27;\u6587\u5b57\u6d4b\u8bd5\uff01\uff01&#x27;, font=setFont, fill=fillColor)    #\u5728\u56fe\u4e0a\u7ed8\u5236\u6587\u5b57<\/span>\n<span>image.save(&quot;out.jpg&quot;, &#x27;jpeg&#x27;)  #\u8f93\u51fa\u56fe\u7247<\/span>\n<\/pre>\n\n\n\n<p>\u63d0\u53d6\u56fe\u7247\u524d\u666f\u90e8\u5206\u6838\u5fc3\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre>\n<span>import numpy as np<\/span>\n<span>import cv2<\/span>\n<span><\/span>\n<span>mask = np.zeros(img.shape[:2],np.uint8) <\/span>\n<span>bgdModel = np.zeros((1,65),np.float64) <\/span>\n<span>fgdModel = np.zeros((1,65),np.float64) <\/span>\n<span>rect = (10, 10, img.shape[1]-10, img.shape[0]-10)<\/span>\n<span>cv2.grabCut(img,mask,rect,bgdModel,fgdModel,5,cv2.GC_INIT_WITH_RECT)<\/span>\n<\/pre>\n\n\n\n<p>\u6709\u4e86\u8499\u7248\u4e4b\u540e\uff0c\u5c31\u53ef\u4ee5\u5bf9\u56fe\u50cf\u8fdb\u884c\u8fd0\u7b97\u3002\u5206\u522b\u53d6\u51fa<strong>\u5e26\u5f39\u5e55\u56fe\u50cf\u7684\u80cc\u666f\u90e8\u5206<\/strong>\uff08\u5176\u5b9e\u76f4\u63a5\u62ff\u5e26\u5f39\u5e55\u56fe\u50cf\u5c31\u53ef\u4ee5\uff09\uff0c\u548c<strong>\u539f\u56fe\u50cf\u7684\u524d\u666f\u90e8\u5206<\/strong>\uff0c\u4e24\u4e2a\u53e0\u52a0\u4e00\u8d77\uff0c\u5c31\u662f\u6211\u4eec\u6700\u7ec8\u9700\u8981\u7684\u6548\u679c\u3002<\/p>\n\n\n\n<pre>\n<span>img = img * (1-mask)[:,:,np.newaxis] + img * mask[:,:,np.newaxis]<\/span>\n<\/pre>\n\n\n\n<h1>\u00a0<\/h1>\n<h1 style=\"text-align: center;\">\u6ce8\u610f<\/h1>\n<p>1. \u524d\u666f\u63d0\u53d6\u7684\u901f\u5ea6\u6bd4\u8f83\u6162\uff0c\u4e3a\u4e86\u80fd\u8fbe\u5230\u5b9e\u65f6\u6548\u679c\uff0c\u5728<strong>\u63d0\u53d6\u524d\u666f\u65f6\uff0c\u5c06\u56fe\u7247\u7f29\u5c0f\uff0c\u83b7\u53d6\u8499\u7248\u4e4b\u540e\uff0c\u518d\u5c06\u5176\u653e\u5927\u81f3\u539f\u5c3a\u5bf8<\/strong>\u3002\u8499\u7248\u4e0d\u9700\u8981\u592a\u9ad8\u7cbe\u5ea6\uff0c\u901a\u8fc7\u8fd9\u4e2a\u65b9\u6cd5\u5c31\u53ef\u4ee5\u505a\u5230\u5b9e\u65f6\u3002<\/p>\n<p>2. \u6bcf\u4e00\u5e27\u7684\u5904\u7406\u901f\u5ea6\u6709\u5feb\u6709\u6162\uff0c\u4e3a\u4e86\u7a33\u5b9a\u5e27\u7387\uff0c\u6211\u52a0\u5165\u4e86\u6bcf\u5e27\u65f6\u95f4\u7684\u8ba1\u7b97\uff0c<strong>\u5982\u679c\u65f6\u95f4\u4e0d\u8db3\u8bbe\u5b9a\u65f6\u957f\uff0c\u5c31 sleep \u5269\u4e0b\u7684\u65f6\u95f4<\/strong>\u3002<\/p>\n<p>3. \u4e00\u4e9b\u8fc7\u6e21\u5e27\u7684\u8bc6\u522b\u6548\u679c\u4f1a\u6bd4\u8f83\u5dee\uff0c\u5bfc\u81f4\u4e2d\u95f4\u5c11\u6570\u8499\u7248\u51fa\u73b0\u7c7b\u4f3c\u201c\u8df3\u5e27\u201d\u7684\u6548\u679c\u3002\u4e3a\u4e86\u5e73\u6ed1\u8fd9\u4e9b\u5e27\uff0c\u6211\u5728\u7a0b\u5e8f\u91cc\u8bb0\u5f55\u6bcf\u4e00\u5e27\u8499\u7248\u4e2d\u524d\u666f\u50cf\u7d20\u7684\u6570\u91cf\uff0c<strong>\u5982\u679c\u5f53\u524d\u5e27\u4e0e\u4e4b\u524d 20 \u5e27\u7684\u5e73\u5747\u503c\u5dee\u8ddd\u8d85\u8fc7 50%\uff0c\u90a3\u5c31\u8ba4\u4e3a\u8fd9\u4e00\u5e27\u7684\u524d\u666f\u63d0\u53d6\u4e0d\u5408\u683c\uff0c\u76f4\u63a5\u4f7f\u7528\u4e4b\u524d\u7684\u8499\u7248<\/strong>\u3002<\/p>\n<p><img loading=\"lazy\" class=\"size-full wp-image-834 aligncenter\" src=\"http:\/\/www.yumefx.com\/wp-content\/uploads\/2019\/01\/danmu_final.gif\" alt=\"\" width=\"392\" height=\"221\" \/><\/p>\n<p>\u5b8c\u6574\u7684\u4ee3\u7801\u592a\u957f\uff0c\u76f4\u63a5\u653e\u5927\u4f6c\u7684<a href=\"https:\/\/gitee.com\/crossin\/snippet\/tree\/master\/ai_barrage\">git\u5730\u5740<\/a>\u3002<\/p>\n<p><img loading=\"lazy\" class=\"size-full wp-image-913 aligncenter\" src=\"http:\/\/www.yumefx.com\/wp-content\/uploads\/2019\/01\/mobaidalao.jpg\" alt=\"\" width=\"140\" height=\"120\" \/><\/p>\n<p>\u00a0<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u603b\u6709\u4e9b\u4eba\u89c9\u5f97\u4f60\u600e\u4e48\u505a\u90fd\u4e0d\u5bf9\uff0c<\/p>\n<p>\u4e5f\u8bb8\u4f60\u552f\u4e00\u7684\u4e0d\u5bf9\u5c31\u662f\u7406\u4f1a\u4ed6\u4eec\u3002<\/p>\n<p style=\"text-align: right;\">\u300a\u8131\u7ebf\u68ee\u6797\u300b<\/p>\n<p style=\"text-align: right;\">\u2014\u2014\u72d0\u72f8\u963f\u5317<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00 \u6700\u8fd1\u5728\u8865\u300a\u5410\u69fd\u5927\u4f1a\u300b\u7b2c\u4e09\u5b63\uff0c\u7a81\u7136\u53d1\u73b0\u5f39\u5e55\u4eec\u4f3c\u4e4e\u53d8\u5f97\u667a\u80fd\u4e86\uff0c\u80fd\u591f\u81ea\u52a8\u8bc6\u522b\u4eba\u7269\u524d\u666f\u548c\u80cc\u666f\uff0c\u4e0d\u4f1a\u518d\u906e\u6321\u4f4f\u4eba\u7269\uff0c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":835,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[12,4],"tags":[37,15,26],"_links":{"self":[{"href":"https:\/\/www.yumefx.com\/index.php?rest_route=\/wp\/v2\/posts\/167"}],"collection":[{"href":"https:\/\/www.yumefx.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yumefx.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yumefx.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yumefx.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=167"}],"version-history":[{"count":0,"href":"https:\/\/www.yumefx.com\/index.php?rest_route=\/wp\/v2\/posts\/167\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.yumefx.com\/index.php?rest_route=\/wp\/v2\/media\/835"}],"wp:attachment":[{"href":"https:\/\/www.yumefx.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=167"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yumefx.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=167"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yumefx.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}