{"id":12793,"date":"2023-02-08T10:00:00","date_gmt":"2023-02-08T01:00:00","guid":{"rendered":"https:\/\/www.gigas-jp.com\/appnews\/?p=12793"},"modified":"2023-02-08T10:35:28","modified_gmt":"2023-02-08T01:35:28","slug":"resizing-the-image-to-a-specific-width-and-height-with-opencv-in-python","status":"publish","type":"post","link":"https:\/\/www.gigas-jp.com\/appnews\/archives\/12793","title":{"rendered":"Resizing the image to a specific width and height with opencv in Python"},"content":{"rendered":"\n<p>Today, I would like to share a program for resizing the images to a specific width and height with opencv library in Python. Let\u2019s take a look.<\/p>\n\n\n\n<p>Opencv has resize method cv2.resize() to resize the images.<\/p>\n\n\n\n<p>We can resize the images simply as follows.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import cv2\n\n# read the input\nimg = cv2.imread('input.jpeg')\nheight, width, channel = img.shape\nprint(f\"Height and width of original image: {height}, {width}\")\n\n# resize the image\nnew_size = (450, 340) # (width, height)\nprint(f\"New height and width: {new_size&#091;1]}, {new_size&#091;0]}\")\nresize_img = cv2.resize(img, new_size)\n\ncv2.imshow('Original img', img)\ncv2.imshow('Resized img', resize_img)\n\ncv2.waitKey(0)<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>The program above will resize the input image and show original and resized images.<\/p>\n\n\n\n<p>Actually, cv2.resize() has other functionalities. Please study more about this. It is interesting.<\/p>\n\n\n\n<p>This is all for now. Hope you enjoy that.<\/p>\n\n\n\n<p>By Asahi<\/p>\n<div class='wp_social_bookmarking_light'>\n            <div class=\"wsbl_google_plus_one\"><g:plusone size=\"medium\" annotation=\"none\" href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/12793\" ><\/g:plusone><\/div>\n            <div class=\"wsbl_hatena_button\"><a href=\"\/\/b.hatena.ne.jp\/entry\/https:\/\/www.gigas-jp.com\/appnews\/archives\/12793\" class=\"hatena-bookmark-button\" data-hatena-bookmark-title=\"Resizing the image to a specific width and height with opencv in Python\" data-hatena-bookmark-layout=\"standard\" title=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\"> <img src=\"\/\/b.hatena.ne.jp\/images\/entry-button\/button-only@2x.png\" alt=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\" width=\"20\" height=\"20\" style=\"border: none;\" \/><\/a><script type=\"text\/javascript\" src=\"\/\/b.hatena.ne.jp\/js\/bookmark_button.js\" charset=\"utf-8\" async=\"async\"><\/script><\/div>\n            <div class=\"wsbl_twitter\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-url=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/12793\" data-text=\"Resizing the image to a specific width and height with opencv in Python\" data-via=\"GIGASJAPAN_APPS\" data-lang=\"ja\">Tweet<\/a><\/div>\n            <div class=\"wsbl_facebook_like\"><div id=\"fb-root\"><\/div><fb:like href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/12793\" layout=\"button_count\" action=\"like\" width=\"100\" share=\"false\" show_faces=\"false\" ><\/fb:like><\/div>\n            <div class=\"wsbl_facebook_send\"><div id=\"fb-root\"><\/div><fb:send href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/12793\" colorscheme=\"light\" ><\/fb:send><\/div>\n    <\/div>\n<br class='wp_social_bookmarking_light_clear' \/>\n","protected":false},"excerpt":{"rendered":"<p>Today, I would like to share a program for resizing the images to a specific width and height with opencv libr [&hellip;]<\/p>\n","protected":false},"author":20,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[100],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/12793"}],"collection":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/users\/20"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/comments?post=12793"}],"version-history":[{"count":1,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/12793\/revisions"}],"predecessor-version":[{"id":12795,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/12793\/revisions\/12795"}],"wp:attachment":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/media?parent=12793"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/categories?post=12793"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/tags?post=12793"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}