{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "c374c692-c572-435c-801a-2f333fcca072", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import os\n", "import pandas as pd\n", "import cv2" ] }, { "cell_type": "markdown", "id": "62097702", "metadata": {}, "source": [ "### ANIMATION" ] }, { "cell_type": "code", "execution_count": 13, "id": "cd720adf-e50b-41d1-88f9-aa44e0e09c7e", "metadata": {}, "outputs": [], "source": [ "## Vertical Line\n", "canva = np.full((500,500,3),255,dtype = np.uint8)\n", "\n", "cv2.line(canva,(255,0),(255,500),(255,0,0),4)\n", "\n", "cv2.imshow(\"line\",canva)\n", "cv2.waitKey()\n", "cv2.destroyAllWindows()" ] }, { "cell_type": "code", "execution_count": 15, "id": "43c537d0-b710-4b91-92de-5d6c0173156b", "metadata": {}, "outputs": [], "source": [ "## half Vertical Line\n", "canva = np.full((500,500,3),255,dtype = np.uint8)\n", "\n", "cv2.line(canva,(255,0),(255,255),(255,0,0),4)\n", "\n", "cv2.imshow(\"line\",canva)\n", "cv2.waitKey()\n", "cv2.destroyAllWindows()" ] }, { "cell_type": "code", "execution_count": 16, "id": "8116c579-9fe2-4c0b-a9fc-2550462943bf", "metadata": {}, "outputs": [], "source": [ "## Horizontal Line\n", "canva = np.full((500,500,3),255,dtype = np.uint8)\n", "\n", "cv2.line(canva,(0,250),(500,250),(255,0,0),4)\n", "\n", "cv2.imshow(\"line\",canva)\n", "cv2.waitKey()\n", "cv2.destroyAllWindows()" ] }, { "cell_type": "markdown", "id": "940f66d9-1902-4555-baa9-fa53617642f7", "metadata": {}, "source": [ "### To Draw Rectangle or Square" ] }, { "cell_type": "code", "execution_count": 19, "id": "865b917e-0f84-4b9b-aec7-38af180f4f85", "metadata": {}, "outputs": [], "source": [ "canva = np.full((500,500,3),255,dtype =np.uint8)\n", "\n", "cv2.rectangle(canva,(200,200),(400,400),(255,0,0),2)\n", "\n", "cv2.rectangle(canva,(300,200),(400,500),(255,0,0),-1)\n", "\n", "cv2.imshow(\"rectangle\",canva)\n", "cv2.waitKey()\n", "cv2.destroyAllWindows()" ] }, { "cell_type": "code", "execution_count": 23, "id": "4a9238cd-b1ac-4488-a211-c95bfdb0c4a5", "metadata": {}, "outputs": [], "source": [ "canva = np.full((500,500,3),255,dtype =np.uint8)\n", "cv2.rectangle(canva,(200,200),(500,400),(255,0,0),2)\n", "\n", "cv2.imshow(\"rectangle\",canva)\n", "cv2.waitKey()\n", "cv2.destroyAllWindows()" ] }, { "cell_type": "markdown", "id": "81eed0c7-424f-4927-9777-1a9ccce97ef5", "metadata": {}, "source": [ "### How to draw Circle" ] }, { "cell_type": "code", "execution_count": 27, "id": "eb691c15-6eb3-4d98-acf1-ce606f1741b1", "metadata": {}, "outputs": [], "source": [ "canva = np.full((500,500,3),255,dtype =np.uint8)\n", "\n", "cv2.circle(canva,(250,250),150,(255,0,0),2)\n", "##image,center(pixel)(c,r),radius,color,thickness of the circle\n", "\n", "cv2.imshow(\"circle\",canva)\n", "cv2.waitKey()\n", "cv2.destroyAllWindows()\n" ] }, { "cell_type": "markdown", "id": "c68bce2d-1c22-4dee-a1d0-f450acdffc67", "metadata": {}, "source": [ "#### both circle and rectangle" ] }, { "cell_type": "code", "execution_count": 29, "id": "5a56c0d7-5d60-4a44-a6d0-8acbc6c67827", "metadata": {}, "outputs": [], "source": [ "canva = np.full((500,500,3),255,dtype =np.uint8)\n", "\n", "cv2.circle(canva,(250,250),150,(255,0,0),2)\n", "cv2.rectangle(canva,(200,200),(500,400),(0,255,0),-1)\n", "\n", "cv2.imshow(\"circle\",canva)\n", "cv2.waitKey()\n", "cv2.destroyAllWindows()" ] }, { "cell_type": "markdown", "id": "b78ad4a9-8f9b-429a-8f13-5311574f6275", "metadata": {}, "source": [ "### To draw polyLines" ] }, { "cell_type": "code", "execution_count": 35, "id": "e3381b1e-6ebc-4e5c-8f4f-bd59c92b0352", "metadata": {}, "outputs": [], "source": [ "pts = np.array([[12,15],[56,78],[89,10],[25,40],[60,30]])\n", "\n", "canva = np.full((500,500,3),255,dtype =np.uint8)\n", "\n", "pts = pts.reshape((-1,1,2))\n", "\n", "cv2.polylines(canva,[pts],True,(0,255,0),4)\n", "\n", "\n", "cv2.imshow(\"polylines\",canva)\n", "cv2.waitKey()\n", "cv2.destroyAllWindows()" ] }, { "cell_type": "markdown", "id": "d8f6f98b-2cb0-48f3-86b7-ffda383bfd30", "metadata": {}, "source": [ "### TO put text in inside the canvas" ] }, { "cell_type": "code", "execution_count": 37, "id": "30935fee-c89b-4742-9037-788a47f3b4fc", "metadata": {}, "outputs": [], "source": [ "canva = np.full((600,600,3),255,dtype =np.uint8)\n", "\n", "cv2.putText(canva,\"Bai Phaneendra\",(100,100),cv2.FONT_ITALIC,2,(255,0,0),8)\n", "\n", "cv2.imshow(\"txt\",canva)\n", "cv2.waitKey()\n", "cv2.destroyAllWindows()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.4" } }, "nbformat": 4, "nbformat_minor": 5 }