如何使用网络摄像头拍照,并有图片上传直接或自动进入我的php形式



我一直在尝试构建一个数据捕获和生物识别(指纹)表单,其中网络摄像头连接到PC上,当您点击添加/上传图像按钮时,系统将自动启动网络摄像头,当您使用网络摄像头拍摄时,图像将自动上传到表单。

一个简单的例子是申请新的驾驶执照的过程。工作人员会要求你填写一张表格,表格数据会被传输到软件中,然后你会被要求站在相机前拍照。在某些情况下,申请人的指纹也会被采集并上传到系统。 我正在使用Dreamweaver, PHP和MySQL开发web应用程序。现在我只熟悉PHP。没有Java编程知识

欢迎你的建议,提前感谢你

迈克

请尝试以下代码从TheOnlyTutorials.com上的agurchand获取图像:

index . html

<!DOCTYPE html>
<html>
<head>
    <title>WebCam jQuery and PHP script</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
 
    <style>
        #camera_wrapper, #show_saved_img{float:left; width: 650px;}
    </style>
 
    <script type="text/javascript" src="scripts/webcam.js"></script>
    <script>
        $(function(){
            //give the php file path
            webcam.set_api_url( 'saveimage.php' );
            webcam.set_swf_url( 'scripts/webcam.swf' );
            webcam.set_quality( 100 ); // Image quality (1 - 100)
            webcam.set_shutter_sound( true ); // play shutter click sound
 
            var camera = $('#camera');
            camera.html(webcam.get_html(600, 460));
 
            $('#capture_btn').click(function(){
                //take snap
                webcam.snap();
            });
 
            //after taking snap call show image
            webcam.set_hook( 'onComplete', function(img){
                $('#show_saved_img').html('<img src="' + img + '">');
                //reset camera for next shot
                webcam.reset();
            });
 
        });
    </script>
</head>
<body>
    <h1>Capture photo with Web Camera - PHP Script</h1>
 
    <!-- camera screen -->
    <div id="camera_wrapper">
    <div id="camera"></div>
    <br />
    <button id="capture_btn">Capture</button>
    </div>
    <!-- show captured image -->
    <div id="show_saved_img" ></div>
</body>
</html>

Saveimage.php
<?php
 
//set random name for the image, used time() for uniqueness
 
$filename =  time() . '.jpg';
$filepath = 'saved_images/';
 
//read the raw POST data and save the file with file_put_contents()
$result = file_put_contents( $filepath.$filename, file_get_contents('php://input') );
if (!$result) {
    print "ERROR: Failed to write data to $filename, check permissionsn";
    exit();
}
 

echo $filepath.$filename;
?>

PHP部分见源代码

也可以从https://code.google.com/p/jpegcam/下载webcam.js库

最新更新