{"id":7134,"date":"2023-08-14T05:10:24","date_gmt":"2023-08-14T13:10:24","guid":{"rendered":"https:\/\/live-cometml.pantheonsite.io\/?p=7134"},"modified":"2025-04-24T17:14:45","modified_gmt":"2025-04-24T17:14:45","slug":"opencv-python-cheat-sheet-from-importing-images-to-face-detection","status":"publish","type":"post","link":"https:\/\/www.comet.com\/site\/blog\/opencv-python-cheat-sheet-from-importing-images-to-face-detection\/","title":{"rendered":"OpenCV-Python Cheat Sheet: From Importing Images to Face Detection"},"content":{"rendered":"\n<link rel=\"canonical\" href=\"https:\/\/www.comet.com\/site\/blog\/opencv-python-cheat-sheet-from-importing-images-to-face-detection\">\n\n\n\n<div class=\"fh fi fj fk fl\">\n<figure><img loading=\"lazy\" decoding=\"async\" class=\"bg mm mn c\" role=\"presentation\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:2000\/1*77qCS1xRajFADWdT50c2dg.jpeg\" alt=\"\" width=\"2000\" height=\"1500\"><\/figure><div class=\"mg bg\">\n<figure class=\"mh mi mj mk ml mg bg paragraph-image\"><picture><\/picture><\/figure>\n<\/div>\n<div class=\"ab ca\">\n<div class=\"ch bg et eu ev ew\">\n<h1 id=\"913b\" class=\"mo mp fo be mq mr ms go mt mu mv gr mw mx my mz na nb nc nd ne nf ng nh ni nj bj\" data-selectable-paragraph=\"\">What is OpenCV-Python?<\/h1>\n<p id=\"560a\" class=\"pw-post-body-paragraph nk nl fo be b gm nm nn no gp np nq nr ns nt nu nv nw nx ny nz oa ob oc od oe fh bj\" data-selectable-paragraph=\"\">OpenCV is an open source <a class=\"af of\" href=\"https:\/\/www.comet.com\/site\/blog\/the-5-computer-vision-techniques-that-will-change-how-you-see-the-world\/\" target=\"_blank\" rel=\"noopener ugc nofollow\">computer vision<\/a> and machine learning library. It has 2500+ optimized algorithms\u2014a comprehensive set of both classic and state-of-the-art computer vision and machine learning algorithms. It has many interfaces, including Python, Java, C++, and Matlab.<\/p>\n<p id=\"b560\" class=\"pw-post-body-paragraph nk nl fo be b gm og nn no gp oh nq nr ns oi nu nv nw oj ny nz oa ok oc od oe fh bj\" data-selectable-paragraph=\"\">Here, we\u2019re gonna tackle the Python interface.<\/p>\n<h2 id=\"9773\" class=\"ol mp fo be mq om on oo mt op oq or mw ns os ot ou nw ov ow ox oa oy oz pa pb bj\" data-selectable-paragraph=\"\">Table of Contents<\/h2>\n<ul class=\"\">\n<li id=\"e56c\" class=\"nk nl fo be b gm nm nn no gp np nq nr pc nt nu nv pd nx ny nz pe ob oc od oe pf pg ph bj\" data-selectable-paragraph=\"\">Installation<\/li>\n<li id=\"2c48\" class=\"nk nl fo be b gm pi nn no gp pj nq nr pc pk nu nv pd pl ny nz pe pm oc od oe pf pg ph bj\" data-selectable-paragraph=\"\">Importing\/Viewing an Image<\/li>\n<li id=\"38ed\" class=\"nk nl fo be b gm pi nn no gp pj nq nr pc pk nu nv pd pl ny nz pe pm oc od oe pf pg ph bj\" data-selectable-paragraph=\"\">Cropping<\/li>\n<li id=\"a738\" class=\"nk nl fo be b gm pi nn no gp pj nq nr pc pk nu nv pd pl ny nz pe pm oc od oe pf pg ph bj\" data-selectable-paragraph=\"\">Resizing<\/li>\n<li id=\"575f\" class=\"nk nl fo be b gm pi nn no gp pj nq nr pc pk nu nv pd pl ny nz pe pm oc od oe pf pg ph bj\" data-selectable-paragraph=\"\">Rotating<\/li>\n<li id=\"5f81\" class=\"nk nl fo be b gm pi nn no gp pj nq nr pc pk nu nv pd pl ny nz pe pm oc od oe pf pg ph bj\" data-selectable-paragraph=\"\">Grayscaling and Thresholding<\/li>\n<li id=\"d29f\" class=\"nk nl fo be b gm pi nn no gp pj nq nr pc pk nu nv pd pl ny nz pe pm oc od oe pf pg ph bj\" data-selectable-paragraph=\"\">Blurring\/Smoothing<\/li>\n<li id=\"de21\" class=\"nk nl fo be b gm pi nn no gp pj nq nr pc pk nu nv pd pl ny nz pe pm oc od oe pf pg ph bj\" data-selectable-paragraph=\"\">Drawing a Rectangle\/Bounding Box<\/li>\n<li id=\"a021\" class=\"nk nl fo be b gm pi nn no gp pj nq nr pc pk nu nv pd pl ny nz pe pm oc od oe pf pg ph bj\" data-selectable-paragraph=\"\">Drawing a Line<\/li>\n<li id=\"9b6e\" class=\"nk nl fo be b gm pi nn no gp pj nq nr pc pk nu nv pd pl ny nz pe pm oc od oe pf pg ph bj\" data-selectable-paragraph=\"\">Writing on an Image<\/li>\n<li id=\"b0e5\" class=\"nk nl fo be b gm pi nn no gp pj nq nr pc pk nu nv pd pl ny nz pe pm oc od oe pf pg ph bj\" data-selectable-paragraph=\"\">Face Detection<\/li>\n<li id=\"0c09\" class=\"nk nl fo be b gm pi nn no gp pj nq nr pc pk nu nv pd pl ny nz pe pm oc od oe pf pg ph bj\" data-selectable-paragraph=\"\">Contours\u2014A Method for Object Detection<\/li>\n<li id=\"c980\" class=\"nk nl fo be b gm pi nn no gp pj nq nr pc pk nu nv pd pl ny nz pe pm oc od oe pf pg ph bj\" data-selectable-paragraph=\"\">Saving an Image<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"fh fi fj fk fl\">\n<div class=\"ab ca\">\n<div class=\"ch bg et eu ev ew\">\n<h1 id=\"4140\" class=\"mo mp fo be mq mr pv go mt mu pw gr mw mx px mz na nb py nd ne nf pz nh ni nj bj\" data-selectable-paragraph=\"\">Installation<\/h1>\n<ul class=\"\">\n<li id=\"9446\" class=\"nk nl fo be b gm nm nn no gp np nq nr pc nt nu nv pd nx ny nz pe ob oc od oe pf pg ph bj\" data-selectable-paragraph=\"\">For Windows, find the guide <a class=\"af of\" href=\"https:\/\/opencv-python-tutroals.readthedocs.io\/en\/latest\/py_tutorials\/py_setup\/py_setup_in_windows\/py_setup_in_windows.html\" target=\"_blank\" rel=\"noopener ugc nofollow\">here<\/a>.<\/li>\n<li id=\"be15\" class=\"nk nl fo be b gm pi nn no gp pj nq nr pc pk nu nv pd pl ny nz pe pm oc od oe pf pg ph bj\" data-selectable-paragraph=\"\">For Linux, find the guide <a class=\"af of\" href=\"https:\/\/docs.opencv.org\/trunk\/d7\/d9f\/tutorial_linux_install.html\" target=\"_blank\" rel=\"noopener ugc nofollow\">here<\/a>.<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"fh fi fj fk fl\">\n<div class=\"ab ca\">\n<div class=\"ch bg et eu ev ew\">\n<h1 id=\"f52a\" class=\"mo mp fo be mq mr pv go mt mu pw gr mw mx px mz na nb py nd ne nf pz nh ni nj bj\" data-selectable-paragraph=\"\">Importing an Image &amp; Viewing it<\/h1>\n<pre class=\"mh mi mj mk ml qa qb qc qd ax qe bj\"><span id=\"4065\" class=\"ol mp fo qb b ia qf qg l iq qh\" data-selectable-paragraph=\"\">import cv2\nimage = cv2.imread(\".\/Path\/To\/Image.extension\")\ncv2.imshow(\"Image\", image)\ncv2.waitKey(0)\ncv2.destroyAllWindows()<\/span><\/pre>\n<p id=\"97db\" class=\"pw-post-body-paragraph nk nl fo be b gm og nn no gp oh nq nr ns oi nu nv nw oj ny nz oa ok oc od oe fh bj\" data-selectable-paragraph=\"\"><strong class=\"be qi\">Warning 1:<\/strong> On reading images this way via openCV, it isn\u2019t in <strong class=\"be qi\"><em class=\"qj\">RGB<\/em><\/strong> colorspace\u2014it\u2019s in <strong class=\"be qi\"><em class=\"qj\">BGR<\/em><\/strong>. Sometime this won\u2019t be an issue with you, <strong class=\"be qi\">you\u2019ll only have trouble if you want to add something colored to your image.<br>\n<\/strong>There are two solutions:<\/p>\n<ol class=\"\">\n<li id=\"5621\" class=\"nk nl fo be b gm og nn no gp oh nq nr pc oi nu nv pd oj ny nz pe ok oc od oe qk pg ph bj\" data-selectable-paragraph=\"\">Switch the <strong class=\"be qi\"><em class=\"qj\">R \u2014 1st one<\/em><\/strong>(red) with the <strong class=\"be qi\"><em class=\"qj\">B \u2014 3rd one<\/em><\/strong>(blue), so that Red is <em class=\"qj\">(<\/em><strong class=\"be qi\"><em class=\"qj\">0<\/em><\/strong><em class=\"qj\">,0,<\/em><strong class=\"be qi\"><em class=\"qj\">255<\/em><\/strong><em class=\"qj\">)<\/em> instead of <em class=\"qj\">(<\/em><strong class=\"be qi\"><em class=\"qj\">255<\/em><\/strong><em class=\"qj\">,0,<\/em><strong class=\"be qi\"><em class=\"qj\">0<\/em><\/strong><em class=\"qj\">)<\/em>.<\/li>\n<li id=\"fcf4\" class=\"nk nl fo be b gm pi nn no gp pj nq nr pc pk nu nv pd pl ny nz pe pm oc od oe qk pg ph bj\" data-selectable-paragraph=\"\">Change the colorspace to <strong class=\"be qi\">RGB<\/strong>:<\/li>\n<\/ol>\n<pre class=\"mh mi mj mk ml qa qb qc qd ax qe bj\"><span id=\"f685\" class=\"ol mp fo qb b ia qf qg l iq qh\" data-selectable-paragraph=\"\">rgb_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)<\/span><\/pre>\n<p id=\"a995\" class=\"pw-post-body-paragraph nk nl fo be b gm og nn no gp oh nq nr ns oi nu nv nw oj ny nz oa ok oc od oe fh bj\" data-selectable-paragraph=\"\">and go on with your code with <code class=\"cw ql qm qn qb b\">rgb_image<\/code> instead of <code class=\"cw ql qm qn qb b\">image<\/code><em class=\"qj\">.<\/em><\/p>\n<p id=\"dc4d\" class=\"pw-post-body-paragraph nk nl fo be b gm og nn no gp oh nq nr ns oi nu nv nw oj ny nz oa ok oc od oe fh bj\" data-selectable-paragraph=\"\"><strong class=\"be qi\">Warning 2: <\/strong>To close the window that\u2019s displaying the image, press any button.<strong class=\"be qi\">If you use the close button it may cause freezes<\/strong> (happens to me when I\u2019m on a Jupyter notebook).<\/p>\n<blockquote class=\"qo qp qq\"><p id=\"78ba\" class=\"nk nl qj be b gm og nn no gp oh nq nr pc oi nu nv pd oj ny nz pe ok oc od oe fh bj\" data-selectable-paragraph=\"\">For simplicity, throughout this tutorial I\u2019ll be using this method to view images:<\/p><\/blockquote>\n<pre class=\"mh mi mj mk ml qa qb qc qd ax qe bj\"><span id=\"41b8\" class=\"ol mp fo qb b ia qf qg l iq qh\" data-selectable-paragraph=\"\">import cv2\ndef viewImage(image, name_of_window):\n    cv2.namedWindow(name_of_window, cv2.WINDOW_NORMAL)\n    cv2.imshow(name_of_window, image)\n    cv2.waitKey(0)\n    cv2.destroyAllWindows()<\/span><\/pre>\n<\/div>\n<\/div>\n<div class=\"mg\">\n<div class=\"ab ca\">\n<div class=\"qr qs qt qu qv qw ce qx cf qy ch bg\">\n<figure class=\"mh mi mj mk ml mg rc rd paragraph-image\">\n<div class=\"re rf eb rg bg rh\" tabindex=\"0\" role=\"button\">\n<figure><img loading=\"lazy\" decoding=\"async\" class=\"bg mm mn c\" role=\"presentation\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:1000\/1*G0I556YQDMfy-sNRZ1qKXw.jpeg\" alt=\"\" width=\"1000\" height=\"627\"><\/figure><div class=\"qz ra rb\"><picture><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/format:webp\/1*G0I556YQDMfy-sNRZ1qKXw.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/format:webp\/1*G0I556YQDMfy-sNRZ1qKXw.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/format:webp\/1*G0I556YQDMfy-sNRZ1qKXw.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/format:webp\/1*G0I556YQDMfy-sNRZ1qKXw.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/format:webp\/1*G0I556YQDMfy-sNRZ1qKXw.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/format:webp\/1*G0I556YQDMfy-sNRZ1qKXw.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:2000\/format:webp\/1*G0I556YQDMfy-sNRZ1qKXw.jpeg 2000w\" type=\"image\/webp\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 1000px\"><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/1*G0I556YQDMfy-sNRZ1qKXw.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/1*G0I556YQDMfy-sNRZ1qKXw.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/1*G0I556YQDMfy-sNRZ1qKXw.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/1*G0I556YQDMfy-sNRZ1qKXw.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/1*G0I556YQDMfy-sNRZ1qKXw.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/1*G0I556YQDMfy-sNRZ1qKXw.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:2000\/1*G0I556YQDMfy-sNRZ1qKXw.jpeg 2000w\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 1000px\" data-testid=\"og\"><\/picture><\/div>\n<\/div><figcaption class=\"ri rj rk qz ra rl rm be b bf z dv\" data-selectable-paragraph=\"\">Source: <a class=\"af of\" href=\"http:\/\/pixabay.com\/\" target=\"_blank\" rel=\"noopener ugc nofollow\">Pixabay<\/a><\/figcaption><\/figure>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"fh fi fj fk fl\">\n<div class=\"ab ca\">\n<div class=\"ch bg et eu ev ew\">\n<h1 id=\"37ab\" class=\"mo mp fo be mq mr pv go mt mu pw gr mw mx px mz na nb py nd ne nf pz nh ni nj bj\" data-selectable-paragraph=\"\">Cropping<\/h1>\n<figure class=\"mh mi mj mk ml mg qz ra paragraph-image\">\n<div class=\"re rf eb rg bg rh\" tabindex=\"0\" role=\"button\">\n<figure><img loading=\"lazy\" decoding=\"async\" class=\"bg mm mn c\" role=\"presentation\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:700\/1*JOqAtM92uNHBxJ9uRAyKtg.jpeg\" alt=\"\" width=\"700\" height=\"467\"><\/figure><div class=\"qz ra rn\"><picture><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/format:webp\/1*JOqAtM92uNHBxJ9uRAyKtg.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/format:webp\/1*JOqAtM92uNHBxJ9uRAyKtg.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/format:webp\/1*JOqAtM92uNHBxJ9uRAyKtg.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/format:webp\/1*JOqAtM92uNHBxJ9uRAyKtg.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/format:webp\/1*JOqAtM92uNHBxJ9uRAyKtg.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/format:webp\/1*JOqAtM92uNHBxJ9uRAyKtg.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1400\/format:webp\/1*JOqAtM92uNHBxJ9uRAyKtg.jpeg 1400w\" type=\"image\/webp\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 700px\"><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/1*JOqAtM92uNHBxJ9uRAyKtg.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/1*JOqAtM92uNHBxJ9uRAyKtg.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/1*JOqAtM92uNHBxJ9uRAyKtg.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/1*JOqAtM92uNHBxJ9uRAyKtg.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/1*JOqAtM92uNHBxJ9uRAyKtg.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/1*JOqAtM92uNHBxJ9uRAyKtg.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*JOqAtM92uNHBxJ9uRAyKtg.jpeg 1400w\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 700px\" data-testid=\"og\"><\/picture><\/div>\n<\/div>\n<figcaption class=\"ri rj rk qz ra rl rm be b bf z dv\" data-selectable-paragraph=\"\">Source: Pixabay<\/figcaption>\n<\/figure>\n<figure class=\"mh mi mj mk ml mg qz ra paragraph-image\">\n<div class=\"re rf eb rg bg rh\" tabindex=\"0\" role=\"button\">\n<figure><img loading=\"lazy\" decoding=\"async\" class=\"bg mm mn c\" role=\"presentation\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:700\/1*UuTiqdGQFfvA78djIPwVYA.jpeg\" alt=\"\" width=\"700\" height=\"242\"><\/figure><div class=\"qz ra ro\"><picture><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/format:webp\/1*UuTiqdGQFfvA78djIPwVYA.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/format:webp\/1*UuTiqdGQFfvA78djIPwVYA.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/format:webp\/1*UuTiqdGQFfvA78djIPwVYA.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/format:webp\/1*UuTiqdGQFfvA78djIPwVYA.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/format:webp\/1*UuTiqdGQFfvA78djIPwVYA.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/format:webp\/1*UuTiqdGQFfvA78djIPwVYA.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1400\/format:webp\/1*UuTiqdGQFfvA78djIPwVYA.jpeg 1400w\" type=\"image\/webp\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 700px\"><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/1*UuTiqdGQFfvA78djIPwVYA.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/1*UuTiqdGQFfvA78djIPwVYA.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/1*UuTiqdGQFfvA78djIPwVYA.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/1*UuTiqdGQFfvA78djIPwVYA.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/1*UuTiqdGQFfvA78djIPwVYA.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/1*UuTiqdGQFfvA78djIPwVYA.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*UuTiqdGQFfvA78djIPwVYA.jpeg 1400w\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 700px\" data-testid=\"og\"><\/picture><\/div>\n<\/div>\n<figcaption class=\"ri rj rk qz ra rl rm be b bf z dv\" data-selectable-paragraph=\"\">Doggo after cropping.<\/figcaption>\n<\/figure>\n<pre class=\"mh mi mj mk ml qa qb qc qd ax qe bj\"><span id=\"4e7f\" class=\"ol mp fo qb b ia qf qg l iq qh\" data-selectable-paragraph=\"\">import cv2\ncropped = image[10:500, 500:2000]\nviewImage(cropped, \"Doggo after cropping.\")<\/span><\/pre>\n<p id=\"7a0c\" class=\"pw-post-body-paragraph nk nl fo be b gm og nn no gp oh nq nr ns oi nu nv nw oj ny nz oa ok oc od oe fh bj\" data-selectable-paragraph=\"\">where <code class=\"cw ql qm qn qb b\">image[10:500, 500:2000]<\/code> is <code class=\"cw ql qm qn qb b\">image[y:y+h, x:x+w]<\/code><\/p>\n<\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"fh fi fj fk fl\">\n<div class=\"ab ca\">\n<div class=\"ch bg et eu ev ew\">\n<h1 id=\"36e8\" class=\"mo mp fo be mq mr pv go mt mu pw gr mw mx px mz na nb py nd ne nf pz nh ni nj bj\" data-selectable-paragraph=\"\">Resizing<\/h1>\n<figure class=\"mh mi mj mk ml mg qz ra paragraph-image\">\n<div class=\"re rf eb rg bg rh\" tabindex=\"0\" role=\"button\">\n<figure><img loading=\"lazy\" decoding=\"async\" class=\"bg mm mn c\" role=\"presentation\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:700\/1*AJjT80DpN93YUWTUkOBOJQ.jpeg\" alt=\"\" width=\"700\" height=\"1053\"><\/figure><div class=\"qz ra rp\"><picture><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/format:webp\/1*AJjT80DpN93YUWTUkOBOJQ.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/format:webp\/1*AJjT80DpN93YUWTUkOBOJQ.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/format:webp\/1*AJjT80DpN93YUWTUkOBOJQ.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/format:webp\/1*AJjT80DpN93YUWTUkOBOJQ.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/format:webp\/1*AJjT80DpN93YUWTUkOBOJQ.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/format:webp\/1*AJjT80DpN93YUWTUkOBOJQ.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1400\/format:webp\/1*AJjT80DpN93YUWTUkOBOJQ.jpeg 1400w\" type=\"image\/webp\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 700px\"><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/1*AJjT80DpN93YUWTUkOBOJQ.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/1*AJjT80DpN93YUWTUkOBOJQ.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/1*AJjT80DpN93YUWTUkOBOJQ.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/1*AJjT80DpN93YUWTUkOBOJQ.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/1*AJjT80DpN93YUWTUkOBOJQ.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/1*AJjT80DpN93YUWTUkOBOJQ.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*AJjT80DpN93YUWTUkOBOJQ.jpeg 1400w\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 700px\" data-testid=\"og\"><\/picture><\/div>\n<\/div>\n<figcaption class=\"ri rj rk qz ra rl rm be b bf z dv\" data-selectable-paragraph=\"\">Source: <a class=\"af of\" href=\"http:\/\/pexels.com\/\" target=\"_blank\" rel=\"noopener ugc nofollow\">Pexels<\/a><\/figcaption>\n<\/figure>\n<figure class=\"mh mi mj mk ml mg qz ra paragraph-image\">\n<figure><img loading=\"lazy\" decoding=\"async\" class=\"bg mm mn c\" role=\"presentation\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:409\/1*YJzoBwWOtJhkksl3Mpv61w.jpeg\" alt=\"\" width=\"409\" height=\"615\"><\/figure><div class=\"qz ra rq\"><picture><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/format:webp\/1*YJzoBwWOtJhkksl3Mpv61w.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/format:webp\/1*YJzoBwWOtJhkksl3Mpv61w.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/format:webp\/1*YJzoBwWOtJhkksl3Mpv61w.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/format:webp\/1*YJzoBwWOtJhkksl3Mpv61w.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/format:webp\/1*YJzoBwWOtJhkksl3Mpv61w.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/format:webp\/1*YJzoBwWOtJhkksl3Mpv61w.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:818\/format:webp\/1*YJzoBwWOtJhkksl3Mpv61w.jpeg 818w\" type=\"image\/webp\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 409px\"><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/1*YJzoBwWOtJhkksl3Mpv61w.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/1*YJzoBwWOtJhkksl3Mpv61w.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/1*YJzoBwWOtJhkksl3Mpv61w.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/1*YJzoBwWOtJhkksl3Mpv61w.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/1*YJzoBwWOtJhkksl3Mpv61w.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/1*YJzoBwWOtJhkksl3Mpv61w.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:818\/1*YJzoBwWOtJhkksl3Mpv61w.jpeg 818w\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 409px\" data-testid=\"og\"><\/picture><\/div>\n<figcaption class=\"ri rj rk qz ra rl rm be b bf z dv\" data-selectable-paragraph=\"\">After resizing with 20%<\/figcaption>\n<\/figure>\n<pre class=\"mh mi mj mk ml qa qb qc qd ax qe bj\"><span id=\"0462\" class=\"ol mp fo qb b ia qf qg l iq qh\" data-selectable-paragraph=\"\">import cv2\nscale_percent = 20 # percent of original size\nwidth = int(img.shape[1] * scale_percent \/ 100)\nheight = int(img.shape[0] * scale_percent \/ 100)\ndim = (width, height)<\/span><span id=\"1718\" class=\"ol mp fo qb b ia rr qg l iq qh\" data-selectable-paragraph=\"\">resized = cv2.resize(img, dim, interpolation = cv2.INTER_AREA)<\/span><span id=\"d434\" class=\"ol mp fo qb b ia rr qg l iq qh\" data-selectable-paragraph=\"\">viewImage(resized, \"After resizing with 20%\")<\/span><\/pre>\n<p id=\"c2b9\" class=\"pw-post-body-paragraph nk nl fo be b gm og nn no gp oh nq nr ns oi nu nv nw oj ny nz oa ok oc od oe fh bj\" data-selectable-paragraph=\"\">This resizing function maintains the dimension-ratio of the original image.<\/p>\n<p id=\"e983\" class=\"pw-post-body-paragraph nk nl fo be b gm og nn no gp oh nq nr ns oi nu nv nw oj ny nz oa ok oc od oe fh bj\" data-selectable-paragraph=\"\"><em class=\"qj\">More image scaling functions <\/em><a class=\"af of\" href=\"https:\/\/www.tutorialkart.com\/opencv\/python\/opencv-python-resize-image\/\" target=\"_blank\" rel=\"noopener ugc nofollow\"><em class=\"qj\">here<\/em><\/a><em class=\"qj\">.<\/em><\/p>\n<\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"fh fi fj fk fl\">\n<div class=\"ab ca\">\n<div class=\"ch bg et eu ev ew\">\n<h1 id=\"ff7f\" class=\"mo mp fo be mq mr pv go mt mu pw gr mw mx px mz na nb py nd ne nf pz nh ni nj bj\" data-selectable-paragraph=\"\">Rotating<\/h1>\n<\/div>\n<\/div>\n<div class=\"mg\">\n<div class=\"ab ca\">\n<div class=\"qr qs qt qu qv qw ce qx cf qy ch bg\">\n<div class=\"mh mi mj mk ml ab ki\">\n<figure class=\"le mg rs rt rc rd ru paragraph-image\">\n<figure><img loading=\"lazy\" decoding=\"async\" class=\"bg mm mn c\" role=\"presentation\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:4928\/1*SVkI8I5XHs18gfS3jrL4Cw.jpeg\" alt=\"\" width=\"500\" height=\"3264\"><\/figure><div class=\"re rf eb rg bg rh\" tabindex=\"0\" role=\"button\"><picture><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/format:webp\/1*SVkI8I5XHs18gfS3jrL4Cw.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/format:webp\/1*SVkI8I5XHs18gfS3jrL4Cw.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/format:webp\/1*SVkI8I5XHs18gfS3jrL4Cw.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/format:webp\/1*SVkI8I5XHs18gfS3jrL4Cw.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/format:webp\/1*SVkI8I5XHs18gfS3jrL4Cw.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/format:webp\/1*SVkI8I5XHs18gfS3jrL4Cw.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1000\/format:webp\/1*SVkI8I5XHs18gfS3jrL4Cw.jpeg 1000w\" type=\"image\/webp\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 500px\"><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/1*SVkI8I5XHs18gfS3jrL4Cw.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/1*SVkI8I5XHs18gfS3jrL4Cw.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/1*SVkI8I5XHs18gfS3jrL4Cw.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/1*SVkI8I5XHs18gfS3jrL4Cw.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/1*SVkI8I5XHs18gfS3jrL4Cw.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/1*SVkI8I5XHs18gfS3jrL4Cw.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1000\/1*SVkI8I5XHs18gfS3jrL4Cw.jpeg 1000w\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 500px\" data-testid=\"og\"><\/picture><\/div>\n<\/figure>\n<figure class=\"le mg rs rt rc rd ru paragraph-image\">\n<figure><img loading=\"lazy\" decoding=\"async\" class=\"bg mm mn c\" role=\"presentation\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:4928\/1*j2pCsTfv_bF1ZAys8IQTLA.jpeg\" alt=\"\" width=\"500\" height=\"3264\"><\/figure><div class=\"re rf eb rg bg rh\" tabindex=\"0\" role=\"button\"><picture><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/format:webp\/1*j2pCsTfv_bF1ZAys8IQTLA.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/format:webp\/1*j2pCsTfv_bF1ZAys8IQTLA.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/format:webp\/1*j2pCsTfv_bF1ZAys8IQTLA.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/format:webp\/1*j2pCsTfv_bF1ZAys8IQTLA.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/format:webp\/1*j2pCsTfv_bF1ZAys8IQTLA.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/format:webp\/1*j2pCsTfv_bF1ZAys8IQTLA.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1000\/format:webp\/1*j2pCsTfv_bF1ZAys8IQTLA.jpeg 1000w\" type=\"image\/webp\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 500px\"><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/1*j2pCsTfv_bF1ZAys8IQTLA.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/1*j2pCsTfv_bF1ZAys8IQTLA.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/1*j2pCsTfv_bF1ZAys8IQTLA.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/1*j2pCsTfv_bF1ZAys8IQTLA.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/1*j2pCsTfv_bF1ZAys8IQTLA.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/1*j2pCsTfv_bF1ZAys8IQTLA.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1000\/1*j2pCsTfv_bF1ZAys8IQTLA.jpeg 1000w\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 500px\" data-testid=\"og\"><\/picture><\/div>\n<figcaption class=\"ri rj rk qz ra rl rm be b bf z dv rv eb rw rx\" data-selectable-paragraph=\"\">Left: Photo by Jonathan Meyer from <a class=\"af of\" href=\"http:\/\/pexels.com\/\" target=\"_blank\" rel=\"noopener ugc nofollow\">Pexels<\/a>. Right: Doggo after rotation by 180 degrees.<\/figcaption>\n<\/figure>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"ab ca\">\n<div class=\"ch bg et eu ev ew\">\n<pre class=\"mh mi mj mk ml qa qb qc qd ax qe bj\"><span id=\"7cdc\" class=\"ol mp fo qb b ia qf qg l iq qh\" data-selectable-paragraph=\"\">import cv2\n(h, w, d) = image.shape\ncenter = (w \/\/ 2, h \/\/ 2)\nM = cv2.getRotationMatrix2D(center, 180, 1.0)\nrotated = cv2.warpAffine(image, M, (w, h))\nviewImage(rotated, \"Doggo after rotation by 190 degrees\")<\/span><\/pre>\n<p id=\"ba03\" class=\"pw-post-body-paragraph nk nl fo be b gm og nn no gp oh nq nr ns oi nu nv nw oj ny nz oa ok oc od oe fh bj\" data-selectable-paragraph=\"\"><code class=\"cw ql qm qn qb b\">image.shape<\/code> outputs the height, width, and channels. <code class=\"cw ql qm qn qb b\">M<\/code> is the rotation matrix\u2014this rotates the image 180 degrees around its center.<br>\n<code class=\"cw ql qm qn qb b\">-ve<\/code> angle rotates the image clockwise &amp; <code class=\"cw ql qm qn qb b\">+ve<\/code> angle rotates the image counterclockwise.<\/p>\n<\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"fh fi fj fk fl\">\n<div class=\"ab ca\">\n<div class=\"ch bg et eu ev ew\">\n<h1 id=\"d9f4\" class=\"mo mp fo be mq mr pv go mt mu pw gr mw mx px mz na nb py nd ne nf pz nh ni nj bj\" data-selectable-paragraph=\"\">Grayscaling and Thresholding (Black &amp; White effect)<\/h1>\n<figure class=\"mh mi mj mk ml mg qz ra paragraph-image\">\n<div class=\"re rf eb rg bg rh\" tabindex=\"0\" role=\"button\">\n<figure><img loading=\"lazy\" decoding=\"async\" class=\"bg mm mn c\" role=\"presentation\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:700\/1*TRn-JK8tlKBCUSgkooKVpg.jpeg\" alt=\"\" width=\"700\" height=\"700\"><\/figure><div class=\"qz ra si\"><picture><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/format:webp\/1*TRn-JK8tlKBCUSgkooKVpg.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/format:webp\/1*TRn-JK8tlKBCUSgkooKVpg.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/format:webp\/1*TRn-JK8tlKBCUSgkooKVpg.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/format:webp\/1*TRn-JK8tlKBCUSgkooKVpg.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/format:webp\/1*TRn-JK8tlKBCUSgkooKVpg.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/format:webp\/1*TRn-JK8tlKBCUSgkooKVpg.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1400\/format:webp\/1*TRn-JK8tlKBCUSgkooKVpg.jpeg 1400w\" type=\"image\/webp\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 700px\"><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/1*TRn-JK8tlKBCUSgkooKVpg.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/1*TRn-JK8tlKBCUSgkooKVpg.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/1*TRn-JK8tlKBCUSgkooKVpg.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/1*TRn-JK8tlKBCUSgkooKVpg.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/1*TRn-JK8tlKBCUSgkooKVpg.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/1*TRn-JK8tlKBCUSgkooKVpg.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*TRn-JK8tlKBCUSgkooKVpg.jpeg 1400w\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 700px\" data-testid=\"og\"><\/picture><\/div>\n<\/div>\n<figcaption class=\"ri rj rk qz ra rl rm be b bf z dv\" data-selectable-paragraph=\"\">Source: <a class=\"af of\" href=\"http:\/\/pexels.com\/\" target=\"_blank\" rel=\"noopener ugc nofollow\">Pexels<\/a><\/figcaption>\n<\/figure>\n<pre class=\"mh mi mj mk ml qa qb qc qd ax qe bj\"><span id=\"e87a\" class=\"ol mp fo qb b ia qf qg l iq qh\" data-selectable-paragraph=\"\">import cv2\ngray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)\nret, threshold_image = cv2.threshold(im, 127, 255, 0)\nviewImage(gray_image, \"Gray-scale doggo\")\nviewImage(threshold_image, \"Black &amp; White doggo\")<\/span><\/pre>\n<p id=\"fe19\" class=\"pw-post-body-paragraph nk nl fo be b gm og nn no gp oh nq nr ns oi nu nv nw oj ny nz oa ok oc od oe fh bj\" data-selectable-paragraph=\"\"><code class=\"cw ql qm qn qb b\">gray_image<\/code> is the grayscale one-channeled version of the image.<em class=\"qj\"><br>\n<\/em>This <code class=\"cw ql qm qn qb b\">threshold<\/code> function will turn all shades darker (smaller) than 127 to 0 and all brighter (greater) to 255.<\/p>\n<p id=\"5c36\" class=\"pw-post-body-paragraph nk nl fo be b gm og nn no gp oh nq nr ns oi nu nv nw oj ny nz oa ok oc od oe fh bj\" data-selectable-paragraph=\"\"><strong class=\"be qi\">Another example:<\/strong><\/p>\n<pre class=\"mh mi mj mk ml qa qb qc qd ax qe bj\"><span id=\"bc26\" class=\"ol mp fo qb b ia qf qg l iq qh\" data-selectable-paragraph=\"\">ret, threshold = cv2.threshold(im, 150, 200, 10)<\/span><\/pre>\n<p id=\"0b69\" class=\"pw-post-body-paragraph nk nl fo be b gm og nn no gp oh nq nr ns oi nu nv nw oj ny nz oa ok oc od oe fh bj\" data-selectable-paragraph=\"\">This will turn all shades smaller than 150 to 10 and all greater to 200.<\/p>\n<p id=\"a5d2\" class=\"pw-post-body-paragraph nk nl fo be b gm og nn no gp oh nq nr ns oi nu nv nw oj ny nz oa ok oc od oe fh bj\" data-selectable-paragraph=\"\"><em class=\"qj\">More thresholding functions <\/em><a class=\"af of\" href=\"https:\/\/docs.opencv.org\/3.4\/d7\/d4d\/tutorial_py_thresholding.html\" target=\"_blank\" rel=\"noopener ugc nofollow\"><em class=\"qj\">here<\/em><\/a><em class=\"qj\">.<\/em><\/p>\n<\/div>\n<\/div>\n<div class=\"mg\">\n<div class=\"ab ca\">\n<div class=\"qr qs qt qu qv qw ce qx cf qy ch bg\">\n<div class=\"mh mi mj mk ml ab ki\">\n<figure class=\"le mg rs rt rc rd ru paragraph-image\">\n<figure><img loading=\"lazy\" decoding=\"async\" class=\"bg mm mn c\" role=\"presentation\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:2000\/1*lVHmCqfGqT0Fx5DIJnaRzQ.jpeg\" alt=\"\" width=\"500\" height=\"2000\"><\/figure><div class=\"re rf eb rg bg rh\" tabindex=\"0\" role=\"button\"><picture><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/format:webp\/1*lVHmCqfGqT0Fx5DIJnaRzQ.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/format:webp\/1*lVHmCqfGqT0Fx5DIJnaRzQ.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/format:webp\/1*lVHmCqfGqT0Fx5DIJnaRzQ.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/format:webp\/1*lVHmCqfGqT0Fx5DIJnaRzQ.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/format:webp\/1*lVHmCqfGqT0Fx5DIJnaRzQ.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/format:webp\/1*lVHmCqfGqT0Fx5DIJnaRzQ.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1000\/format:webp\/1*lVHmCqfGqT0Fx5DIJnaRzQ.jpeg 1000w\" type=\"image\/webp\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 500px\"><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/1*lVHmCqfGqT0Fx5DIJnaRzQ.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/1*lVHmCqfGqT0Fx5DIJnaRzQ.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/1*lVHmCqfGqT0Fx5DIJnaRzQ.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/1*lVHmCqfGqT0Fx5DIJnaRzQ.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/1*lVHmCqfGqT0Fx5DIJnaRzQ.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/1*lVHmCqfGqT0Fx5DIJnaRzQ.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1000\/1*lVHmCqfGqT0Fx5DIJnaRzQ.jpeg 1000w\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 500px\" data-testid=\"og\"><\/picture><\/div>\n<\/figure>\n<figure class=\"le mg rs rt rc rd ru paragraph-image\">\n<figure><img loading=\"lazy\" decoding=\"async\" class=\"bg mm mn c\" role=\"presentation\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:2000\/1*4p1SghdBZucSg5R2dZvn1Q.jpeg\" alt=\"\" width=\"500\" height=\"2000\"><\/figure><div class=\"re rf eb rg bg rh\" tabindex=\"0\" role=\"button\"><picture><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/format:webp\/1*4p1SghdBZucSg5R2dZvn1Q.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/format:webp\/1*4p1SghdBZucSg5R2dZvn1Q.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/format:webp\/1*4p1SghdBZucSg5R2dZvn1Q.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/format:webp\/1*4p1SghdBZucSg5R2dZvn1Q.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/format:webp\/1*4p1SghdBZucSg5R2dZvn1Q.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/format:webp\/1*4p1SghdBZucSg5R2dZvn1Q.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1000\/format:webp\/1*4p1SghdBZucSg5R2dZvn1Q.jpeg 1000w\" type=\"image\/webp\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 500px\"><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/1*4p1SghdBZucSg5R2dZvn1Q.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/1*4p1SghdBZucSg5R2dZvn1Q.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/1*4p1SghdBZucSg5R2dZvn1Q.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/1*4p1SghdBZucSg5R2dZvn1Q.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/1*4p1SghdBZucSg5R2dZvn1Q.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/1*4p1SghdBZucSg5R2dZvn1Q.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1000\/1*4p1SghdBZucSg5R2dZvn1Q.jpeg 1000w\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 500px\" data-testid=\"og\"><\/picture><\/div>\n<figcaption class=\"ri rj rk qz ra rl rm be b bf z dv rv eb rw rx\" data-selectable-paragraph=\"\">Left: Gray-scale doggo. Right: Black &amp; White doggo.<\/figcaption>\n<\/figure>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"fh fi fj fk fl\">\n<div class=\"ab ca\">\n<div class=\"ch bg et eu ev ew\">\n<h1 id=\"28f2\" class=\"mo mp fo be mq mr pv go mt mu pw gr mw mx px mz na nb py nd ne nf pz nh ni nj bj\" data-selectable-paragraph=\"\">Blurring\/Smoothing<\/h1>\n<\/div>\n<\/div>\n<div class=\"mg\">\n<div class=\"ab ca\">\n<div class=\"qr qs qt qu qv qw ce qx cf qy ch bg\">\n<div class=\"mh mi mj mk ml ab ki\">\n<figure class=\"le mg rs rt rc rd ru paragraph-image\">\n<figure><img loading=\"lazy\" decoding=\"async\" class=\"bg mm mn c\" role=\"presentation\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:1920\/1*Rny9ak-Taj58otF4ao9uFA.jpeg\" alt=\"\" width=\"500\" height=\"1280\"><\/figure><div class=\"re rf eb rg bg rh\" tabindex=\"0\" role=\"button\"><picture><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/format:webp\/1*Rny9ak-Taj58otF4ao9uFA.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/format:webp\/1*Rny9ak-Taj58otF4ao9uFA.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/format:webp\/1*Rny9ak-Taj58otF4ao9uFA.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/format:webp\/1*Rny9ak-Taj58otF4ao9uFA.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/format:webp\/1*Rny9ak-Taj58otF4ao9uFA.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/format:webp\/1*Rny9ak-Taj58otF4ao9uFA.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1000\/format:webp\/1*Rny9ak-Taj58otF4ao9uFA.jpeg 1000w\" type=\"image\/webp\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 500px\"><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/1*Rny9ak-Taj58otF4ao9uFA.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/1*Rny9ak-Taj58otF4ao9uFA.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/1*Rny9ak-Taj58otF4ao9uFA.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/1*Rny9ak-Taj58otF4ao9uFA.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/1*Rny9ak-Taj58otF4ao9uFA.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/1*Rny9ak-Taj58otF4ao9uFA.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1000\/1*Rny9ak-Taj58otF4ao9uFA.jpeg 1000w\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 500px\" data-testid=\"og\"><\/picture><\/div>\n<\/figure>\n<figure class=\"le mg rs rt rc rd ru paragraph-image\">\n<figure><img loading=\"lazy\" decoding=\"async\" class=\"bg mm mn c\" role=\"presentation\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:1920\/1*WhEeegXBhcAllIRDN4TTvA.jpeg\" alt=\"\" width=\"500\" height=\"1280\"><\/figure><div class=\"re rf eb rg bg rh\" tabindex=\"0\" role=\"button\"><picture><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/format:webp\/1*WhEeegXBhcAllIRDN4TTvA.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/format:webp\/1*WhEeegXBhcAllIRDN4TTvA.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/format:webp\/1*WhEeegXBhcAllIRDN4TTvA.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/format:webp\/1*WhEeegXBhcAllIRDN4TTvA.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/format:webp\/1*WhEeegXBhcAllIRDN4TTvA.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/format:webp\/1*WhEeegXBhcAllIRDN4TTvA.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1000\/format:webp\/1*WhEeegXBhcAllIRDN4TTvA.jpeg 1000w\" type=\"image\/webp\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 500px\"><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/1*WhEeegXBhcAllIRDN4TTvA.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/1*WhEeegXBhcAllIRDN4TTvA.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/1*WhEeegXBhcAllIRDN4TTvA.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/1*WhEeegXBhcAllIRDN4TTvA.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/1*WhEeegXBhcAllIRDN4TTvA.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/1*WhEeegXBhcAllIRDN4TTvA.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1000\/1*WhEeegXBhcAllIRDN4TTvA.jpeg 1000w\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 500px\" data-testid=\"og\"><\/picture><\/div>\n<figcaption class=\"ri rj rk qz ra rl rm be b bf z dv rv eb rw rx\" data-selectable-paragraph=\"\">Left: Image from Pixabay. Right: Blurred doggo.<\/figcaption>\n<\/figure>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"ab ca\">\n<div class=\"ch bg et eu ev ew\">\n<pre class=\"mh mi mj mk ml qa qb qc qd ax qe bj\"><span id=\"7ea0\" class=\"ol mp fo qb b ia qf qg l iq qh\" data-selectable-paragraph=\"\">import cv2\nblurred = cv2.GaussianBlur(image, (51, 51), 0)\nviewImage(blurred, \"Blurred doggo\")<\/span><\/pre>\n<h2 id=\"ee26\" class=\"ol mp fo be mq om on oo mt op oq or mw ns os ot ou nw ov ow ox oa oy oz pa pb bj\" data-selectable-paragraph=\"\">The GaussianBlur function takes 3 parameters:<\/h2>\n<ul class=\"\">\n<li id=\"2730\" class=\"nk nl fo be b gm nm nn no gp np nq nr pc nt nu nv pd nx ny nz pe ob oc od oe pf pg ph bj\" data-selectable-paragraph=\"\">The first parameter is the image you want to blur.<\/li>\n<li id=\"6aed\" class=\"nk nl fo be b gm pi nn no gp pj nq nr pc pk nu nv pd pl ny nz pe pm oc od oe pf pg ph bj\" data-selectable-paragraph=\"\">The second parameter must be a tuple of <strong class=\"be qi\">2 positive odd numbers<\/strong>. When they increase, the blur effect increases.<\/li>\n<li id=\"8e78\" class=\"nk nl fo be b gm pi nn no gp pj nq nr pc pk nu nv pd pl ny nz pe pm oc od oe pf pg ph bj\" data-selectable-paragraph=\"\">The third parameter is The <em class=\"qj\">sigmaX<\/em> and <em class=\"qj\">sigmaY<\/em>. When left at 0, they\u2019re automatically calculated from the kernel size.<\/li>\n<\/ul>\n<p id=\"178f\" class=\"pw-post-body-paragraph nk nl fo be b gm og nn no gp oh nq nr ns oi nu nv nw oj ny nz oa ok oc od oe fh bj\" data-selectable-paragraph=\"\"><em class=\"qj\">More blurring functions <\/em><a class=\"af of\" href=\"https:\/\/docs.opencv.org\/3.1.0\/d4\/d13\/tutorial_py_filtering.html\" target=\"_blank\" rel=\"noopener ugc nofollow\"><em class=\"qj\">here<\/em><\/a><em class=\"qj\">.<\/em><\/p>\n<\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"fh fi fj fk fl\">\n<div class=\"ab ca\">\n<div class=\"ch bg et eu ev ew\">\n<h1 id=\"855f\" class=\"mo mp fo be mq mr pv go mt mu pw gr mw mx px mz na nb py nd ne nf pz nh ni nj bj\" data-selectable-paragraph=\"\">Drawing a Rectangle\/Bounding Box on an Image<\/h1>\n<\/div>\n<\/div>\n<div class=\"mg\">\n<div class=\"ab ca\">\n<div class=\"qr qs qt qu qv qw ce qx cf qy ch bg\">\n<div class=\"mh mi mj mk ml ab ki\">\n<figure class=\"le mg rs rt rc rd ru paragraph-image\">\n<figure><img loading=\"lazy\" decoding=\"async\" class=\"bg mm mn c\" role=\"presentation\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:5760\/1*rr0RN5b8cxseYUwABRdlKw.jpeg\" alt=\"\" width=\"500\" height=\"3840\"><\/figure><div class=\"re rf eb rg bg rh\" tabindex=\"0\" role=\"button\"><picture><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/format:webp\/1*rr0RN5b8cxseYUwABRdlKw.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/format:webp\/1*rr0RN5b8cxseYUwABRdlKw.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/format:webp\/1*rr0RN5b8cxseYUwABRdlKw.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/format:webp\/1*rr0RN5b8cxseYUwABRdlKw.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/format:webp\/1*rr0RN5b8cxseYUwABRdlKw.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/format:webp\/1*rr0RN5b8cxseYUwABRdlKw.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1000\/format:webp\/1*rr0RN5b8cxseYUwABRdlKw.jpeg 1000w\" type=\"image\/webp\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 500px\"><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/1*rr0RN5b8cxseYUwABRdlKw.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/1*rr0RN5b8cxseYUwABRdlKw.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/1*rr0RN5b8cxseYUwABRdlKw.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/1*rr0RN5b8cxseYUwABRdlKw.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/1*rr0RN5b8cxseYUwABRdlKw.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/1*rr0RN5b8cxseYUwABRdlKw.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1000\/1*rr0RN5b8cxseYUwABRdlKw.jpeg 1000w\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 500px\" data-testid=\"og\"><\/picture><\/div>\n<\/figure>\n<figure class=\"le mg rs rt rc rd ru paragraph-image\">\n<figure><img loading=\"lazy\" decoding=\"async\" class=\"bg mm mn c\" role=\"presentation\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:5760\/1*uMd8BQyqdDhpH-gR8F3tbg.jpeg\" alt=\"\" width=\"500\" height=\"3840\"><\/figure><div class=\"re rf eb rg bg rh\" tabindex=\"0\" role=\"button\"><picture><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/format:webp\/1*uMd8BQyqdDhpH-gR8F3tbg.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/format:webp\/1*uMd8BQyqdDhpH-gR8F3tbg.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/format:webp\/1*uMd8BQyqdDhpH-gR8F3tbg.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/format:webp\/1*uMd8BQyqdDhpH-gR8F3tbg.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/format:webp\/1*uMd8BQyqdDhpH-gR8F3tbg.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/format:webp\/1*uMd8BQyqdDhpH-gR8F3tbg.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1000\/format:webp\/1*uMd8BQyqdDhpH-gR8F3tbg.jpeg 1000w\" type=\"image\/webp\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 500px\"><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/1*uMd8BQyqdDhpH-gR8F3tbg.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/1*uMd8BQyqdDhpH-gR8F3tbg.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/1*uMd8BQyqdDhpH-gR8F3tbg.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/1*uMd8BQyqdDhpH-gR8F3tbg.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/1*uMd8BQyqdDhpH-gR8F3tbg.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/1*uMd8BQyqdDhpH-gR8F3tbg.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1000\/1*uMd8BQyqdDhpH-gR8F3tbg.jpeg 1000w\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 500px\" data-testid=\"og\"><\/picture><\/div>\n<figcaption class=\"ri rj rk qz ra rl rm be b bf z dv rv eb rw rx\" data-selectable-paragraph=\"\">Left: Image from Pexels. Right: Doggo with a rectangle on his face.<\/figcaption>\n<\/figure>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"ab ca\">\n<div class=\"ch bg et eu ev ew\">\n<pre class=\"mh mi mj mk ml qa qb qc qd ax qe bj\"><span id=\"d08e\" class=\"ol mp fo qb b ia qf qg l iq qh\" data-selectable-paragraph=\"\">import cv2\noutput = image.copy()\ncv2.rectangle(output, (2600, 800), (4100, 2400), (0, 255, 255), 10)\nviewImage(output, \"Doggo with a rectangle on his face\") <\/span><\/pre>\n<h2 id=\"31df\" class=\"ol mp fo be mq om on oo mt op oq or mw ns os ot ou nw ov ow ox oa oy oz pa pb bj\" data-selectable-paragraph=\"\">The rectangle function takes 5 parameters:<\/h2>\n<ul class=\"\">\n<li id=\"ac38\" class=\"nk nl fo be b gm nm nn no gp np nq nr pc nt nu nv pd nx ny nz pe ob oc od oe pf pg ph bj\" data-selectable-paragraph=\"\">The first parameter is the image.<\/li>\n<li id=\"5277\" class=\"nk nl fo be b gm pi nn no gp pj nq nr pc pk nu nv pd pl ny nz pe pm oc od oe pf pg ph bj\" data-selectable-paragraph=\"\">The second parameter is <em class=\"qj\">x1<\/em>,<em class=\"qj\"> y1 \u2014 Top Left Corner.<\/em><\/li>\n<li id=\"6173\" class=\"nk nl fo be b gm pi nn no gp pj nq nr pc pk nu nv pd pl ny nz pe pm oc od oe pf pg ph bj\" data-selectable-paragraph=\"\">The third parameter is <em class=\"qj\">x2<\/em>, <em class=\"qj\">y2 \u2014 Bottom Right Corner.<\/em><\/li>\n<li id=\"ba92\" class=\"nk nl fo be b gm pi nn no gp pj nq nr pc pk nu nv pd pl ny nz pe pm oc od oe pf pg ph bj\" data-selectable-paragraph=\"\">The fourth parameter is the rectangle color (<strong class=\"be qi\"><em class=\"qj\">GBR<\/em><\/strong>\/<strong class=\"be qi\"><em class=\"qj\">RGB<\/em><\/strong>, depending on how you imported your image).<\/li>\n<li id=\"3db3\" class=\"nk nl fo be b gm pi nn no gp pj nq nr pc pk nu nv pd pl ny nz pe pm oc od oe pf pg ph bj\" data-selectable-paragraph=\"\">The fifth parameter is the rectangle line thickness.<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"fh fi fj fk fl\">\n<div class=\"ab ca\">\n<div class=\"ch bg et eu ev ew\">\n<h1 id=\"bb3c\" class=\"mo mp fo be mq mr pv go mt mu pw gr mw mx px mz na nb py nd ne nf pz nh ni nj bj\" data-selectable-paragraph=\"\">Drawing a line<\/h1>\n<\/div>\n<\/div>\n<div class=\"mg\">\n<div class=\"ab ca\">\n<div class=\"qr qs qt qu qv qw ce qx cf qy ch bg\">\n<div class=\"mh mi mj mk ml ab ki\">\n<figure class=\"le mg rs rt rc rd ru paragraph-image\">\n<figure><img loading=\"lazy\" decoding=\"async\" class=\"bg mm mn c\" role=\"presentation\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:3264\/1*NdAq3JTqU8nLZWjbaGfjPg.jpeg\" alt=\"\" width=\"500\" height=\"2448\"><\/figure><div class=\"re rf eb rg bg rh\" tabindex=\"0\" role=\"button\"><picture><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/format:webp\/1*NdAq3JTqU8nLZWjbaGfjPg.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/format:webp\/1*NdAq3JTqU8nLZWjbaGfjPg.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/format:webp\/1*NdAq3JTqU8nLZWjbaGfjPg.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/format:webp\/1*NdAq3JTqU8nLZWjbaGfjPg.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/format:webp\/1*NdAq3JTqU8nLZWjbaGfjPg.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/format:webp\/1*NdAq3JTqU8nLZWjbaGfjPg.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1000\/format:webp\/1*NdAq3JTqU8nLZWjbaGfjPg.jpeg 1000w\" type=\"image\/webp\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 500px\"><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/1*NdAq3JTqU8nLZWjbaGfjPg.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/1*NdAq3JTqU8nLZWjbaGfjPg.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/1*NdAq3JTqU8nLZWjbaGfjPg.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/1*NdAq3JTqU8nLZWjbaGfjPg.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/1*NdAq3JTqU8nLZWjbaGfjPg.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/1*NdAq3JTqU8nLZWjbaGfjPg.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1000\/1*NdAq3JTqU8nLZWjbaGfjPg.jpeg 1000w\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 500px\" data-testid=\"og\"><\/picture><\/div>\n<\/figure>\n<figure class=\"le mg rs rt rc rd ru paragraph-image\">\n<figure><img loading=\"lazy\" decoding=\"async\" class=\"bg mm mn c\" role=\"presentation\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:3264\/1*H1r2tUmUN3V15ps5ynwJHQ.jpeg\" alt=\"\" width=\"500\" height=\"2448\"><\/figure><div class=\"re rf eb rg bg rh\" tabindex=\"0\" role=\"button\"><picture><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/format:webp\/1*H1r2tUmUN3V15ps5ynwJHQ.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/format:webp\/1*H1r2tUmUN3V15ps5ynwJHQ.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/format:webp\/1*H1r2tUmUN3V15ps5ynwJHQ.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/format:webp\/1*H1r2tUmUN3V15ps5ynwJHQ.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/format:webp\/1*H1r2tUmUN3V15ps5ynwJHQ.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/format:webp\/1*H1r2tUmUN3V15ps5ynwJHQ.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1000\/format:webp\/1*H1r2tUmUN3V15ps5ynwJHQ.jpeg 1000w\" type=\"image\/webp\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 500px\"><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/1*H1r2tUmUN3V15ps5ynwJHQ.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/1*H1r2tUmUN3V15ps5ynwJHQ.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/1*H1r2tUmUN3V15ps5ynwJHQ.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/1*H1r2tUmUN3V15ps5ynwJHQ.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/1*H1r2tUmUN3V15ps5ynwJHQ.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/1*H1r2tUmUN3V15ps5ynwJHQ.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1000\/1*H1r2tUmUN3V15ps5ynwJHQ.jpeg 1000w\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 500px\" data-testid=\"og\"><\/picture><\/div>\n<figcaption class=\"ri rj rk qz ra rl rm be b bf z dv rv eb rw rx\" data-selectable-paragraph=\"\">Left: Image from Pexels. Right: 2 Doggos separated by a line.<\/figcaption>\n<\/figure>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"ab ca\">\n<div class=\"ch bg et eu ev ew\">\n<pre class=\"mh mi mj mk ml qa qb qc qd ax qe bj\"><span id=\"4b14\" class=\"ol mp fo qb b ia qf qg l iq qh\" data-selectable-paragraph=\"\">import cv2\noutput = image.copy()\ncv2.line(output, (60, 20), (400, 200), (0, 0, 255), 5)\nviewImage(output, \"2 Doggos separated by a line\")<\/span><\/pre>\n<h2 id=\"c51a\" class=\"ol mp fo be mq om on oo mt op oq or mw ns os ot ou nw ov ow ox oa oy oz pa pb bj\" data-selectable-paragraph=\"\">The line function takes 5 parameters<\/h2>\n<ul class=\"\">\n<li id=\"f4a5\" class=\"nk nl fo be b gm nm nn no gp np nq nr pc nt nu nv pd nx ny nz pe ob oc od oe pf pg ph bj\" data-selectable-paragraph=\"\">The first parameter is the image you want to draw a line on.<\/li>\n<li id=\"eea8\" class=\"nk nl fo be b gm pi nn no gp pj nq nr pc pk nu nv pd pl ny nz pe pm oc od oe pf pg ph bj\" data-selectable-paragraph=\"\">The second parameter is <em class=\"qj\">x1<\/em>,<em class=\"qj\"> y1<\/em>.<\/li>\n<li id=\"3d6b\" class=\"nk nl fo be b gm pi nn no gp pj nq nr pc pk nu nv pd pl ny nz pe pm oc od oe pf pg ph bj\" data-selectable-paragraph=\"\">The third parameter is <em class=\"qj\">x2<\/em>, <em class=\"qj\">y2<\/em>.<\/li>\n<li id=\"da3d\" class=\"nk nl fo be b gm pi nn no gp pj nq nr pc pk nu nv pd pl ny nz pe pm oc od oe pf pg ph bj\" data-selectable-paragraph=\"\">The fourth parameter is the line color (<strong class=\"be qi\"><em class=\"qj\">GBR<\/em><\/strong>\/<strong class=\"be qi\"><em class=\"qj\">RGB<\/em><\/strong> depending on how you imported your image).<\/li>\n<li id=\"a871\" class=\"nk nl fo be b gm pi nn no gp pj nq nr pc pk nu nv pd pl ny nz pe pm oc od oe pf pg ph bj\" data-selectable-paragraph=\"\">The fifth parameter is the line thickness.<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"fh fi fj fk fl\">\n<div class=\"ab ca\">\n<div class=\"ch bg et eu ev ew\">\n<h1 id=\"1618\" class=\"mo mp fo be mq mr pv go mt mu pw gr mw mx px mz na nb py nd ne nf pz nh ni nj bj\" data-selectable-paragraph=\"\">Writing on an image<\/h1>\n<\/div>\n<\/div>\n<div class=\"mg\">\n<div class=\"ab ca\">\n<div class=\"qr qs qt qu qv qw ce qx cf qy ch bg\">\n<div class=\"mh mi mj mk ml ab ki\">\n<figure class=\"le mg rs rt rc rd ru paragraph-image\">\n<figure><img loading=\"lazy\" decoding=\"async\" class=\"bg mm mn c\" role=\"presentation\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:6000\/1*crsVfLMtv1SNBMlqXyFfYg.jpeg\" alt=\"\" width=\"500\" height=\"4000\"><\/figure><div class=\"re rf eb rg bg rh\" tabindex=\"0\" role=\"button\"><picture><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/format:webp\/1*crsVfLMtv1SNBMlqXyFfYg.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/format:webp\/1*crsVfLMtv1SNBMlqXyFfYg.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/format:webp\/1*crsVfLMtv1SNBMlqXyFfYg.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/format:webp\/1*crsVfLMtv1SNBMlqXyFfYg.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/format:webp\/1*crsVfLMtv1SNBMlqXyFfYg.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/format:webp\/1*crsVfLMtv1SNBMlqXyFfYg.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1000\/format:webp\/1*crsVfLMtv1SNBMlqXyFfYg.jpeg 1000w\" type=\"image\/webp\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 500px\"><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/1*crsVfLMtv1SNBMlqXyFfYg.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/1*crsVfLMtv1SNBMlqXyFfYg.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/1*crsVfLMtv1SNBMlqXyFfYg.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/1*crsVfLMtv1SNBMlqXyFfYg.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/1*crsVfLMtv1SNBMlqXyFfYg.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/1*crsVfLMtv1SNBMlqXyFfYg.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1000\/1*crsVfLMtv1SNBMlqXyFfYg.jpeg 1000w\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 500px\" data-testid=\"og\"><\/picture><\/div>\n<\/figure>\n<figure class=\"le mg rs rt rc rd ru paragraph-image\">\n<figure><img loading=\"lazy\" decoding=\"async\" class=\"bg mm mn c\" role=\"presentation\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:6000\/1*lTizoTFVbhkx2PdDVEi9WQ.jpeg\" alt=\"\" width=\"500\" height=\"4000\"><\/figure><div class=\"re rf eb rg bg rh\" tabindex=\"0\" role=\"button\"><picture><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/format:webp\/1*lTizoTFVbhkx2PdDVEi9WQ.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/format:webp\/1*lTizoTFVbhkx2PdDVEi9WQ.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/format:webp\/1*lTizoTFVbhkx2PdDVEi9WQ.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/format:webp\/1*lTizoTFVbhkx2PdDVEi9WQ.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/format:webp\/1*lTizoTFVbhkx2PdDVEi9WQ.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/format:webp\/1*lTizoTFVbhkx2PdDVEi9WQ.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1000\/format:webp\/1*lTizoTFVbhkx2PdDVEi9WQ.jpeg 1000w\" type=\"image\/webp\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 500px\"><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/1*lTizoTFVbhkx2PdDVEi9WQ.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/1*lTizoTFVbhkx2PdDVEi9WQ.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/1*lTizoTFVbhkx2PdDVEi9WQ.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/1*lTizoTFVbhkx2PdDVEi9WQ.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/1*lTizoTFVbhkx2PdDVEi9WQ.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/1*lTizoTFVbhkx2PdDVEi9WQ.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1000\/1*lTizoTFVbhkx2PdDVEi9WQ.jpeg 1000w\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 500px\" data-testid=\"og\"><\/picture><\/div>\n<figcaption class=\"ri rj rk qz ra rl rm be b bf z dv rv eb rw rx\" data-selectable-paragraph=\"\">Left: Image from Pexels. Right: Image with text.<\/figcaption>\n<\/figure>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"ab ca\">\n<div class=\"ch bg et eu ev ew\">\n<pre class=\"mh mi mj mk ml qa qb qc qd ax qe bj\"><span id=\"6e4b\" class=\"ol mp fo qb b ia qf qg l iq qh\" data-selectable-paragraph=\"\">import cv2\noutput = image.copy()\ncv2.putText(output, \"We &lt;3 Dogs\", (1500, 3600),cv2.FONT_HERSHEY_SIMPLEX, 15, (30, 105, 210), 40)\nviewImage(output, \"image with text\")<\/span><\/pre>\n<h2 id=\"6c71\" class=\"ol mp fo be mq om on oo mt op oq or mw ns os ot ou nw ov ow ox oa oy oz pa pb bj\" data-selectable-paragraph=\"\">The putText function takes 7 parameters<\/h2>\n<ul class=\"\">\n<li id=\"569f\" class=\"nk nl fo be b gm nm nn no gp np nq nr pc nt nu nv pd nx ny nz pe ob oc od oe pf pg ph bj\" data-selectable-paragraph=\"\">The first parameter is the image you want to write on.<\/li>\n<li id=\"4de8\" class=\"nk nl fo be b gm pi nn no gp pj nq nr pc pk nu nv pd pl ny nz pe pm oc od oe pf pg ph bj\" data-selectable-paragraph=\"\">The second parameter is the text itself.<\/li>\n<li id=\"ba2f\" class=\"nk nl fo be b gm pi nn no gp pj nq nr pc pk nu nv pd pl ny nz pe pm oc od oe pf pg ph bj\" data-selectable-paragraph=\"\">The third parameter is the <em class=\"qj\">x<\/em>, <em class=\"qj\">y<\/em>\u2014the bottom left coordinate where the text starts.<\/li>\n<li id=\"77c0\" class=\"nk nl fo be b gm pi nn no gp pj nq nr pc pk nu nv pd pl ny nz pe pm oc od oe pf pg ph bj\" data-selectable-paragraph=\"\">The fourth parameter is the font type.<\/li>\n<li id=\"4f27\" class=\"nk nl fo be b gm pi nn no gp pj nq nr pc pk nu nv pd pl ny nz pe pm oc od oe pf pg ph bj\" data-selectable-paragraph=\"\">The fifth parameter is the font size.<\/li>\n<li id=\"a3e9\" class=\"nk nl fo be b gm pi nn no gp pj nq nr pc pk nu nv pd pl ny nz pe pm oc od oe pf pg ph bj\" data-selectable-paragraph=\"\">The sixth parameter is the color (<strong class=\"be qi\"><em class=\"qj\">GBR<\/em><\/strong>\/<strong class=\"be qi\"><em class=\"qj\">RGB<\/em><\/strong> depending on how you imported your image).<\/li>\n<li id=\"9a68\" class=\"nk nl fo be b gm pi nn no gp pj nq nr pc pk nu nv pd pl ny nz pe pm oc od oe pf pg ph bj\" data-selectable-paragraph=\"\">The seventh parameter is the thickness of the text.<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"fh fi fj fk fl\">\n<div class=\"ab ca\">\n<div class=\"ch bg et eu ev ew\">\n<h1 id=\"7ce9\" class=\"mo mp fo be mq mr pv go mt mu pw gr mw mx px mz na nb py nd ne nf pz nh ni nj bj\" data-selectable-paragraph=\"\">Face Detection<\/h1>\n<p id=\"c33e\" class=\"pw-post-body-paragraph nk nl fo be b gm nm nn no gp np nq nr ns nt nu nv nw nx ny nz oa ob oc od oe fh bj\" data-selectable-paragraph=\"\">Can\u2019t have dog pictures here, sadly \ud83d\ude41<\/p>\n<figure class=\"mh mi mj mk ml mg qz ra paragraph-image\">\n<div class=\"re rf eb rg bg rh\" tabindex=\"0\" role=\"button\">\n<figure><img loading=\"lazy\" decoding=\"async\" class=\"bg mm mn c\" role=\"presentation\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:700\/1*nevvkOrzz97jJ3cB8PiQiQ.jpeg\" alt=\"\" width=\"700\" height=\"467\"><\/figure><div class=\"qz ra rn\"><picture><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/format:webp\/1*nevvkOrzz97jJ3cB8PiQiQ.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/format:webp\/1*nevvkOrzz97jJ3cB8PiQiQ.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/format:webp\/1*nevvkOrzz97jJ3cB8PiQiQ.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/format:webp\/1*nevvkOrzz97jJ3cB8PiQiQ.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/format:webp\/1*nevvkOrzz97jJ3cB8PiQiQ.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/format:webp\/1*nevvkOrzz97jJ3cB8PiQiQ.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1400\/format:webp\/1*nevvkOrzz97jJ3cB8PiQiQ.jpeg 1400w\" type=\"image\/webp\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 700px\"><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/1*nevvkOrzz97jJ3cB8PiQiQ.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/1*nevvkOrzz97jJ3cB8PiQiQ.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/1*nevvkOrzz97jJ3cB8PiQiQ.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/1*nevvkOrzz97jJ3cB8PiQiQ.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/1*nevvkOrzz97jJ3cB8PiQiQ.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/1*nevvkOrzz97jJ3cB8PiQiQ.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*nevvkOrzz97jJ3cB8PiQiQ.jpeg 1400w\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 700px\" data-testid=\"og\"><\/picture><\/div>\n<\/div>\n<figcaption class=\"ri rj rk qz ra rl rm be b bf z dv\" data-selectable-paragraph=\"\"><a class=\"af of\" href=\"https:\/\/pixabay.com\/photos\/young-woman-female-youth-healthy-1208208\/\" target=\"_blank\" rel=\"noopener ugc nofollow\">Photo by Free-Photos from Pixabay<\/a><\/figcaption>\n<\/figure>\n<pre class=\"mh mi mj mk ml qa qb qc qd ax qe bj\"><span id=\"be22\" class=\"ol mp fo qb b ia qf qg l iq qh\" data-selectable-paragraph=\"\">import cv2<\/span><span id=\"a171\" class=\"ol mp fo qb b ia rr qg l iq qh\" data-selectable-paragraph=\"\">image_path = \".\/Path\/To\/Photo.extension\"\nface_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')<\/span><span id=\"cdf9\" class=\"ol mp fo qb b ia rr qg l iq qh\" data-selectable-paragraph=\"\">image = cv2.imread(image_path)\ngray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)\nfaces = face_cascade.detectMultiScale(\n    gray,\n    scaleFactor= 1.1,\n    minNeighbors= 5,\n    minSize=(10, 10)\n)<\/span><span id=\"e130\" class=\"ol mp fo qb b ia rr qg l iq qh\" data-selectable-paragraph=\"\">faces_detected = format(len(faces)) + \" faces detected!\"\nprint(faces_detected)<\/span><span id=\"1823\" class=\"ol mp fo qb b ia rr qg l iq qh\" data-selectable-paragraph=\"\"># Draw a rectangle around the faces\nfor (x, y, w, h) in faces:\n    cv2.rectangle(image, (x, y), (x+w, y+h), (255, 255, 0), 2)<\/span><span id=\"4cb2\" class=\"ol mp fo qb b ia rr qg l iq qh\" data-selectable-paragraph=\"\">viewImage(image,faces_detected)<\/span><\/pre>\n<p id=\"a158\" class=\"pw-post-body-paragraph nk nl fo be b gm og nn no gp oh nq nr ns oi nu nv nw oj ny nz oa ok oc od oe fh bj\" data-selectable-paragraph=\"\">The <code class=\"cw ql qm qn qb b\">detectMultiScale<\/code> function is a general function that detects objects. Since we\u2019re calling it on the face cascade, that\u2019s what it detects.<\/p>\n<h2 id=\"a072\" class=\"ol mp fo be mq om on oo mt op oq or mw ns os ot ou nw ov ow ox oa oy oz pa pb bj\" data-selectable-paragraph=\"\">The detectMultiScale function takes 4 parameters<\/h2>\n<ul class=\"\">\n<li id=\"dc98\" class=\"nk nl fo be b gm nm nn no gp np nq nr pc nt nu nv pd nx ny nz pe ob oc od oe pf pg ph bj\" data-selectable-paragraph=\"\">The first parameter is the grayscale image.<\/li>\n<li id=\"a6aa\" class=\"nk nl fo be b gm pi nn no gp pj nq nr pc pk nu nv pd pl ny nz pe pm oc od oe pf pg ph bj\" data-selectable-paragraph=\"\">The second parameter is the <code class=\"cw ql qm qn qb b\">scaleFactor<\/code>. Since some faces may be closer to the camera, they would appear bigger than the faces in the back. The scale factor compensates for this.<\/li>\n<li id=\"7f1e\" class=\"nk nl fo be b gm pi nn no gp pj nq nr pc pk nu nv pd pl ny nz pe pm oc od oe pf pg ph bj\" data-selectable-paragraph=\"\">The detection algorithm uses a moving window to detect objects. <code class=\"cw ql qm qn qb b\">minNeighbors<\/code> defines how many objects are detected near the current one before it declares the face found.<\/li>\n<li id=\"201a\" class=\"nk nl fo be b gm pi nn no gp pj nq nr pc pk nu nv pd pl ny nz pe pm oc od oe pf pg ph bj\" data-selectable-paragraph=\"\"><code class=\"cw ql qm qn qb b\">minSize<\/code>, meanwhile, gives the size of each window.<\/li>\n<\/ul>\n<figure class=\"mh mi mj mk ml mg qz ra paragraph-image\">\n<figure><img loading=\"lazy\" decoding=\"async\" class=\"bg mm mn c\" role=\"presentation\" src=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/1*IUvY3sxQ_j7qErv8Wr1xtg.jpeg\" alt=\"\" width=\"640\" height=\"426\"><\/figure><div class=\"qz ra sj\"><picture><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/format:webp\/1*IUvY3sxQ_j7qErv8Wr1xtg.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/format:webp\/1*IUvY3sxQ_j7qErv8Wr1xtg.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/format:webp\/1*IUvY3sxQ_j7qErv8Wr1xtg.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/format:webp\/1*IUvY3sxQ_j7qErv8Wr1xtg.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/format:webp\/1*IUvY3sxQ_j7qErv8Wr1xtg.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/format:webp\/1*IUvY3sxQ_j7qErv8Wr1xtg.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1280\/format:webp\/1*IUvY3sxQ_j7qErv8Wr1xtg.jpeg 1280w\" type=\"image\/webp\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 640px\"><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/1*IUvY3sxQ_j7qErv8Wr1xtg.jpeg 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/1*IUvY3sxQ_j7qErv8Wr1xtg.jpeg 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/1*IUvY3sxQ_j7qErv8Wr1xtg.jpeg 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/1*IUvY3sxQ_j7qErv8Wr1xtg.jpeg 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/1*IUvY3sxQ_j7qErv8Wr1xtg.jpeg 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/1*IUvY3sxQ_j7qErv8Wr1xtg.jpeg 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1280\/1*IUvY3sxQ_j7qErv8Wr1xtg.jpeg 1280w\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 640px\" data-testid=\"og\"><\/picture><\/div>\n<figcaption class=\"ri rj rk qz ra rl rm be b bf z dv\" data-selectable-paragraph=\"\">2 faces detected!<\/figcaption>\n<\/figure>\n<\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"fh fi fj fk fl\">\n<div class=\"ab ca\">\n<div class=\"ch bg et eu ev ew\">\n<h1 id=\"c567\" class=\"mo mp fo be mq mr pv go mt mu pw gr mw mx px mz na nb py nd ne nf pz nh ni nj bj\" data-selectable-paragraph=\"\">Contours\u2014A method for Object Detection<\/h1>\n<p id=\"bbc4\" class=\"pw-post-body-paragraph nk nl fo be b gm nm nn no gp np nq nr ns nt nu nv nw nx ny nz oa ob oc od oe fh bj\" data-selectable-paragraph=\"\">Using color-based image segmentation, you can detect objects.<br>\n<code class=\"cw ql qm qn qb b\">cv2.findContours<\/code> &amp; <code class=\"cw ql qm qn qb b\">cv2.drawContours<\/code> are two functions that help you with that.<\/p>\n<p id=\"31e3\" class=\"pw-post-body-paragraph nk nl fo be b gm og nn no gp oh nq nr ns oi nu nv nw oj ny nz oa ok oc od oe fh bj\" data-selectable-paragraph=\"\">Recently, I\u2019ve written a very detailed articled called <a class=\"af of\" href=\"https:\/\/towardsdatascience.com\/object-detection-via-color-based-image-segmentation-using-python-e9b7c72f0e11\" target=\"_blank\" rel=\"noopener\">Object detection via color-based image segmentation using Python<\/a>. Everything you need to know about contours is there.<\/p>\n<\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"fh fi fj fk fl\">\n<div class=\"ab ca\">\n<div class=\"ch bg et eu ev ew\">\n<h1 id=\"29e6\" class=\"mo mp fo be mq mr pv go mt mu pw gr mw mx px mz na nb py nd ne nf pz nh ni nj bj\" data-selectable-paragraph=\"\">Finally, Saving the image<\/h1>\n<pre class=\"mh mi mj mk ml qa qb qc qd ax qe bj\"><span id=\"dbae\" class=\"ol mp fo qb b ia qf qg l iq qh\" data-selectable-paragraph=\"\">import cv2\nimage = cv2.imread(\".\/Import\/path.extension\")\ncv2.imwrite(\".\/Export\/Path.extension\", image)<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"fh fi fj fk fl\">\n<div class=\"ab ca\">\n<div class=\"ch bg et eu ev ew\">\n<h1 id=\"36f9\" class=\"mo mp fo be mq mr pv go mt mu pw gr mw mx px mz na nb py nd ne nf pz nh ni nj bj\" data-selectable-paragraph=\"\">To Conclude<\/h1>\n<p id=\"4646\" class=\"pw-post-body-paragraph nk nl fo be b gm nm nn no gp np nq nr ns nt nu nv nw nx ny nz oa ob oc od oe fh bj\" data-selectable-paragraph=\"\">OpenCV is a library full of great easy-to-use algorithms that can be used in 3D modeling, advanced image &amp; video editing, tracking an identifying objects in videos, classifying people who are doing a certain action in videos, finding similar images from a dataset of images, and much more.<\/p>\n<p id=\"39ff\" class=\"pw-post-body-paragraph nk nl fo be b gm og nn no gp oh nq nr ns oi nu nv nw oj ny nz oa ok oc od oe fh bj\" data-selectable-paragraph=\"\">The bottom line is that learning OpenCV is crucial for people who want to take part in machine learning projects that are image-related.<\/p>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>What is OpenCV-Python? OpenCV is an open source computer vision and machine learning library. It has 2500+ optimized algorithms\u2014a comprehensive set of both classic and state-of-the-art computer vision and machine learning algorithms. It has many interfaces, including Python, Java, C++, and Matlab. Here, we\u2019re gonna tackle the Python interface. Table of Contents Installation Importing\/Viewing an [&hellip;]<\/p>\n","protected":false},"author":76,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"customer_name":"","customer_description":"","customer_industry":"","customer_technologies":"","customer_logo":"","footnotes":""},"categories":[6],"tags":[],"coauthors":[173],"class_list":["post-7134","post","type-post","status-publish","format-standard","hentry","category-machine-learning"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.9 (Yoast SEO v25.9) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>OpenCV-Python Cheat Sheet: From Importing Images to Face Detection - Comet<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.comet.com\/site\/blog\/opencv-python-cheat-sheet-from-importing-images-to-face-detection\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"OpenCV-Python Cheat Sheet: From Importing Images to Face Detection\" \/>\n<meta property=\"og:description\" content=\"What is OpenCV-Python? OpenCV is an open source computer vision and machine learning library. It has 2500+ optimized algorithms\u2014a comprehensive set of both classic and state-of-the-art computer vision and machine learning algorithms. It has many interfaces, including Python, Java, C++, and Matlab. Here, we\u2019re gonna tackle the Python interface. Table of Contents Installation Importing\/Viewing an [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.comet.com\/site\/blog\/opencv-python-cheat-sheet-from-importing-images-to-face-detection\/\" \/>\n<meta property=\"og:site_name\" content=\"Comet\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/cometdotml\" \/>\n<meta property=\"article:published_time\" content=\"2023-08-14T13:10:24+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-04-24T17:14:45+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/miro.medium.com\/v2\/resize:fit:2000\/1*77qCS1xRajFADWdT50c2dg.jpeg\" \/>\n<meta name=\"author\" content=\"Salma Ghoneim\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@Cometml\" \/>\n<meta name=\"twitter:site\" content=\"@Cometml\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Salma Ghoneim\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"OpenCV-Python Cheat Sheet: From Importing Images to Face Detection - Comet","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.comet.com\/site\/blog\/opencv-python-cheat-sheet-from-importing-images-to-face-detection\/","og_locale":"en_US","og_type":"article","og_title":"OpenCV-Python Cheat Sheet: From Importing Images to Face Detection","og_description":"What is OpenCV-Python? OpenCV is an open source computer vision and machine learning library. It has 2500+ optimized algorithms\u2014a comprehensive set of both classic and state-of-the-art computer vision and machine learning algorithms. It has many interfaces, including Python, Java, C++, and Matlab. Here, we\u2019re gonna tackle the Python interface. Table of Contents Installation Importing\/Viewing an [&hellip;]","og_url":"https:\/\/www.comet.com\/site\/blog\/opencv-python-cheat-sheet-from-importing-images-to-face-detection\/","og_site_name":"Comet","article_publisher":"https:\/\/www.facebook.com\/cometdotml","article_published_time":"2023-08-14T13:10:24+00:00","article_modified_time":"2025-04-24T17:14:45+00:00","og_image":[{"url":"https:\/\/miro.medium.com\/v2\/resize:fit:2000\/1*77qCS1xRajFADWdT50c2dg.jpeg","type":"","width":"","height":""}],"author":"Salma Ghoneim","twitter_card":"summary_large_image","twitter_creator":"@Cometml","twitter_site":"@Cometml","twitter_misc":{"Written by":"Salma Ghoneim","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.comet.com\/site\/blog\/opencv-python-cheat-sheet-from-importing-images-to-face-detection\/#article","isPartOf":{"@id":"https:\/\/www.comet.com\/site\/blog\/opencv-python-cheat-sheet-from-importing-images-to-face-detection\/"},"author":{"name":"Salma Ghoneim","@id":"https:\/\/www.comet.com\/site\/#\/schema\/person\/7d1866c12b28d54aadfc2abe675ca29e"},"headline":"OpenCV-Python Cheat Sheet: From Importing Images to Face Detection","datePublished":"2023-08-14T13:10:24+00:00","dateModified":"2025-04-24T17:14:45+00:00","mainEntityOfPage":{"@id":"https:\/\/www.comet.com\/site\/blog\/opencv-python-cheat-sheet-from-importing-images-to-face-detection\/"},"wordCount":906,"publisher":{"@id":"https:\/\/www.comet.com\/site\/#organization"},"image":{"@id":"https:\/\/www.comet.com\/site\/blog\/opencv-python-cheat-sheet-from-importing-images-to-face-detection\/#primaryimage"},"thumbnailUrl":"https:\/\/miro.medium.com\/v2\/resize:fit:2000\/1*77qCS1xRajFADWdT50c2dg.jpeg","articleSection":["Machine Learning"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.comet.com\/site\/blog\/opencv-python-cheat-sheet-from-importing-images-to-face-detection\/","url":"https:\/\/www.comet.com\/site\/blog\/opencv-python-cheat-sheet-from-importing-images-to-face-detection\/","name":"OpenCV-Python Cheat Sheet: From Importing Images to Face Detection - Comet","isPartOf":{"@id":"https:\/\/www.comet.com\/site\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.comet.com\/site\/blog\/opencv-python-cheat-sheet-from-importing-images-to-face-detection\/#primaryimage"},"image":{"@id":"https:\/\/www.comet.com\/site\/blog\/opencv-python-cheat-sheet-from-importing-images-to-face-detection\/#primaryimage"},"thumbnailUrl":"https:\/\/miro.medium.com\/v2\/resize:fit:2000\/1*77qCS1xRajFADWdT50c2dg.jpeg","datePublished":"2023-08-14T13:10:24+00:00","dateModified":"2025-04-24T17:14:45+00:00","breadcrumb":{"@id":"https:\/\/www.comet.com\/site\/blog\/opencv-python-cheat-sheet-from-importing-images-to-face-detection\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.comet.com\/site\/blog\/opencv-python-cheat-sheet-from-importing-images-to-face-detection\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.comet.com\/site\/blog\/opencv-python-cheat-sheet-from-importing-images-to-face-detection\/#primaryimage","url":"https:\/\/miro.medium.com\/v2\/resize:fit:2000\/1*77qCS1xRajFADWdT50c2dg.jpeg","contentUrl":"https:\/\/miro.medium.com\/v2\/resize:fit:2000\/1*77qCS1xRajFADWdT50c2dg.jpeg"},{"@type":"BreadcrumbList","@id":"https:\/\/www.comet.com\/site\/blog\/opencv-python-cheat-sheet-from-importing-images-to-face-detection\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.comet.com\/site\/"},{"@type":"ListItem","position":2,"name":"OpenCV-Python Cheat Sheet: From Importing Images to Face Detection"}]},{"@type":"WebSite","@id":"https:\/\/www.comet.com\/site\/#website","url":"https:\/\/www.comet.com\/site\/","name":"Comet","description":"Build Better Models Faster","publisher":{"@id":"https:\/\/www.comet.com\/site\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.comet.com\/site\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.comet.com\/site\/#organization","name":"Comet ML, Inc.","alternateName":"Comet","url":"https:\/\/www.comet.com\/site\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.comet.com\/site\/#\/schema\/logo\/image\/","url":"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2025\/01\/logo_comet_square.png","contentUrl":"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2025\/01\/logo_comet_square.png","width":310,"height":310,"caption":"Comet ML, Inc."},"image":{"@id":"https:\/\/www.comet.com\/site\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/cometdotml","https:\/\/x.com\/Cometml","https:\/\/www.youtube.com\/channel\/UCmN63HKvfXSCS-UwVwmK8Hw"]},{"@type":"Person","@id":"https:\/\/www.comet.com\/site\/#\/schema\/person\/7d1866c12b28d54aadfc2abe675ca29e","name":"Salma Ghoneim","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.comet.com\/site\/#\/schema\/person\/image\/e917fcbaafac29feaac6cd8eb2980eae","url":"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2023\/08\/1575134294179-96x96.jpg","contentUrl":"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2023\/08\/1575134294179-96x96.jpg","caption":"Salma Ghoneim"},"url":"https:\/\/www.comet.com\/site\/blog\/author\/salmaghoneimgmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/posts\/7134","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/users\/76"}],"replies":[{"embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/comments?post=7134"}],"version-history":[{"count":1,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/posts\/7134\/revisions"}],"predecessor-version":[{"id":15580,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/posts\/7134\/revisions\/15580"}],"wp:attachment":[{"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/media?parent=7134"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/categories?post=7134"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/tags?post=7134"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/coauthors?post=7134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}