123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690 |
- <html>
- <head>
- <!--<meta http-equiv="Content-Type" content="text/html; charset=gb2312">-->
- <meta http-equiv="X-UA-Compatible" content="IE=10"/>
- <title>SDK demo</title>
- <script language="javascript" type="text/javascript">
- var CamID = -1;
- var ResolutionStr;
- var pCamWidth;
- var pCamHeight;
- var DeviceCount;
- var DeviceStatus = false;
- var isOpenCamera = false;
- var isAllSelect = 0;
- var RotateAngle = 0;
- var isCaptureIdCard = false;
- var IdCardCount = 0;
- var IdCardPath1;
- var IdCardPath2;
- //var t2 = window.setTimeout("show()", 3000);
- function ShowInfo(op) {
- var obj = document.getElementById("TextArea1");
- obj.value = obj.value + " \n" + op;
- }
- //时间格式化显示
- function formatDate(time) {
- var date = new Date(time);
- var year = date.getFullYear(),
- month = date.getMonth() + 1,
- day = date.getDate(),
- hour = date.getHours(),
- min = date.getMinutes(),
- sec = date.getSeconds();
- var newTime = year +
- (month < 10 ? '0' + month : month) +
- (day < 10 ? '0' + day : day) +
- (hour < 10 ? '0' + hour : hour) +
- (min < 10 ? '0' + min : min) +
- (sec < 10 ? '0' + sec : sec) ;
- return newTime;
- }
- function InitLoad() {
- //axOcx.SetCutType(1); //默认自动寻边
- DeviceCount = axOcx.GetDeviceCount(); //获取设备数目
- if (DeviceCount == 0)
- alert("未发现相关设备");
- if (DeviceCount > 0) {
- //枚举相关设备
- for (var i = 0; i < DeviceCount; i++) {
- var nameStr = axOcx.GetDeviceName(i);
- var objOption = document.createElement("option");
- objOption.text = nameStr;
- objOption.value = i;
- document.getElementById("Device").options.add(objOption);
- }
- document.getElementById("Device").selectedIndex = 0;
- CamID = 0;
- var resindex = 0;
- var cmpVal = 0;
- //主头
- if (CamID == 0) {
- var ResolutionCount = axOcx.GetStillResolutionCount(CamID); //获取分辨率数目
- if (ResolutionCount > 0) {
- var resObj = document.getElementById("Resolution");
- for (var i = 0; i < ResolutionCount; i++) {
- var resolutionStr = axOcx.GetStillResolution(i);
- var objOption = document.createElement("option");
- objOption.text = resolutionStr;
- objOption.value = i;
- resObj.options.add(objOption);
- //找出最大分辨率
- var pos = resolutionStr.lastIndexOf("*");
- var cmpWidth = parseInt(resolutionStr.substring(0, pos));
- if (cmpWidth > cmpVal) {
- resindex = i;
- }
- }
- resObj.selectedIndex = resindex;
- ResolutionStr = resObj.options[resObj.selectedIndex].text;
- var pos = ResolutionStr.lastIndexOf("*");
- pCamWidth = parseInt(ResolutionStr.substring(0, pos));
- pCamHeight = parseInt(ResolutionStr.substring(pos + 1, ResolutionStr.length));
- }
- }
- //副头
- if (CamID == 1) {
- var ResolutionCount = axOcx.GetResolutionCount(CamID); //获取分辨率数目
- if (ResolutionCount > 0) {
- var resObj = document.getElementById("Resolution");
- for (var i = 0; i < ResolutionCount; i++) {
- var resolutionStr = axOcx.GetResolution(i);
- var objOption = document.createElement("option");
- objOption.text = resolutionStr;
- objOption.value = i;
- resObj.options.add(objOption);
- }
- resObj.selectedIndex = 0;
- ResolutionStr = resObj.options[resObj.selectedIndex].text;
- var pos = ResolutionStr.lastIndexOf("*");
- pCamWidth = parseInt(ResolutionStr.substring(0, pos));
- pCamHeight = parseInt(ResolutionStr.substring(pos + 1, ResolutionStr.length));
- }
- }
-
- }
- }
- //开启摄像头
- function OpenDevice() {
- if (DeviceCount > 0) {
- var iRect;
- if (CamID == 0) //主头
- iRect = axOcx.OpenDeviceEx(pCamWidth, pCamHeight);
- if (CamID == 1) //副头
- iRect = axOcx.OpenDevice(CamID, pCamWidth, pCamHeight);
- if (iRect == 0) {
- isOpenCamera = true;
- }
- else {
- axOcx.CloseDevice();
- isOpenCamera = false;
- }
- }
- }
- //关闭摄像头
- function CloseDevice() {
- if (isOpenCamera)
- {
- axOcx.CloseDevice()
- isOpenCamera = false;
- }
- }
- //切换摄像头
- function SelectDevice() {
- var resindex = 0;
- var cmpVal = 0;
- CamID = document.getElementById("Device").selectedIndex;
- if (CamID == 0) {
- var ResolutionCount = axOcx.GetStillResolutionCount(CamID); //获取分辨率数目
- if (ResolutionCount > 0) {
- var resObj = document.getElementById("Resolution");
- for (var i = 0; i < ResolutionCount; i++) {
- var resolutionStr = axOcx.GetStillResolution(i);
- var objOption = document.createElement("option");
- objOption.text = resolutionStr;
- objOption.value = i;
- resObj.options.add(objOption);
- //找出最大分辨率
- var pos = resolutionStr.lastIndexOf("*");
- var cmpWidth = parseInt(resolutionStr.substring(0, pos));
- if (cmpWidth > cmpVal) {
- resindex = i;
- }
- }
- resObj.selectedIndex = resindex;
- ResolutionStr = resObj.options[resObj.selectedIndex].text;
- var pos = ResolutionStr.lastIndexOf("*");
- pCamWidth = parseInt(ResolutionStr.substring(0, pos));
- pCamHeight = parseInt(ResolutionStr.substring(pos + 1, ResolutionStr.length));
- }
- }
- //副头
- if (CamID == 1) {
- var ResolutionCount = axOcx.GetResolutionCount(CamID); //获取分辨率数目
- if (ResolutionCount > 0) {
- var resObj = document.getElementById("Resolution");
- for (var i = 0; i < ResolutionCount; i++) {
- var resolutionStr = axOcx.GetResolution(i);
- var objOption = document.createElement("option");
- objOption.text = resolutionStr;
- objOption.value = i;
- resObj.options.add(objOption);
- }
- resObj.selectedIndex = 0;
- ResolutionStr = resObj.options[resObj.selectedIndex].text;
- var pos = ResolutionStr.lastIndexOf("*");
- pCamWidth = parseInt(ResolutionStr.substring(0, pos));
- pCamHeight = parseInt(ResolutionStr.substring(pos + 1, ResolutionStr.length));
- }
- }
- CloseDevice();
- OpenDevice();
- }
- //切换分辨率
- function SelectResolution() {
- var resObj = document.getElementById("Resolution");
- ResolutionStr = resObj.options[resObj.selectedIndex].text;
- var pos = ResolutionStr.lastIndexOf("*");
- pCamWidth = parseInt(ResolutionStr.substring(0, pos));
- pCamHeight = parseInt(ResolutionStr.substring(pos + 1, ResolutionStr.length));
- CloseDevice();
- OpenDevice();
- }
- //抓图拍照
- var captureCount = 0;
- function Capture() {
- if (isOpenCamera == false)
- return;
- var formatIndex = document.getElementById("FileFormat").selectedIndex; //文件格式
- var formatTypeStr = ".jpg";
- if (formatIndex == 0) formatTypeStr = ".jpg";
- if (formatIndex == 1) formatTypeStr = ".bmp";
- if (formatIndex == 2) formatTypeStr = ".png";
- if (formatIndex == 3) formatTypeStr = ".tif";
- if (formatIndex == 4) formatTypeStr = ".gif";
- if (formatIndex == 5) formatTypeStr = ".pdf";
- var name = formatDate(new Date().getTime());
- var path = "D:\\" + name + formatTypeStr;
- var base64Str;
- if (CamID == 0)
- base64Str = axOcx.CaptureImage(path);
- if (CamID == 0)
- base64Str = axOcx.CaptureStillImage(path);
- //axOcx.GetQrBarCodeContent(1, path);
- if (base64Str != "fail") {
- var showImgCtl = document.getElementById("img1");
- showImgCtl.src = "data:;base64," + base64Str;
- ShowInfo("拍照完成,图片位置:" + path);
- }
- else
- ShowInfo("拍照失败!");
- }
- function GetQrBarCodeContent() {
- if (isOpenCamera == false)
- return;
- var iRest = axOcx.GetQrBarCodeContent(1, "");
- ShowInfo("二维码识别结果:" + iRest);
- }
- //添加图片到PDF
- function AddImageToPDF() {
- if (isOpenCamera == false)
- return;
- axOcx.SetImageFormat(0); //默认添加JPG格式图片
- var name = formatDate(new Date().getTime());
- var path = "D:\\" + name + ".jpg";
- var base64Str = axOcx.CaptureImage(path);
- axOcx.AddImageFileToPDF(path);
- var showImgCtl = document.getElementById("img1");
- showImgCtl.src = "data:;base64," + base64Str;
- ShowInfo("已添加要合并到PDF的图片,图片位置:" + path);
-
- var formatIndex = document.getElementById("FileFormat").selectedIndex;
- axOcx.SetImageFormat(formatIndex);
- }
- //合并PDF
- function CombineToPDF() {
- var name = formatDate(new Date().getTime());
- var path = "D:\\" + name + ".pdf";
- var iRest = axOcx.CombineToPDF(path, false);
- if (iRest == 0) {
- ShowInfo("PDF合并成功,文件位置:" + path);
- }
- else {
- ShowInfo("PDF合并失败!");
- }
- }
- //旋转
- function SetRoate(ag) {
- if (isOpenCamera == false)
- return;
- if (ag == 0) {
- RotateAngle -= 90;
- if (RotateAngle < 0)
- RotateAngle = 270;
- }
- else {
- RotateAngle += 90;
- if (RotateAngle > 270)
- RotateAngle = 0;
- }
- axOcx.SetRotate(RotateAngle);
- }
- //缩放
- function Zoom(val) {
- if (isOpenCamera == false)
- return;
- if (val == 0) {
- axOcx.ZoomIn();
- }
- else {
- axOcx.ZoomOut();
- }
- }
- //1:1
- function TrueSize() {
- if (isOpenCamera == false)
- return;
- axOcx.TrueSize();
- }
- //适合屏幕
- function BestSize() {
- if (isOpenCamera == false)
- return;
- axOcx.BestSize();
- }
- //对焦
- function ManualToFocus() {
- if (isOpenCamera == false) return;
- axOcx.ManualToFocus();
- }
- //设备属性
- function SetParams() {
- if (isOpenCamera == false) return;
- axOcx.ShowImageSettingWindow();
- }
- //设置拍摄模式
- function SetCaptrueMode() {
- if (document.getElementById("Radio1").checked) {
- axOcx.SetCutType(0);
- }
- if (document.getElementById("Radio2").checked) {
- axOcx.SetCutType(1);
- }
- if (document.getElementById("Radio3").checked) {
- axOcx.SetCutType(2);
- }
- }
- //设置文件格式
- function SetFileFormat() {
- var obj = document.getElementById("FileFormat");
- axOcx.SetImageFormat(obj.selectedIndex);
- }
- //去底色
- function SetDeleteBgColor() {
- var obj = document.getElementById("Checkbox1");
- if (obj.checked) {
- axOcx.SetDeleteBgColor(1);
- }
- else {
- axOcx.SetDeleteBgColor(0);
- }
- }
- //上传
- function HttpUploadFile() {
- var filePath = "C:\\test.jpg";
- //var url = "http://192.168.1.80/MyServletTest/upload";
- var url = "http://localhost:4523/UploadFile.ashx";
- var iRest = axOcx.UploadFile(url, filePath);
- if(iRest=="fail")
- ShowInfo("上传失败!");
- else
- ShowInfo("上传成功. 后台返回内容:" + iRest);
- }
-
- //*************读取身份证**************************
- function ReadIdCard() {
- var iRest = axOcx.readCard();
- if (iRest == 0) {
- document.getElementById("CardName").value = axOcx.GetCardInfo(0);
- document.getElementById("CardSex").value = axOcx.GetCardInfo(1);
- document.getElementById("CardNation").value = axOcx.GetCardInfo(2);
- document.getElementById("CardBorn").value = axOcx.GetCardInfo(3);
- document.getElementById("CardAddress").value = axOcx.GetCardInfo(4);
- document.getElementById("CardNum").value = axOcx.GetCardInfo(5);
- document.getElementById("CardIssuedAt").value = axOcx.GetCardInfo(6);
- document.getElementById("CardEffectDate").value = axOcx.GetCardInfo(7) + "-" + axOcx.GetCardInfo(8);
- var obj = document.getElementById("IdCardPhoto");
- obj.src = "data:;base64," + axOcx.GetCardInfo(10);
- ShowInfo("读卡成功");
- }
- else
- ShowInfo("读卡失败!");
-
- }
- //*************人脸识别部分**************************
- //打开单目摄像头
- function OpenSingleFaceDevice() {
- var iRest = axOcx.OpenSingleFaceDevice();
- if(iRest!=0)
- ShowInfo("开启单目人脸摄像头失败!");
- else
- ShowInfo("开启单目人脸摄像头成功");
- }
- //关闭单目摄像头
- function CloseSingleFaceDevice() {
- axOcx.CloseSingleFaceDevice();
- ShowInfo("关闭单目人脸摄像头");
- }
- //打开双目摄像头
- function OpenDualFaceDevice() {
- var iRest = axOcx.OpenDualFaceDevice();
- if (iRest != 0)
- ShowInfo("开启双目人脸摄像头失败!");
- else
- ShowInfo("开启双目人脸摄像头成功");
- }
- //关闭双目摄像头
- function CloseDualFaceDevice() {
- axOcx.CloseDualFaceDevice();
- ShowInfo("关闭双目人脸摄像头");
- }
- //两张图片比对
- function FaceImageCompare() {
- var imgpath1 = "D:\\face1.jpg";
- var imgpath2 = "D:\\face2.jpg";
- var iRest = axOcx.FaceImageCompare(imgpath1, imgpath2);
- if(iRest==0)
- ShowInfo("比对通过,验证为同一个人");
- else
- ShowInfo("比对失败! 验证不通过!");
- }
- //图片与人脸摄像头检测到的人脸图像比对
- function FaceFromCameraCompare() {
- var imgpath1 = "D:\\face1.jpg";
- var iRest = axOcx.FaceFromCameraCompare(imgpath1);
- if (iRest == 0)
- ShowInfo("比对通过,验证为同一个人");
- else
- ShowInfo("比对失败! 验证不通过!");
- }
- //获取检测到的人脸图像
- function GetFaceImageFromCam() {
- var path = "D:\\face1.jpg";
- var iRestStr = axOcx.GetFaceImageFromCam(path);
- if (iRestStr == "fail") {
- ShowInfo("获取检测到的人脸图像失败!");
- }
- else {
- var showImgCtl = document.getElementById("img1");
- showImgCtl.src = "data:;base64," + iRestStr;
- ShowInfo("获取检测到的人脸图像,图片位置:" + path);
- }
-
- }
- //人脸摄像头拍照
- function FaceCameraCapture() {
- var path = "D:\\face2.jpg";
- var iRestStr = axOcx.FaceCameraCapture(path);
- if (iRestStr == "fail") {
- ShowInfo("人脸摄像头拍照失败!");
- }
- else {
- var showImgCtl = document.getElementById("img1");
- showImgCtl.src = "data:;base64," + iRestStr;
- ShowInfo("人脸摄像头拍照完成,图片位置:" + path);
- }
-
- }
- //////////////////////////////////////////
- function StartRec() {
- var videoPath = "D:\\videotest.avi";
- var iRest = axOcx.Start_REC(videoPath, 8);
- if (iRest == 0)
- ShowInfo("开始录像");
- else
- ShowInfo("开始录像失败!");
- }
- function StopRec() {
- var iRest = axOcx.Stop_REC();
- ShowInfo("停止录像");
- }
- </script>
- <script language="javascript" for="axOcx" event="CheckLivingBody(flag)" type="text/javascript">
- alert("事件触发");
- </script>
- </head>
- <body onload="InitLoad();OpenDevice()" onunload="CloseDevice()">
-
- <div style="width:600px; height: 700px; border: 1px solid white; background:#C7EDCC; float:left">
- <!--[if IE]>
- <object classid="clsid:42BEFDDA-49E3-4851-9031-DC56ADA62756" id="axOcx" style=" width:100%; height:400px" ></object>
- <![endif]-->
- <!--[if !IE]> -->
- <object type="application/x-camera" clsid="{42BEFDDA-49E3-4851-9031-DC56ADA62756}" id="axOcx" style=" width:100%; height:400px" >
- </object>
- <!-- <![endif]-->
-
- <div align="left" style=" width:100%; height:32px">
- <input type = "button" value = "放大" onclick = "Zoom(0);" style="height: 30px" />
- <input type = "button" value = "缩小" onclick = "Zoom(1);" style="height: 30px" />
- <input type = "button" value = "左旋" onclick = "SetRoate(0);" style="height: 30px" />
- <input type = "button" value = "右旋" onclick = "SetRoate(1);" style="height: 30px" />
- <input type = "button" value = "1:1" onclick = "TrueSize();" style="height: 30px" />
- <input type = "button" value = "适屏" onclick = "BestSize();" style="height: 30px" />
- <input type = "button" value = "对焦" onclick = "ManualToFocus();" style="height: 30px" />
- <input type = "button" id="CaptureBt" value = " 拍照 " onclick = "Capture();" style="height: 30px" />
- <input type = "button" value = "读身份证" onclick = "ReadIdCard();" style="height: 30px" />
- </div>
- <div align="left" style=" width:100%; height:32px">
- <input type = "button" value = " 设置 " onclick = "SetParams();" style="height: 30px" />
- <input type = "button" value = " 上传 " onclick = "HttpUploadFile();" style="height: 30px" />
- <input type = "button" value = "二维码识别" onclick = "GetQrBarCodeContent();" style="height: 30px" />
- <input type = "button" value = "添加图片到PDF" onclick = "AddImageToPDF()" style="height: 30px"/>
- <input type = "button" value = "合并PDF" onclick = "CombineToPDF()" style="height: 30px"/>
- <input type = "button" value = "开始录像" onclick = "StartRec()" style="height: 30px"/>
- <input type = "button" value = "停止录像" onclick = "StopRec()" style="height: 30px"/>
- <input id="Checkbox1" type="checkbox" onclick = "SetDeleteBgColor()"/>去底色
- </div>
- <br />
- <div align="left" style=" width:100%; height:32px">
- <input type = "button" value = "开启单目人脸摄像头" onclick = "OpenSingleFaceDevice()" style="height: 30px"/>
- <input type = "button" value = "关闭单目人脸摄像头" onclick = "CloseSingleFaceDevice()" style="height: 30px"/>
- <input type = "button" value = "开启双目人脸摄像头" onclick = "OpenDualFaceDevice()" style="height: 30px"/>
- <input type = "button" value = "关闭双目人脸摄像头" onclick = "CloseDualFaceDevice()" style="height: 30px"/>
- </div>
- <div align="left" style=" width:100%; height:32px">
- <input type = "button" value = "获取检测的人脸图片" onclick = "GetFaceImageFromCam()" style="height: 30px"/>
- <input type = "button" value = "人脸摄像头拍照" onclick = "FaceCameraCapture()" style="height: 30px"/>
- <input type = "button" value = "人脸图片比对" onclick = "FaceImageCompare()" style="height: 30px"/>
- <input type = "button" value = "人脸图片与摄像头人脸比对" onclick = "FaceFromCameraCompare()" style="height: 30px"/>
- </div>
- <div style="width:100%; height: 120px" align="left" >
- <textarea id="TextArea1" style=" width:596px; height:120px" cols="20" rows="5"></textarea>
-
- </div>
-
- </div>
- <div style="width:210px; height: 700px; border: 1px solid white; background:#C7EDCC; float:left">
- <div style="width:100%; height: 32px" align="left" >
- <img id="img1" src="" style="width: 160px;height: 160px" /> <br /> <br />
- 设 备:
- <select id="Device" name="D1" onchange = "SelectDevice()" style="width:145px"> </select> <br />
- 分辨率:
- <select id="Resolution" name="D2" onchange = "SelectResolution()" style="width:138px" > </select> <br />
-
- 文件格式:
- <select id="FileFormat" onchange = "SetFileFormat()">
- <option value="0">jpg</option>
- <option value="1">bmp</option>
- <option value="2">png</option>
- <option value="3">tif</option>
- <option value="4">gif</option>
- <option value="5">pdf</option>
- </select>
- <br />
- <br /> 拍摄模式: <br />
- <input id="Radio1" name="R1" type="radio" value="V1" onclick="SetCaptrueMode()" checked="checked"/>不裁切
- <input id="Radio2" name="R1" type="radio" value="V2" onclick="SetCaptrueMode()"/>自动裁切<br />
- <input id="Radio3" name="R1" type="radio" value="V3" onclick="SetCaptrueMode()"/>手动裁切<br />
- <br />身份证信息 <br />
- <img id="IdCardPhoto" src="" style="width: 80px;height: 100px;" />
- <br />
- 姓名
- <input id="CardName" type="text" style="width: 100px"/> <br />
- 性别
- <input id="CardSex" type="text" style="width: 50px"/>
- 民族
- <input id="CardNation" type="text" style="width: 55px"/> <br />
- 出生
- <input id="CardBorn" type="text" style="width: 100px"/> <br />
- 住址
- <br />
- <textarea id="CardAddress" cols="20" rows="3" style="width:200px"></textarea>
- 身份证号码
- <br />
- <input id="CardNum" type="text" style="width: 200px"/> <br />
- 签发机关
- <input id="CardIssuedAt" type="text" style="width: 128px"/> <br />
- 有效期限
- <input id="CardEffectDate" type="text" style="width: 128px"/> <br />
- </div>
- </div>
- </body>
- </html>
|