{"id":213,"date":"2021-02-27T18:24:18","date_gmt":"2021-02-27T10:24:18","guid":{"rendered":"http:\/\/madapapa.com\/wordpress\/?p=213"},"modified":"2021-02-27T22:27:23","modified_gmt":"2021-02-27T14:27:23","slug":"cv2imshow-crashes-kernel","status":"publish","type":"post","link":"http:\/\/madapapa.com\/wordpress\/?p=213","title":{"rendered":"cv2.imshow() crashes Kernel"},"content":{"rendered":"<h2 id=\"toc_0\">\u7528pyplot.imshow\u53d6\u4ee3cv2.imshow<\/h2>\n<p>\u6211\u5728\u8fd0\u884ccv2.imshow\u548cdestroyAllWindows\u65f6\uff0cJupyter notebook\u51fa\u73b0\u5982\u4e0b\u544a\u8b66\uff0c\u7136\u540eVisual studio code\u5d29\u6e83\uff0c\u5fc5\u987b\u91cd\u542f\u624d\u80fd\u6b63\u5e38\u3002<\/p>\n<pre><code class=\"language-text\">Error: Direct kernel connection broken\n<\/code><\/pre>\n<p>githhub\u4e0a\u5206\u6790\u8fd9\u4e0d\u662fnotebook\u95ee\u9898\uff0c\u5e94\u8be5\u4e0eipython\u6216ipykernel\u6709\u5173\u3002<\/p>\n<p>\u540e\u6765\u91c7\u7528matplotlib\u7684pyplot\u51fd\u6570\uff0c\u6548\u679c\u66f4\u597d<\/p>\n<pre><code class=\"language-text\">%matplotlib inline\nfrom matplotlib import pyplot as plt\nimg1 = cv2.imread(&quot;ls.jpg&quot;)\nplt.imshow(img1)\nplt.show()\n\n<\/code><\/pre>\n<p><img decoding=\"async\" src=\"http:\/\/madapapa.com\/wordpress\/wp-content\/uploads\/2021\/02\/Screen-Shot-2021-02-27-at-6.31.42-PM.png\" alt=\"Screen Shot 2021-02-27 at 6.31.42 PM\"\/><\/p>\n<h2 id=\"toc_1\">cv2\u662fBGR\u4e0epyplot\u662fRGB<\/h2>\n<p>\u4e3a\u4ec0\u4e48\u4e0a\u56fe\u4eba\u8138\u53d1\u84dd\uff0c\u56e0\u4e3a\u56fe\u7247\u662f\u7528cv2\u8bfb\u53d6\u7684\uff0c\u989c\u8272\u987a\u5e8f\u662fBGR\uff0c\u800cpyplot\u662fRGB\uff0c\u56e0\u6b64\u9700\u8981\u505a\u4e00\u4e2a\u8f6c\u6362\u3002<\/p>\n<pre><code class=\"language-text\">plt.imshow(cv2.cvtColor(img1, cv2.COLOR_BGR2RGB))\n#plt.imshow(img1)\nplt.show()\n<\/code><\/pre>\n<p><img decoding=\"async\" src=\"http:\/\/madapapa.com\/wordpress\/wp-content\/uploads\/2021\/02\/Screen-Shot-2021-02-27-at-10.26.00-PM.png\" alt=\"Screen Shot 2021-02-27 at 10.26.00 PM\"\/><br \/>\n<img decoding=\"async\" src=\"http:\/\/madapapa.com\/wordpress\/wp-content\/uploads\/2021\/02\/Screen-Shot-2021-02-27-at-10.25.46-PM.png\" alt=\"Screen Shot 2021-02-27 at 10.25.46 PM\"\/><\/p>\n<p>\u53c2\u8003<br \/>\n<a href=\"https:\/\/stackoverflow.com\/questions\/43943333\/cv2-imshow-crashes-kernel\">stackoverflow<\/a><br \/>\n<a href=\"https:\/\/github.com\/jupyter\/notebook\/issues\/3935\">github<\/a><br \/>\n<a href=\"https:\/\/www.jb51.net\/article\/185397.htm\">BGR2RGB<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7528pyplot.imshow\u53d6\u4ee3cv2.imshow \u6211\u5728\u8fd0\u884ccv2.imshow\u548cdestroyAllWindows\u65f6\uff0cJupyter notebook\u51fa\u73b0\u5982\u4e0b\u544a\u8b66\uff0c\u7136\u540eVisual studio code\u5d29\u6e83\uff0c\u5fc5\u987b\u91cd\u542f\u624d\u80fd\u6b63\u5e38\u3002 Error: Direct kernel connection broken githhub\u4e0a\u5206\u6790\u8fd9\u4e0d\u662fnotebook\u95ee\u9898\uff0c\u5e94\u8be5\u4e0eipython\u6216ipykernel\u6709\u5173\u3002 \u540e\u6765\u91c7\u7528matplotlib\u7684pyplot\u51fd\u6570\uff0c\u6548\u679c\u66f4\u597d %matplotlib inline from matplotlib import pyplot as plt img1 = cv2.imread(&quot;ls.jpg&quot;) plt.imshow(img1) plt.show() cv2\u662fBGR\u4e0epyplot\u662fRGB \u4e3a\u4ec0\u4e48\u4e0a\u56fe\u4eba\u8138\u53d1\u84dd\uff0c\u56e0\u4e3a\u56fe\u7247\u662f\u7528cv2\u8bfb\u53d6\u7684\uff0c\u989c\u8272\u987a\u5e8f\u662fBGR\uff0c\u800cpyplot\u662fRGB\uff0c\u56e0\u6b64\u9700\u8981\u505a\u4e00\u4e2a\u8f6c\u6362\u3002 plt.imshow(cv2.cvtColor(img1, cv2.COLOR_BGR2RGB)) #plt.imshow(img1) plt.show() \u53c2\u8003 stackoverflow github BGR2RGB<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"categories":[1],"tags":[38,37],"class_list":["post-213","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-imshow","tag-matplotlib"],"_links":{"self":[{"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/213","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=213"}],"version-history":[{"count":2,"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/213\/revisions"}],"predecessor-version":[{"id":217,"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/213\/revisions\/217"}],"wp:attachment":[{"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=213"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}