Beispiel #1
0
    def carregar_preparar_dados(self, empty_path = 'dataset/rawdataset/empty', occupied_path = 'dataset/rawdataset/occupied'):
        
        empty = image_utils().load_image_from_path(empty_path)
        occup = image_utils().load_image_from_path(occupied_path)

        #print(empty)

        train_empty = empty[0:100]
        test_empty = empty[100:150]

        train_occup = occup[0:100]
        test_occup = occup[100:150]

        train_empty = np.asarray(train_empty)
        #print(train_empty.shape)
        base_train = np.concatenate([train_empty, train_occup])
        base_test = np.concatenate([test_empty, test_occup])

        #print(base_train.shape)
        #print(base_test.shape)


        labels_train = np.zeros(200, dtype=np.int)
        labels_train[100:200] = np.ones(100, dtype=np.int)

        labels_test = np.zeros(100, dtype=np.int)
        labels_test[50:100] = np.ones(50, dtype=np.int)

        #print(labels_train[0:100])


        train_zip = zip (base_train,labels_train)
        test_zip = zip (base_test,labels_test)
        
        return base_train,base_test, labels_train, labels_test
Beispiel #2
0
    def training (self):

        base_train,base_test, labels_train, labels_test = self.carregar_preparar_dados()

        features_train = image_utils().extract_features(base_train)
        features_test = image_utils().extract_features(base_test)


        SVM().train(features_train,labels_train,features_test,labels_test)
        #SVM().test(features_test,labels_test)

        features_test = features_test[94].reshape(1,-1)
        SVM().predict(features_test)
Beispiel #3
0
    def testing (self):
        base_train,base_test, labels_train, labels_test = self.carregar_preparar_dados()

        features_train = image_utils().extract_features(base_train)
        features_test = image_utils().extract_features(base_test)


        SVM().test(features_test,labels_test)

        







        

#Call_SVM().training()
Beispiel #4
0
def generateVideo(boxes, statusWindow):
    path = 'videos/p2.mp4'
    vs = cv2.VideoCapture(path)
    fps = 12
    capSize = (640, 360)

    fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'v')

    out = cv2.VideoWriter()
    success = out.open('./teste5.mp4', fourcc, fps, capSize, True)

    num_frames = count_frames(path)
    #print(num_frames)

    get_point = 0
    i = 0

    try:
        while i < num_frames:
            ret, frame = vs.read()

            frame = imutils.resize(frame, width=450)

            gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
            #cv2.imshow("gray ", gray )

            gau = cv2.GaussianBlur(gray, (7, 7), 0)

            img_resize = image_utils.getRotateRect(gau, boxes)
            feature = image_utils().extract_features(img_resize)

            timestamp = datetime.datetime.now()

            score = SVM().predict(feature)

            available_slots = []

            for index, scr in enumerate(score):
                if scr == 0:
                    cv2.polylines(frame, np.int32([boxes[index]]), True,
                                  (0, 0, 255), 2)
                    s = False
                    i = 0
                else:
                    ## if the parking slot is availble

                    slot_first_x_cord = float(boxes[index][1][0])

                    if (checkMinimum(available_slots, slot_first_x_cord)):
                        cv2.polylines(frame, np.int32([boxes[index]]), True,
                                      (255, 0, 0), 2)

                        if s == False:
                            cv2.putText(
                                frame,
                                timestamp.strftime(
                                    " Available: %d %m %Y %I:%M:%S"),
                                (10, frame.shape[0] - 10),
                                cv2.FONT_HERSHEY_SIMPLEX, 0.65, (255, 0, 0), 2)

                            i += 1
                            if i > 100:
                                s = True

                    else:
                        cv2.polylines(frame, np.int32([boxes[index]]), True,
                                      (0, 255, 0), 2)

                        if s == False:
                            cv2.putText(
                                frame,
                                timestamp.strftime(
                                    " Available: %d %m %Y %I:%M:%S"),
                                (10, frame.shape[0] - 10),
                                cv2.FONT_HERSHEY_SIMPLEX, 0.65, (0, 255, 0), 2)
                            i += 1
                            if i > 100:
                                s = True

                    msg = "Parking slots are available "
                    clr = 'green'
                    updateStatusWindow(msg, clr)

                    available_slots.append(slot_first_x_cord)

            if not available_slots:
                msg = "Parking slots are not available "
                clr = 'red'
                updateStatusWindow(msg, clr)

            cv2.imshow("frame", frame)

            key = cv2.waitKey(10) & 0xFF

            if key == ord("q"):
                break

            if key == ord('p'):
                hist = cv2.calcHist([a[1]], [0], None, [256], [0, 256])
                plt.plot(hist)
                plt.show()

            i += 1
    except KeyboardInterrupt:
        pass
Beispiel #5
0
    else:
        box1 = np.array([(130.14516129032256, 226.74999999999994),
                         (85.68951612903224, 223.12096774193543),
                         (121.97983870967742, 175.0362903225806),
                         (155.5483870967742, 179.57258064516125)])
        box2 = np.array([(137.4032258064516, 225.84274193548384),
                         (166.43548387096774, 173.22177419354836),
                         (210.89112903225805, 177.758064516129),
                         (196.375, 226.74999999999994)])

        boxes = [box1, box2]
    #print('afdasdf')
    #print(box1[0].shape)

    img_resize = image_utils.getRotateRect(gau, boxes)
    feature = image_utils().extract_features(img_resize)
    '''feature1 = feature.reshape(-1, 1)
    score0 = SVM().predict(feature1)
    score1 = SVM().predict(feature[1])

    print (score0, score1)'''
    timestamp = datetime.datetime.now()

    score = SVM().predict(feature)

    if score[0] == 0:
        cv2.polylines(frame, np.int32([box1]), True, (0, 0, 255), 2)
        saida = False
        i = 0

    else: