using System;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.IO;
class Read
{
public static void Main(string[] args)
{
string pattern1 = @"\d(\s|$)"; //标签
string pattern2 = @"[0-9]\d{5}.jpg"; //路径
string pattern3 = @"\d+\,\d+\,\d+\,\d+"; //坐标
string pattern4 = @"\d+"; //坐标提取
List<int> labels = new List<int> { };
List<string> path1 = new List<string> { };
int[] box1 = new int[4];
int[] label1 = { };
List<box> boxes = new List<box> { };
List<Sample> samples = new List<Sample> { };
string path = @"C:\Users\Administrator\Desktop\1.txt"; //小样本试验
string[] contents = File.ReadAllLines(path);
foreach (string str in contents)
{
Sample sample = new Sample();
foreach (Match match1 in Regex.Matches(str, pattern1))
{
//Console.Write(Convert.ToInt32(match1.Value) + " ");
labels.Add(Convert.ToInt32(match1.Value));
//labels.Add(Convert.ToInt32(match1.Value));
}
sample.getLabels(labels);
foreach (Match match2 in Regex.Matches(str, pattern2))
{
c#练习——读取路径内容放入队列
最新推荐文章于 2024-06-12 17:04:58 发布
该博客介绍如何使用C#读取类似train.txt的文件内容,将数据转化为Sample对象集合。内容包括解析文件中的图片路径、坐标和类别,创建Sample类和box类实例,并利用队列存储坐标数据。

最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



