How to draw Filled rectangle to every frame of video by using Python-OpenCV? Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report In this article, we will discuss how to draw a filled rectangle on every frame of video through OpenCV in Python. Stepwise Implementation:Import the required libraries into the working space.Read the video on which you have to write. Syntax: cap = cv2.VideoCapture("path") Create an output file using cv2.VideoWriter_fourcc() method. Here you will have options of video formats. Syntax: output = cv2.VideoWriter("output.avi", cv2.VideoWriter_fourcc(*'MPEG'), 30, (1080, 1920)) Then edit the frames of the video by adding shapes to it (In our case it is a filled rectangle). We will use the cv2.rectangle() method. This method is used to draw a rectangle on any image. Syntax: cv2.rectangle(frame, (100, 100), (500, 500), (0, 255, 0), -1) Then write all the frames in the video file. Syntax: output.write(frame) Example: In this example, we add a green rectangle to the video. Input Video: Python3 import cv2 def main(): # reading the input cap = cv2.VideoCapture("input.mp4") output = cv2.VideoWriter( "output.avi", cv2.VideoWriter_fourcc(*'MPEG'), 30, (1080, 1920)) while(True): ret, frame = cap.read() if(ret): # adding filled rectangle on each frame cv2.rectangle(frame, (100, 150), (500, 600), (0, 255, 0), -1) # writing the new frame in output output.write(frame) cv2.imshow("output", frame) if cv2.waitKey(1) & 0xFF == ord('s'): break else: break cv2.destroyAllWindows() output.release() cap.release() if __name__ == "__main__": main() Output: Comment More infoAdvertise with us Next Article Interview Preparation For Software Developers B bhavyajain4641 Follow Improve Article Tags : Python OpenCV Python-OpenCV Practice Tags : python Similar Reads Interview PreparationInterview Preparation For Software DevelopersMust Coding Questions - Company-wise Must Do Coding Questions - Topic-wiseCompany-wise Practice ProblemsCompany PreparationCompetitive ProgrammingSoftware Design-PatternsCompany-wise Interview ExperienceExperienced - Interview ExperiencesInternship - Interview ExperiencesPractice @GeeksforgeeksProblem of the DayTopic-wise PracticeDifficulty Level - SchoolDifficulty Level - BasicDifficulty Level - EasyDifficulty Level - MediumDifficulty Level - HardLeaderboard !!Explore More...Data StructuresArraysLinked ListStackQueueBinary TreeBinary Search TreeHeapHashingGraphAdvance Data StructuresMatrixStringAll Data StructuresAlgorithmsAnalysis of AlgorithmsSearching AlgorithmsSorting AlgorithmsPattern SearchingGeometric AlgorithmsMathematical AlgorithmsRandomized AlgorithmsGreedy AlgorithmsDynamic ProgrammingDivide & ConquerBacktrackingBranch & BoundAll AlgorithmsProgramming LanguagesCC++JavaPythonC#Go LangSQLPHPScalaPerlKotlinWeb TechnologiesHTMLCSSJavaScriptBootstrapTailwind CSSAngularJSReactJSjQueryNodeJSPHPWeb DesignWeb BrowserFile FormatsComputer Science SubjectsOperating SystemsDBMSComputer NetworkComputer Organization & ArchitectureTOCCompiler DesignDigital Elec. & Logic DesignSoftware EngineeringEngineering MathematicsData Science & MLComplete Data Science CourseData Science TutorialMachine Learning TutorialDeep Learning TutorialNLP TutorialMachine Learning ProjectsData Analysis TutorialTutorial LibraryPython TutorialDjango TutorialPandas TutorialKivy TutorialTkinter TutorialOpenCV TutorialSelenium TutorialGATE CSGATE CS NotesGate CornerPrevious Year GATE PapersLast Minute Notes (LMNs)Important Topic For GATE CSGATE CoursePrevious Year Paper: CS exams Like