从网络摄像头和商店捕获图像

时间:2017-04-05 08:35:40

标签: codeigniter

我想从网络摄像头捕获图像并将其存储到数据库和文件路径中。但它也不会存储在数据库中的文件路径中。

我的观点:

<script type="text/javascript" src="<?php echo base_url() ?>assets/dist/js/webcam.min.js"></script>


<div class="form-group">
                                        <div class="col-sm-3  col-md-offset-3 no-print">
                                            <!--<img src="<?php echo base_url(); ?>assets/images/blank.png" >-->
                                            <div class="clearfix" id="my_camera"></div><br>
                                            <button type="button" class="btn btn-info" onClick="take_snapshot()"><i class="fa fa-camera fa-fw"></i>Capture</button>
                                        </div>
                                        <div class="col-md-3 col-md-offset-1 imager" id="results">
                                            <!--<img src="<?php echo base_url(); ?>assets/images/user.png" class="thumbnail" >-->
                                            <h3>Visitors Photo</h3>
                                        </div>
                                    </div>
<script language="JavaScript">
        function take_snapshot() {                
            Webcam.snap(function (data_uri) {                    
                document.getElementById('results').innerHTML =
                        '<h2>Here is your image:</h2>' +
                        '<img src="' + data_uri + '"/>';
            });
        }
    </script>
<script language="JavaScript">
        Webcam.set({
            width: 320,
            height: 240,
            image_format: 'jpeg',
            jpeg_quality: 90
        });
        Webcam.attach('#my_camera');
    </script>

1 个答案:

答案 0 :(得分:0)

如果你使用https://github.com/jhuckaby/webcamjs/blob/master/DOCS.md,你可以

 Webcam.snap(function (data_uri) {                    
                document.getElementById('results').innerHTML =
                        '<h2>Here is your image:</h2>' +
                        '<img src="' + data_uri + '"/>';
            });

必须像

Webcam.snap(function (data_uri) {                    
                    document.getElementById('results').innerHTML =
                            '<h2>Here is your image:</h2>' +
                            '<img src="' + data_uri + '"/>';
                    Webcam.upload( data_uri, '<?php echo site_url('controlerfunctiontoupload'); ?>', function(code, text) {
            if (code == '200') {
              alert ('ok');
            } else {
              alert('error');
            }
        } );
                });

参见文档

upload_name     "webcam"

在controler / function中上传

$filename='test.jpg';
$filepath=FCPATH.'folderWithRights0777/'.$filename;
    $result=move_uploaded_file($_FILES['webcam']['tmp_name'], $filepath));

也适用于数据库中的插入

$this->db->from('files');
$this->db->set('image', $filename);
$this->db->insert();