简体   繁体   中英

How to draw Filled rectangle to every frame of video by using opencv python

If i want to add Black filled rectangle at Bottom left (x1,y1) and Top right (x2,y2) to every frame of my Video How can i do it?

here is the general method for rectangle

image = cv2.rectangle(image, start_point, end_point, color, thickness)

in our case use thickness as -1 to fill the rectangle

image = cv2.rectangle(image, (x1,y1), (x2,y2), (0,0,0), -1)

Similar to what @muhammad-safwan said, but this should also help you put it in each frame of your video:

You haven't provided us with any code but I am assuming it looks similar to this (where cap is your video capture source):

while True:
    ret, image = cap.read()
    image = cv2.resize(image, (500, 500))
    
    # this is the part to add to your code
    cv2.rectangle(image, (0, 0), (200, 200), (0, 0, 0), -1)

    cv2.imshow("My Video", image)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        cv2.destroyAllWindows()

Use cv2.rectangle(image, (0, 0), (200, 200), (0, 0, 0), -1) to add the rectangle to every frame (variable used is image) in your video.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM