基本信息
源码名称:USB摄像头人脸图像抓拍采集程序
源码大小:2.72M
文件格式:.zip
开发语言:C#
更新时间:2025-03-02
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 5 元 
   源码介绍

公司做人脸识别产品经常要用到USB摄像头采集人员人脸照片,没有方便的采集程序,我就做了一个方便项目上使用,通过电脑USB摄像头抓拍照片,自动以unix时间命名保存照片文件,可以选择摄像头,选择分辨率,选择照片保存位置,可设置保存的JPG图像文件压缩质量,里面也放了可保存为PNG格式的代码,使用空格键快速拍照,用在几个项目上还是比较好用的。

    private void btnShoot_Click(object sender, EventArgs e)
    {
        Bitmap img = vispShoot.GetCurrentVideoFrame();
        picbPreview.Image = img;
        TimeSpan now = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0,0 ); 
        long t = Convert.ToInt64(now.TotalMilliseconds) / 1000;
        SaveImageWithQuality(img, string.Format(txt_ImageAddress.Text   @"\{0}.jpg", t.ToString()), long.Parse(sizetextBox1.Text.ToString()));
        MessageBox.Show("照片保存成功");
         //img.Save(string.Format(txt_ImageAddress.Text @"\{0}.jpg", t.ToString()), System.Drawing.Imaging.ImageFormat.Jpeg); MessageBox.Show("保存成功");
        //如果不指定文件名,则默认以当前时间戳命名,微软的Image.Save方法保存到图片压缩质量为75,不加jpeg后缀名则以PNG格式保存,或者Savepath,System.Drawing.Imaging.ImageFormat.Png
    
    }
    protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
    {
        if (keyData == (Keys.Space))
        {
            btnShoot.PerformClick();
        }
        return base.ProcessCmdKey(ref msg, keyData);
    }
    /// <summary>
    /// 窗体关闭
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
        DisConnect();
    }

    private void btn_brewse_Click(object sender, EventArgs e)
    {
        OpenFileDialog op = new OpenFileDialog();
        // op.Title = "浏览图像文件"; op.Filter = "图像文件(*.jpg)|*.jpg"; op.ShowDialog(); txt_ImageAddress.Text = op.FileName;
        op.Title = "选择保存位置";
        op.Filter = "文件夹|*.jpg|所有文件|*.*";
        op.FileName = "选择文件夹";
        op.CheckFileExists = false;
        op.CheckPathExists = true;
        op.ValidateNames = false;
        if (op.ShowDialog() == DialogResult.OK)
        {
            string selectedFolderPath = Path.GetDirectoryName(op.FileName);
            txt_ImageAddress.Text = selectedFolderPath;
            // 使用选中的文件夹路径进行后续操作
        }
    }

    private void txt_ImageAddress_TextChanged(object sender, EventArgs e)
    {

    }

    private void sizebutton1_Click(object sender, EventArgs e)
    {
        long anotherNumber;
        bool success = long.TryParse(sizetextBox1.Text.ToString(), out anotherNumber);
        if (success)
        {
            MessageBox.Show("设置成功"); ;  
        }
        else
        {
            MessageBox.Show("设置失败");
        }
    }
}