import os
import cv2

# os.environ["config"]="{\"TZ\": \"Asia/Kolkata\", \"MONGO_URI\": \"mongodb://admin:iLens$1234@192.168.3.181:2717/admin\", \"MONGO_DATABASE\": \"ilens_ai\", \"MONGO_COLLECTION\": \"janusDeployment\", \"MONGO_KEY\": \"deploymentId\", \"MONGO_VALUE\": \"aarti_ppe\", \"MONGO_COLL\": \"serviceConfiguration\", \"MONGO_DB\": \"ilens_ai\"}"
from edge_engine.edge_processor import ExecutePipeline
from edge_engine.edge_processor import Pubs
from scripts import Ppe
from edge_engine.common.config import EDGE_CONFIG

if __name__ == '__main__':
    pubs = Pubs()
    mod = Ppe(config=EDGE_CONFIG,
              model_config=EDGE_CONFIG["modelConfig"],
              pubs=pubs,
              device_id=EDGE_CONFIG['deviceId'])
    ex = ExecutePipeline(mod)
    ex.run_model()

    # For testing Only

    # cap = cv2.VideoCapture("data/aarti.mp4")
    # count = 0
    # while True:
    #     ret, frame = cap.read()
    #     if not ret:
    #         print("Error reading frame from stream")
    #         break
    #     frame = cv2.resize(frame, (800, 600),
    #                        interpolation=cv2.INTER_LINEAR)
    #     obj = {'frame': frame, 'frameId': count}
    #     frame = mod._predict(obj)
    #     count = count + 1
    #     # if cv2.waitKey(1) & 0xFF == ord('q'):
    #     #     break
    # cap.release()
