예제 #1
0
        if resize:
            frame = cv2.resize(frame, (width, height))
        imgDisplay = frame.copy()

        tracker.deleteTrack(frame.copy())

        if (frame_count % frame_interval) == 0:

            output_rgb = cv2.cvtColor(imgDisplay, cv2.COLOR_BGR2RGB)
            (boxes, scores, classes) = detector.detectObject(output_rgb)

            for i in range(boxes.shape[0]):
                # filter out the object that cannot fulfill all requirement
                # (low confidence score,object is not vehicle type, etc.)
                rect = getRectangle(boxes[i],width,height)
                result = label.getLabel(classes[i])
                check = validBoundingBox(rect,scores[i],result,vehicleClass)

                if check is False:
                    continue

                matchedID = tracker.getMatchId(frame,rect)
                # if current detected object already have tracker, do nothing
                if matchedID is not None:
                    continue
                
                # else create new tracker for the object
                (xmin,ymin,xmax,ymax) = rect

                vehicle = Vehicle()
                currentTrackID += 1
예제 #2
0
def featureExtract(subjectDirs, windowSize, windowShift, me):
    currentSubject = 1

    # Initialize a numpy array of overall feature matrix size
    # TODO: Change dimensionality of np.zeros to accomodate FD features
    featureMatrix = np.zeros((
        0,
        22))  # Depth = n, width = num features + 1 for label + 1 for subjectID

    # For each subject
    for folder in subjectDirs:
        print("Processing folder: ", folder)

        # I manually marked all the folders in my dataset that did not have a label.txt or had some other disparity with a '-nl' suffix. This can easily be done with code, but there are few enough folders that this was easier. 'oldData' contains data from previous class iterations that I chose not to include for now.
        if folder[-3:] == '-nl' or folder == "oldData":
            continue  # Ignore

        # Create label object
        labs = Label('allData\\' + folder + "\\labels.txt")
        # List of items in subject directory
        folderItems = os.listdir('allData\\' + folder)

        if folder == me:
            subjectID = 0
        else:
            subjectID = currentSubject
            currentSubject += 1

        # Initialize a numpy array for feature matrix for the single subject
        # TODO: Change dimensionality of np.zeros to accomodate FD features
        subjectFeatureMatrix = np.zeros((0, 21))  # (n, features + 1 for label)

        # For each file inside the folder
        for item in folderItems:
            # NOTE: The structure we want is |accelTD|baromTD|accelFD|baromFD|

            # Since the structure of the matrix we want to generate necessitates that we have both the accel and barom data side by side, we must process them together.
            # Here, the code ignores everything that is not accel data. When it finds accel data, it also processes the corresponding barom data by removing the last nine characters from the filename ('accel.txt') and appending 'pressure.txt' to get the barom data for the same time.

            # Ignore labels, pressure, and gyro
            if item == 'labels.txt':
                continue  # Ignore, we already have what we need
            # elif item[-9:] == 'accel.txt': # No need to check if it's accel if that's the default
            #     dataType = 'accel'
            elif item[-12:] == 'pressure.txt':
                #dataType = 'barom'
                continue
            elif item[-8:] == 'gyro.txt':
                #dataType = 'gyro'
                continue

            # Get arrays from filenames
            dataAccel = readFile('allData\\' + folder + '\\' + item)
            dataBarom = readFile('allData\\' + folder + '\\' + item[:-9] +
                                 'pressure.txt')
            dataLabel = labs.getLabel(int(
                dataAccel[0, 0]))  # Timestamp of first entry
            dataAccel, dataBarom = interp(
                dataAccel, dataBarom)  # Reassign arrs to be interpolated
            featuresInFile = [
            ]  # (n, 2TDf + 2FDf) -- len, 2*number of time domain features + 2*number of frequency domain features

            # Start the windowing
            for index in range(0, len(dataAccel), windowShift):
                # Assuming sample rate is 32Hz (idk how accurate that is)

                # Set the end point to where we are plus the windowSize, or to the end of the arr if that would exceed limits
                end = index + windowSize + 1
                if index + windowSize + 1 > len(dataAccel):
                    end = len(dataAccel)

                workingDataAccel = dataAccel[index:end]  # (window, 3)
                workingDataBarom = dataBarom[index:end]  # (window, 1)
                windowFeatures = getFeatures(
                    workingDataAccel,
                    workingDataBarom)  # (1,features) actually (f,)
                featuresInFile.append(windowFeatures)

            # print("Inner loop - featuresInFile after windowing: ", np.array(featuresInFile).shape)
            print("Processed item: ", item,
                  np.array(featuresInFile).shape, "label: ", dataLabel)

            ## ATTACH LABELS HERE
            labelsVector = np.full((len(featuresInFile), 1),
                                   dataLabel)  # (n,1)
            featuresInFile = np.concatenate((featuresInFile, labelsVector),
                                            axis=1)  # (n,features+1)
            subjectFeatureMatrix = np.concatenate(
                (subjectFeatureMatrix, featuresInFile), axis=0)
            #print("inner loop -- subjectFeatureMatrix: ", np.array(subjectFeatureMatrix).shape)

        ## ATTACH SUBJECTID HERE
        subjectIDMatrix = np.full((len(subjectFeatureMatrix), 1),
                                  subjectID)  # (N, 1)
        subjectFeatureMatrix = np.concatenate(
            (subjectFeatureMatrix, subjectIDMatrix),
            axis=1)  # (N, features + 1)
        featureMatrix = np.concatenate((featureMatrix, subjectFeatureMatrix),
                                       axis=0)
        print("Added subject %d, featureMatrix shape is now:" % (subjectID),
              featureMatrix.shape)

    #print("featureMatrix contains NaN?", (True in np.isnan(featureMatrix)))
    return featureMatrix