c#练习——读取路径内容放入队列

该博客介绍如何使用C#读取类似train.txt的文件内容,将数据转化为Sample对象集合。内容包括解析文件中的图片路径、坐标和类别,创建Sample类和box类实例,并利用队列存储坐标数据。
摘要由CSDN通过智能技术生成
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 (Mat
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值