{"id":690,"date":"2021-08-07T08:01:43","date_gmt":"2021-08-06T23:01:43","guid":{"rendered":"https:\/\/www.thinqa.net\/?p=690"},"modified":"2021-08-07T08:01:44","modified_gmt":"2021-08-06T23:01:44","slug":"error-215assertion-failed-size-width0-size-height0-in-function-imshow","status":"publish","type":"post","link":"https:\/\/www.thinqa.net\/en\/2021\/08\/07\/690","title":{"rendered":"error: (-215:Assertion failed) size.width>0 &#038;&#038; size.height>0 in function &#8216;imshow&#8217;"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">I wanted to try OpenCV in python, so I thought I&#8217;d start with a simple image display\u2026 so I set up a simple script, but I immediately got an error.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p class=\"wp-block-paragraph\">\u300cerror: (-215:Assertion failed) size.width>0 &amp;&amp; size.height>0 in function &#8216;imshow&#8217;\u300d<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The script I ran (test.py) is as follows. It is very simple.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import cv2\nbgr = cv2.imread('\/home\/malt\/fruits.jpg')\n\ncv2.imshow(\"image\", bgr)\ncv2.waitKey()<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A quick google search revealed that the error occurred in line 4, imshow, as shown, but the image may not have been read in line 2, the first step.<br>The images for this sample were taken from a <a href=\"https:\/\/www.kkaneko.jp\/tools\/ubuntu\/opencv.html\">website,<\/a> but I made a mistake here.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><br><br>https:\/\/github.com\/opencv\/opencv\/blob\/master\/samples\/data\/fruits.jpg<br><br>I used wget to get it from the above, and the actual image file uri was the following.<br><br>https:\/\/raw.githubusercontent.com\/opencv\/opencv\/master\/samples\/data\/fruits.jpg<br><br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It was a mistake.<br>When I checked the first file I got, I found that it could not be opened as an image, so I used wget to get it again and ran the above script.<br>This time, the image was displayed correctly.<br>By the way, this sample script has &#8220;waitKey()&#8221; at the end, so if you activate the window with the image shown below and press any key, the script will exit.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"551\" src=\"https:\/\/www.thinqa.net\/wp-content\/uploads\/2020\/05\/opencv_imshow.jpg\" alt=\"\" class=\"wp-image-572\" srcset=\"https:\/\/www.thinqa.net\/wp-content\/uploads\/2020\/05\/opencv_imshow.jpg 600w, https:\/\/www.thinqa.net\/wp-content\/uploads\/2020\/05\/opencv_imshow-300x276.jpg 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>I wanted to try OpenCV in python, so I thought I&#8217;d start with a simple image display\u2026 so I set up a simple script, but I immediately got an error.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_locale":"en_US","_original_post":"https:\/\/www.thinqa.net\/?p=571","footnotes":""},"categories":[2],"tags":[35],"class_list":["post-690","post","type-post","status-publish","format-standard","hentry","category-it","tag-python","en-US"],"_links":{"self":[{"href":"https:\/\/www.thinqa.net\/wp-json\/wp\/v2\/posts\/690","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.thinqa.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.thinqa.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.thinqa.net\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.thinqa.net\/wp-json\/wp\/v2\/comments?post=690"}],"version-history":[{"count":1,"href":"https:\/\/www.thinqa.net\/wp-json\/wp\/v2\/posts\/690\/revisions"}],"predecessor-version":[{"id":691,"href":"https:\/\/www.thinqa.net\/wp-json\/wp\/v2\/posts\/690\/revisions\/691"}],"wp:attachment":[{"href":"https:\/\/www.thinqa.net\/wp-json\/wp\/v2\/media?parent=690"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.thinqa.net\/wp-json\/wp\/v2\/categories?post=690"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.thinqa.net\/wp-json\/wp\/v2\/tags?post=690"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}