自动保存PubFig 数据库


PubFig face database 链接(http://www.cs.columbia.edu/CAVE/databases/pubfig/)

是一个之前一直想下载的人脸数据库,数据库里面的人脸只提供url并没提供可以下载的是图片,之前因为想要一张一张的自己下非常的累人所以就没有下载过。


之前在博客里面分享了一个利用网络url直接保存文件的博客,利用里面的方法我也写了一个自动保存PubFig的程序,话不多说,直接上代码。


using System.Net; // for WebClient
using System.IO; // for MemoryStream
using System.Text;// for Encoding
using System.Drawing;// for image

     private void button1_Click(object sender, EventArgs e)
        {

            //downloading image from urls

            WebClient wc = new WebClient();// key member of downloading
     //       wc.
            MemoryStream ms;
            StreamReader m_StreamReader = new StreamReader("..\\..\\eval_urls.txt");// open the txt file with C# form
                                                                                    // 没有用之前的fopen了

             while(true)
            {
                String temp_line = m_StreamReader.ReadLine();// read one line of txt file 用的挺爽
                if (temp_line == null)
                 {
                     break;// break when reach the end of file;
                 }
                 String []parts = temp_line.Split('\t');// split the readed line by '\t'
                 if ((parts[0].IndexOf('#'))!=-1)
                 {
                     continue;// the first and second  row of image is useless so discard them

                 }

                 String ImgSavePath = ".\\"+parts[0] + "\\";
                 if (!Directory.Exists(ImgSavePath))
                 {
                     Directory.CreateDirectory(ImgSavePath);// create the Directiory when necessary 
                 }
                 ImgSavePath += parts[0] + "_" + parts[1] + ".jpg";// path of saving image
                
                 try
                 {
                     wc.DownloadFile(parts[2], ImgSavePath); // using the DownloadFile function instead of DownloadData
               //      ms = new MemoryStream(wc.DownloadData(parts[2]));
               //      Image img = Image.FromStream(ms);
               //      img.Save(ImgSavePath); 
                 }
                 catch (System.Exception ex)
                 {
                <span style="white-space:pre">	</span>// catch the exception when the image is invalid
                 }


           
            }
}



总结一下哈

1 c#还是很好用的,很多内存管理的事情都可以不用考虑了,这对于我这种常年写c的人来说真是福音啊

2 DownloadFile 这个函数貌似比共享的博客里面的DownloadData 这个函数要好用一些,直接输入url 和保存的文件名就可以直接下载了

3 好多国外的网站的图片都找不到了,吐槽一下这个库,估计是下不全。


骚年们,有了库就可以干活了,赶紧去干活吧。




  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 11
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值