import cv2 as cv
import numpy as np
from gstreamer import gstreamer_pipeline0, gstreamer_pipeline1
from agentspace import Agent, space

class CameraAgent(Agent):

    def __init__(self,cameraId,nameImage):
        self.cameraId = cameraId
        self.nameImage = nameImage
        super().__init__()

    def init(self): 
        if self.cameraId == 0:
            pipeline = gstreamer_pipeline0(1280,720,1280//2,720//2,20,0)
        elif self.cameraId == 1:
            pipeline = gstreamer_pipeline1(320,240,320,240,10)
        else:
            pipeline = self.cameraId
        self.camera = cv.VideoCapture(pipeline, cv.CAP_GSTREAMER)
        while True:
            hasFrame, frame = self.camera.read() 
            if hasFrame: 
                space(validity=0.15)[self.nameImage] = frame
    
    def senseSelectAct(self):
        pass

