Created
May 8, 2023 06:21
-
-
Save iranjith4/de4fafe299e0b1b520a707473b8c5b5d to your computer and use it in GitHub Desktop.
Loading a CSV file and reading lines
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private func loadPoseSamples() { | |
var poseSamples: [PoseSample] = [] | |
var text: String | |
do { | |
if let path = Bundle.main.path(forResource: Self.POSE_SAMPLES_FILE, ofType: Self.POSE_SAMPLES_FILE_EXT) { | |
text = try String(contentsOfFile: path, encoding: String.Encoding.utf8) | |
} else { | |
print(TAG, "Could not find file.") | |
return | |
} | |
} catch { | |
print(TAG, "Error when loading pose samples.") | |
return | |
} | |
let lines: [String] = text | |
.split(separator: "\r\n", omittingEmptySubsequences: true) | |
.map(String.init) | |
for csvLine in lines { | |
// If line is not a valid {@link PoseSample}, we'll get null and skip adding to the list. | |
let poseSample: PoseSample? = PoseSample.getPoseSample(csvLine, seperator: ",") | |
if let poseSample = poseSample { | |
poseSamples.append(poseSample) | |
} | |
} | |
poseClassifier = PoseClassifier(poseSamples) | |
if isStreamMode { | |
for className in Self.POSE_CLASSES { | |
repCounters.append(RepetitionCounter(className: className)) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment