'read frames asynchronously from webcam using golang

Using Python, i've implemented a class that reads frames from webcam asynchrounously so i can increase the fps of my live stream everything was working quite well, i have been using the class WebcamVideoStream and FileVideoStream that are located in imutils.video. The code provided there is the next :

class WebcamVideoStream:

def __init__(self, src=0, name="WebcamVideoStream"):
    # initialize the video camera stream and read the first frame
    # from the stream
    self.stream = cv2.VideoCapture(src)
    (self.grabbed, self.frame) = self.stream.read()
    # initialize the thread name
    self.name = name

    # initialize the variable used to indicate if the thread should
    # be stopped
    self.stopped = False

def start(self):
    # start the thread to read frames from the video stream
    t = Thread(target=self.update, name=self.name, args=())
    t.daemon = True
    t.start()
    return self

def update(self):
    # keep looping infinitely until the thread is stopped
    while True:
        # if the thread indicator variable is set, stop the thread
        if self.stopped:
            return

        # otherwise, read the next frame from the stream
        (self.grabbed, self.frame) = self.stream.read()

def read(self):
    # return the frame most recently read
    return self.frame

def stop(self):
    # indicate that the thread should be stopped
    self.stopped = True

i can start communication with the webcam using this line of code :

image = WebcamVideoStream("Camera_IP").start()
frame = image.read()

now am trying to do exactly the same thing but using gocv and golang, which means i dont want to use the function : gocv.OpenVideoCapture("url") and frame.Read(&img) directly but i want to make them in a separate thread, i made a lot of researches on the web to find a way to do it but no results, can anyone help me with that please ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source