Beispiel #1
0
def main():
    logging.basicConfig(level=logging.INFO)

    # args = parse_args()

    image_file = "images/parking_lot_1.png"  #args.image_file
    data_file = "data/coordinates_1.yml"  #args.data_file
    start_frame = 0  #args.start_frame

    if image_file is not None:
        with open(data_file, "w+") as points:
            generator = CoordinatesGenerator(image_file, points, COLOR_RED)
            generator.generate()
        storeCor = open("data\\pastCordinate.pickle", 'wb')

        # source, destination
        pickle.dump(generator.saveCordinate, storeCor)
        storeCor.close()
        print(generator.saveCordinate)
        logging.info(generator.saveCordinate)

    with open(data_file, "r") as data:
        points = yaml.load(data)
        # points = load(data, Loader=yaml.Loader)
        # detector = MotionDetector(args.video_file, points, int(start_frame))
        detector = MotionDetector("videos/parking_lot_1.mp4", points,
                                  int(start_frame))
        #pass the spot no which you want to spot
        # in image the spotno are 1 index
        spotNo = 0
        detector.detect_motion(spotNo)
Beispiel #2
0
def main():
    logging.basicConfig(level=logging.INFO)

    cap = cv2.VideoCapture("./videos/sample1.mp4")

    ret, frame = cap.read()
    #cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
    #cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
    cv2.imwrite('test111.jpg', frame)


    start_frame = "4000"
    image_file = "./images/parking_lot_1.png"
    test_image = "test111.jpg"
    data_file = "./data/coordinates_1.yml"
    video_file = "./videos/sample1.mp4"
    #video_url = "parking_lot_1.mp4"
    video_url = "C:/Users/YHJ/PycharmProjects/parkingLot/DetectParking-develop/ParkingLot-master/parking_lot/videos/sample1.mp4"



    if image_file is not None:
        with open(data_file, "w+") as points:

            generator = CoordinatesGenerator(test_image, points, COLOR_RED)
            generator.generate()

    with open(data_file, "r") as data:
        points = yaml.load(data , Loader=yaml.FullLoader)
        print(points)
        detector = MotionDetector(video_file, points, int(start_frame))
        detector.detect_motion()
        print("sdfs")
def gen(name):
    data_file = 'data/' + name + '.yml'
    start_frame = '1'
    video_file = 'videos/' + name + '.mp4'

    with open(data_file, "r") as data:
        points = yaml.load(data, Loader=yaml.FullLoader)
        detector = MotionDetector(video_file, points, int(start_frame))
        detector.detect_motion()
Beispiel #4
0
def main():

    print('main executed')
    logging.basicConfig(level=logging.INFO)

    image_file = "images/parking_lot_1.png"
    data_file = "data/coordinates_1.yml"
    start_frame = 400
    video_file = "videos/parking_lot_1.mp4"

    f = open("config.txt", "r")
    arr = {}
    for _ in range(0, 2):
        result = f.readline()
        arr[result.split(' : ')[0]] = result.split(' : ')[-1].split('\n')[0]
    print(arr)
    f.close()
    url = arr['img_url']

    img_resp_pic = requests.get(url)
    img_arr_pic = np.array(bytearray(img_resp_pic.content), dtype=np.uint8)
    img1_pic = cv2.imdecode(img_arr_pic, -1)
    filename = 'savedImage.jpg'
    cv2.imwrite(filename, img1_pic)

    #cv2.imshow("AndroidCamPic",img1_pic)
    #cv2.waitKey(0)==27

    #cv2.destroyWindow("AndroidCamPic")
    '''while True:
        img_resp= requests.get(url)
        img_arr= np.array(bytearray(img_resp.content),dtype=np.uint8)
        img = cv2.imdecode(img_arr, -1)
        
        cv2.imshow("AndroidCam",img)
        
        if cv2.waitKey(1)==27:
             break
    cv2.destroyWindow("AndroidCamPic")'''
    if filename is not None:
        with open(data_file, "w+") as points:
            generator = CoordinatesGenerator(filename, points, COLOR_RED)
            generator.generate()

    with open(data_file, "r") as data:
        '''try:
            thread.start_new_thread( MotionDetector, ( ) )
            thread.start_new_thread( alpr, ( ) )
        except:
            print("Error: unable to start thread")'''
        points = yaml.load(data)
        detector = MotionDetector(video_file, points, int(start_frame))
        detector.detect_motion()
Beispiel #5
0
def main():
    
    logging.basicConfig(level=logging.INFO)

    args = parse_args()

    image_file = args.image_file
    data_file = args.data_file
    start_frame = args.start_frame
    
    if image_file is not None:
            with open(data_file, "w+") as points:
                generator = CoordinatesGenerator(image_file, points, COLOR_RED)
                generator.generate()
    
    while(1>0) :
        
        capture_duration = 10
        
        cap = cv2.VideoCapture(1)
        
        start_time = time.time()

        if(cap.isOpened()== False):
            print("error")
        fourcc = cv2.VideoWriter_fourcc(*'mp4v')
        out = cv2.VideoWriter('videos/output.mp4', -1, 20.0, (640,480))
        
        while(int(time.time() - start_time) < capture_duration):
            ret, frame = cap.read()
            if ret == True:
                out.write(frame)
                cv2.imshow('Frame',frame)
                if cv2.waitKey(1) & 0xFF == ord('q'):
                    break
            else:
                break
        cap.release()
        out.release()
        cv2.destroyAllWindows()
        
          
        

        with open(data_file, "r") as data:
            points = yaml.load(data,Loader=yaml.FullLoader)
            
            #CALL MotionDetector from motion_detector.py
            detector = MotionDetector(args.video_file, points, int(start_frame))
            detector.detect_motion()
Beispiel #6
0
def main():
    logging.basicConfig(level=logging.INFO)

    image_file = "images/parking_lot_1.png"
    data_file = "data/coordinates_1.yml"
    start_frame = 400
    video_file = "videos/parking_lot_1.mp4"

    if image_file is not None:
        with open(data_file, "w+") as points:
            generator = CoordinatesGenerator(image_file, points, COLOR_RED)
            generator.generate()

    with open(data_file, "r") as data:
        points = yaml.load(data)
        detector = MotionDetector(video_file, points, int(start_frame))
        detector.detect_motion()
def main():
    logging.basicConfig(level=logging.INFO)

    args = parse_args()

    image_file = args.image_file
    data_file = args.data_file
    start_frame = args.start_frame

    if image_file is not None:
        with open(data_file, "w+") as points:
            generator = CoordinatesGenerator(image_file, points, COLOR_RED)
            generator.generate()

    with open(data_file, "r") as data:
        points = yaml.safe_load(data)
        detector = MotionDetector(args.video_file, points, int(start_frame))
        detector.detect_motion()
Beispiel #8
0
def main():
    logging.basicConfig(level=logging.INFO)

    args = parse_args()

    image_file = args.image_file
    data_file = args.data_file
    start_frame = args.start_frame

    # If image file is provided, prompt user to generate rectangles
    if image_file is not None:
        with open(data_file, "w+") as points:
            generator = CoordinatesGenerator(image_file, points, COLOR_RED)
            generator.generate()

    # Read coordinates_1.yml in...
    with open(data_file, "r") as data:
        points = yaml.load(data)
        detector = MotionDetector(args.video_file, points, int(start_frame))
        detector.detect_motion()
Beispiel #9
0
def main():
    logging.basicConfig(level=logging.INFO)

    args = parse_args()

    image_file = args.image_file
    data_generate_file = args.data_generate_file
    data_file = args.data_file
    video_file = args.video_file
    start_frame = args.start_frame

    # generate coordinate based data map.
    if image_file is not None and args.data_generate_file:
        with open(data_generate_file, "w+") as points:
            generator = CoordinatesGenerator(image_file, points, COLOR_RED)
            generator.generate()

    # read from coordinate data map
    if data_file is not None and video_file is not None:
        with open(data_file, "r") as data:
            #points = yaml.load(data)
            points = yaml.safe_load(data)
            detector = MotionDetector(video_file, points, int(start_frame))
            detector.detect_motion()
Beispiel #10
0
class Controller:
    def __init__(self, points, previousTime, currentTime, waterLevelSlots):

        self.points = points
        self.previousTime = previousTime
        self.currentTime = currentTime
        self.waterLevelSlots = waterLevelSlots
        self.detector = MotionDetector(self.points, 1, self.waterLevelSlots)

    def runController(self):

        workingDirectory = os.getcwd() + '\\captured_videos'
        hasIncomingVideoCaptureChanged = False
        try:

            videoCaptureDirectory = max([
                os.path.join(workingDirectory, d)
                for d in os.listdir(workingDirectory)
            ],
                                        key=os.path.getmtime)

            self.currentTime = time.ctime(
                os.path.getmtime(videoCaptureDirectory))

        except FileNotFoundError:
            pass

        if self.currentTime == self.previousTime:
            hasIncomingVideoCaptureChanged = False
            return None, None

        hasIncomingVideoCaptureChanged = True
        self.previousTime = self.currentTime

        videoFilePath = videoCaptureDirectory + '//output.mp4'

        return self.detector.detect_motion(
            videoFilePath,
            hasIncomingVideoCaptureChanged), self.waterLevelSlots