java 图像采集_JAVA B/S通过摄像头采集图片信息解决方案。

var pos = 0, ctx = null, saveCB, image =[];var w=320;var h=240;var canvas = document.createElement("canvas");

canvas.setAttribute('width', w);

canvas.setAttribute('height', h);if (1==0&&canvas.toDataURL) {//支持HTML5时候用

debugger;

ctx= canvas.getContext("2d");

image= ctx.getImageData(0, 0, w, h);

saveCB= function(data) {//会循环调用该方法直到读完每行,data是一行的坐标。var col = data.split(";");var img =image;for(var i = 0; i < 320; i++) { var tmp =parseInt(col[i]);

img.data[pos+ 0] = (tmp >> 16) & 0xff;

img.data[pos+ 1] = (tmp >> 8) & 0xff;

img.data[pos+ 2] = tmp & 0xff;

img.data[pos+ 3] = 0xff;

pos+= 4;

}if (pos >= 4 * w *h) {

ctx.putImageData(img,0, 0);

$.ajax({

url :"../test2/video",

dataType :"json",

type :'post',

data:{

type:"data",

image: canvas.toDataURL("image/png")

},

error:function(e)

{

},

beforeSend:function(){

layer.load();

},

complete:function(){

layer.closeAll('loading');

},

success :function(url) {

$('#myImg').attr('src',url);

}

})//$.post("../test2/video?tmp=" + Math.random(), {type: "data", image: canvas.toDataURL("image/png")},function(url)

//{

//$('#myImg').attr('src',url);

//},"json");

pos = 0;

}

};

}else{

saveCB= function(data) {//循环调用该方法

image.push(data);

pos+= 4 *w;if (pos >= 4 * w *h) {

$.ajax({

url :"../test2/video",

dataType :"json",

type :'post',

data:{

type:"pixel",

image: image.join('|'),

w:w,

h:h

},

error:function(c)

{

},

beforeSend:function(){

layer.load();

},

complete:function(){

layer.closeAll('loading');

},

success :function(url) {

$('#myImg').attr('src',url);

}

})//$.post("../test2/video", {type: "pixel", image: image.join('|'),w:w,h:h},function(url)

//{

//alert(url);

//$('#myImg').attr('src',url);

//},"json");

pos = 0;

}

};

}

$("#webcam").webcam({

width: w,

height: h,

mode:"callback",

swffile: swfpah,

onSave: saveCB,

onCapture:function() {

webcam.save();

},

debug:function(type, string) {

console.log(type+ ": " +string);

},

onLoad:function() {

$('#test').bind('click',function(){

webcam.capture();

});

}

});

});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值