{"id":219,"date":"2021-03-06T14:07:44","date_gmt":"2021-03-06T06:07:44","guid":{"rendered":"http:\/\/madapapa.com\/wordpress\/?p=219"},"modified":"2021-03-06T19:01:57","modified_gmt":"2021-03-06T11:01:57","slug":"pltshow-wu-fa-xian-shi-tu-pianimread-yurandomrandi","status":"publish","type":"post","link":"http:\/\/madapapa.com\/wordpress\/?p=219","title":{"rendered":"plt.show\u65e0\u6cd5\u663e\u793a\u56fe\u7247\uff0cimread\u4e0erandom.randint\u751f\u6210narray\u6570\u7ec4\u7684\u533a\u522b"},"content":{"rendered":"<p>\u4f7f\u7528np.random.randint\u751f\u6210\u4e86\u6570\u7ec4\uff0c\u4f46\u662f\u6ca1\u6cd5\u50cf\u8bfb\u53d6\u56fe\u50cf\u540e\u751f\u6210\u7684\u6570\u7ec4\uff0c\u4f7f\u7528plt.show\u663e\u793a\u56fe\u7247\u663e\u793a\u5982\u4e0b\u9519\u8bef\uff08\u4f30\u8ba1\u4f7f\u7528pil\u56fe\u50cf\u4e5f\u662f\u5982\u6b64\uff09<\/p>\n<pre><code class=\"language-text\">&gt; Unsupported depth of input image:\n&gt;     &#39;VDepth::contains(depth)&#39;\n&gt; where\n&gt;     &#39;depth&#39; is 4 (CV_32S)\n<\/code><\/pre>\n<p>\u521d\u6b65\u5206\u6790\uff0c\u5e94\u8be5\u662f\u4e0e\u6570\u636e\u7c7b\u578b\u76f8\u5173<\/p>\n<h2 id=\"toc_0\">\u5bf9\u6bd4imread\u4e0erandint\u751f\u6210\u6570\u7ec4\u7684\u6570\u636e\u7c7b\u578b<\/h2>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u770b\u4f7f\u7528randint\u751f\u6210\u7684\u6570\u7ec4\u6570\u636e\u7c7b\u578b<\/p>\n<pre><code class=\"language-text\">img4Random = np.random.randint(0,256,1200,dtype= &#39;i&#39;)\nbgrImg4Random  = img4Random.reshape(20,20,3)\n<\/code><\/pre>\n<p>\u8fd9\u91cc\u751f\u6210\u7684\u6570\u7ec4\uff0c\u6bcf\u4e2a\u5143\u7d20\u7684\u8303\u56f4\u662f\u4ece0\uff5e255\uff0c\u4f46\u662f\u6570\u636e\u7c7b\u578b\u662fint32\uff08dtype=\u2018i\u2019\uff09<\/p>\n<pre><code class=\"language-text\">print(bgrImg4Random[0,0])\nprint(bgrImg4Random[0,0,0])\nprint(bgrImg4Random[0,0,1])\nprint(bgrImg4Random[0,0,2])\ntype(bgrImg4Random[0,0,2])\n<\/code><\/pre>\n<p>\u663e\u793a\u7ed3\u679c\u5982\u4e0b<\/p>\n<pre><code class=\"language-text\">[ 20 103  51]\n20\n103\n51\nnumpy.int32\n<\/code><\/pre>\n<p>\u5982\u679c\u7701\u7565dtype\u53c2\u6570\uff0c\u9ed8\u8ba4\u6570\u636e\u7c7b\u578b\u662fint64<\/p>\n<pre><code class=\"language-text\">img4Random = np.random.randint(0,256,1200)\n<\/code><\/pre>\n<p>\u663e\u793a\u7ed3\u679c\u5982\u4e0b<\/p>\n<pre><code class=\"language-text\">numpy.int64\n<\/code><\/pre>\n<p>\u73b0\u5728\u6211\u4eec\u770b\u770b\u4ecejpg\u751f\u6210\u7684\u6570\u7ec4\u60c5\u51b5\uff0c\u5982\u4e0b<\/p>\n<pre><code class=\"language-text\">img1 = cv2.imread(&quot;ls.jpg&quot;)\nprint(img1[0,1,0])\ntype(img1[0,0,0])\n<\/code><\/pre>\n<p>\u6570\u636e\u7c7b\u578b\u662f unit8,\u4e5f\u53ef\u4ee5\u7528print(image1.dtype)\u6765\u663e\u793a\u6570\u636e\u7c7b\u578b<\/p>\n<pre><code class=\"language-text\">33\nnumpy.uint8\n<\/code><\/pre>\n<h2 id=\"toc_1\">\u8f6c\u6362\u6570\u7ec4\u7684\u6570\u636e\u7c7b\u578b<\/h2>\n<p>\u4f7f\u7528np.unit8\u6216\u8005astype\u4e24\u79cd\u65b9\u5f0f\u90fd\u53ef\u4ee5\u8fdb\u884c\u8f6c\u6362\u5230unit8<\/p>\n<pre><code class=\"language-text\">bgrImg4Random  = img4Random.reshape(20,20,3)\n#bgrImg4Random = np.uint8(bgrImg4Random)\n#bgrImg4Random=bgrImg4Random.astype(np.uint8)\n<\/code><\/pre>\n<p>\u56fe\u50cf\u663e\u793a\u51fa\u6765\u4e86\uff0c\u968f\u673a\u76843\u901a\u9053\u56fe\u50cf\uff0c20*20\u4e2a\u50cf\u7d20<br \/>\n<img decoding=\"async\" src=\"http:\/\/madapapa.com\/wordpress\/wp-content\/uploads\/2021\/03\/Screen-Shot-2021-03-06-at-2.37.07-PM.png\" alt=\"Screen Shot 2021-03-06 at 2.37.07 PM\"\/><\/p>\n<h2 id=\"toc_2\">\u53c2\u8003<\/h2>\n<p><a href=\"https:\/\/zhidao.baidu.com\/question\/2144595633168621188.html\">\u6570\u636e\u8bfb\u5165\u5c31\u662funit8\uff0c\u4f7f\u7528np.unit8\u8f6c\u6362<\/a>\uff0c\u8fd9\u91cc\u4ecb\u7ecd\u4e86pil\u56fe\u50cf\uff0c\u6682\u65f6\u6211\u6ca1\u6709\u4f7f\u7528\u8fc7\uff1b<br \/>\n<a href=\"https:\/\/blog.csdn.net\/weixin_34272308\/article\/details\/85991650\">\u89e3\u91caopencv\u7070\u5ea6\u56fe\u548cRGB\u56fe\u6570\u636e\u7c7b\u578b<\/a>\uff0cint\u662f32\u4f4d\uff0c\u800c8\u4f4d\u5c31\u8db3\u591f\u4e86\uff0c\u91c7\u7528int\u4f1a\u6d6a\u8d39\u5b58\u50a8\u7a7a\u95f4\u3002<br \/>\n<a href=\"https:\/\/blog.csdn.net\/qq_39751320\/article\/details\/104849194\">\u4ecb\u7ecdopencv\u5904\u7406\u56fe\u50cf\u4f7f\u7528unit8<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528np.random.randint\u751f\u6210\u4e86\u6570\u7ec4\uff0c\u4f46\u662f\u6ca1\u6cd5\u50cf\u8bfb\u53d6\u56fe\u50cf\u540e\u751f\u6210\u7684\u6570\u7ec4\uff0c\u4f7f\u7528plt.show\u663e\u793a\u56fe\u7247\u663e\u793a\u5982\u4e0b\u9519\u8bef\uff08\u4f30\u8ba1\u4f7f\u7528pil\u56fe\u50cf\u4e5f\u662f\u5982\u6b64\uff09 &gt; Unsupported depth of input image: &gt; &#39;VDepth::contains(depth)&#39; &gt; where &gt; &#39;depth&#39; is 4 (CV_32S) \u521d\u6b65\u5206\u6790\uff0c\u5e94\u8be5\u662f\u4e0e\u6570\u636e\u7c7b\u578b\u76f8\u5173 \u5bf9\u6bd4imread\u4e0erandint\u751f\u6210\u6570\u7ec4\u7684\u6570\u636e\u7c7b\u578b \u9996\u5148\uff0c\u6211\u4eec\u770b\u4f7f\u7528randint\u751f\u6210\u7684\u6570\u7ec4\u6570\u636e\u7c7b\u578b img4Random = np.random.randint(0,256,1200,dtype= &#39;i&#39;) bgrImg4Random = img4Random.reshape(20,20,3) \u8fd9\u91cc\u751f\u6210\u7684\u6570\u7ec4\uff0c\u6bcf\u4e2a\u5143\u7d20\u7684\u8303\u56f4\u662f\u4ece0\uff5e255\uff0c\u4f46\u662f\u6570\u636e\u7c7b\u578b\u662fint32\uff08dtype=\u2018i\u2019\uff09 print(bgrImg4Random[0,0]) print(bgrImg4Random[0,0,0]) print(bgrImg4Random[0,0,1]) print(bgrImg4Random[0,0,2]) type(bgrImg4Random[0,0,2]) \u663e\u793a\u7ed3\u679c\u5982\u4e0b [ 20 103 51] 20 103 51 numpy.int32 \u5982\u679c\u7701\u7565dtype\u53c2\u6570\uff0c\u9ed8\u8ba4\u6570\u636e\u7c7b\u578b\u662fint64 img4Random = np.random.randint(0,256,1200) \u663e\u793a\u7ed3\u679c\u5982\u4e0b numpy.int64 \u73b0\u5728\u6211\u4eec\u770b\u770b\u4ecejpg\u751f\u6210\u7684\u6570\u7ec4\u60c5\u51b5\uff0c\u5982\u4e0b img1 = cv2.imread(&quot;ls.jpg&quot;) print(img1[0,1,0]) type(img1[0,0,0]) \u6570\u636e\u7c7b\u578b\u662f unit8,\u4e5f\u53ef\u4ee5\u7528print(image1.dtype)\u6765\u663e\u793a\u6570\u636e\u7c7b\u578b &hellip; <a href=\"http:\/\/madapapa.com\/wordpress\/?p=219\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">plt.show\u65e0\u6cd5\u663e\u793a\u56fe\u7247\uff0cimread\u4e0erandom.randint\u751f\u6210narray\u6570\u7ec4\u7684\u533a\u522b<\/span><\/a><\/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":[5],"tags":[31],"class_list":["post-219","post","type-post","status-publish","format-standard","hentry","category-linux","tag-opencv"],"_links":{"self":[{"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/219","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=219"}],"version-history":[{"count":2,"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/219\/revisions"}],"predecessor-version":[{"id":221,"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/219\/revisions\/221"}],"wp:attachment":[{"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=219"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}