Skip to content Skip to sidebar Skip to footer

Can I Render An Opencv Animation From A Background Thread In Python?

Can I render an openCV animation from a background thread in Python? Here is my attempt: import cv2 import numpy as np from time import sleep bitmap = np.zeros((512,512,3),np.uint

Solution 1:

This doesn't answer the question, but it solves the problem:

import cv2
import numpy as np
from time import sleep


import threading
import time

bitmap = np.zeros((512,512,3),np.uint8)
def update_bitmap():
    for i in range(512):
        bitmap[i,i,:] = 128
        sleep(1/32)


def main():
    threading.Thread(target=update_bitmap).start()

    hz = 30
    delta_t = 1 / hz
    t = time.time()
    try:
        while True:
            sleep(0.001)
            if time.time() > t+delta_t:
                t += delta_t
                cv2.imshow("Color Image", bitmap)
                cv2.waitKey(1)

    except KeyboardInterrupt:
        cv2.destroyAllWindows()
        exit(0)

main()

Post a Comment for "Can I Render An Opencv Animation From A Background Thread In Python?"