当前位置: 首页 > news >正文

企业网站建设基本流程中国大数据平台官网

企业网站建设基本流程,中国大数据平台官网,市住房和城乡建设委员会网站房产栏目,安居客做网站0.什么是WebSocket,由于普通的请求是间断式发送的,如果要同一时间发生大量的请求,必然导致响应速度慢(因为根据tcp协议要经过三层握手,如果不持续发送,就会导致n多次握手,关闭连接,打开连接) 1.业务需求: 由于我需要使用java来处理视频的问题,视频其实就是图片,相当于每张图片…

0.什么是WebSocket,由于普通的请求是间断式发送的,如果要同一时间发生大量的请求,必然导致响应速度慢(因为根据tcp协议要经过三层握手,如果不持续发送,就会导致n多次握手,关闭连接,打开连接)

1.业务需求: 由于我需要使用java来处理视频的问题,视频其实就是图片,相当于每张图片就是帧,不停发送帧去实现人脸失败,然后返回处理结果,(支付宝刷脸支付也是同样的道理)

2.前端建立WebSocket()对象,onMessage函数监听返回的结果

<!DOCTYPE html>
<html>
<head><title>视频帧捕获</title>
</head>
<body><video id="videoElement" autoplay></video><canvas id="canvasElement" style="display: none;"></canvas><script>//如果是https协议的话,就需要改为 wssvar socket = new WebSocket("ws://localhost:8080/facedetect");const video = document.getElementById('videoElement');const canvas = document.getElementById('canvasElement');const context = canvas.getContext('2d');socket.onopen = function() {console.log("xxxx");// 每1秒发送一次视频帧数据,必须要在这里写定时器,因为打开连接后才能发送请求,不然每次都会报Websocket close的错误setInterval(captureFrame,10000)};socket.onmessage = function(event) {var result = event.data;// 处理服务器返回的结果console.log(result);//打印出结果};socket.onclose = function(event) {console.log("WebSocket已关闭");};socket.onerror = function(event) {console.error('WebSocket错误:', event);};navigator.mediaDevices.getUserMedia({ video: true }).then(stream => {video.srcObject = stream;}).catch(error => {console.error('无法访问摄像头:', error);});function captureFrame() {context.drawImage(video, 0, 0, canvas.width, canvas.height);const imageDataUrl = canvas.toDataURL('image/jpeg', 0.5);console.log(imageDataUrl) socket.send(imageDataUrl);// 将数据URL发送到WebSocket服务器}// 每隔一段时间捕获一帧并发送到Servlet</script>
</body>
</html>

3.后端写配置类,配置websocket的路径

@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {@Overridepublic void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {//录入人脸数据页面registry.addHandler(myHandler(),  "/face").setAllowedOrigins("*");//人脸识别页面registry.addHandler(myHandler1(), "/facedetect").setAllowedOrigins("*");}@Beanpublic WebSocketHandler myHandler() {return new FaceController();}@Beanpublic WebSocketHandler myHandler1() {return new FaceController1();}
}

4.写controller

//人脸录入的controller
@Controller
@RequestMapping("/face")
@CrossOrigin
public class FaceController extends TextWebSocketHandler {private WebSocketSession session;// 处理WebSocket连接请求@Overridepublic void afterConnectionEstablished(WebSocketSession session) throws Exception {System.out.println("WebSocket连接已建立");// 保存WebSocket会话this.session = session;}// 处理WebSocket文本消息@Overrideprotected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {String text = message.getPayload();System.out.println(text);text = text.replaceFirst("^data:image/[^;]+;base64,?\\s*", "");text = text.replaceAll("[^A-Za-z0-9+/=]", "");System.out.println(text);byte[] imageBytes = Base64.getDecoder().decode(text);if (imageBytes != null) {try {// 读取字节数组并返回BufferedImage对象ByteArrayInputStream bis = new ByteArrayInputStream(imageBytes);BufferedImage bufferedImage = ImageIO.read(bis);if (bufferedImage != null) {// 示例:显示图像宽度和高度int width = bufferedImage.getWidth();int height = bufferedImage.getHeight();System.out.println("图像宽度:" + width);System.out.println("图像高度:" + height);//录入人脸Employee e1 = HRService.addEmp(UUID.randomUUID().toString().substring(0,10), bufferedImage);ImageService.saveFaceImage(bufferedImage, e1.getCode());// 保存员工照片文件System.out.println(e1.getCode());// 在这里可以对BufferedImage对象进行其他操作} else {System.out.println("无法读取图像");}} catch (Exception e) {e.printStackTrace();}} else {System.out.println("无效的base64数据");}}// 根据接收到的文本消息进行相应的处理}
//人脸检测的控制器
@Controller
@RequestMapping("/facedetect")
@CrossOrigin
public class FaceController1 extends TextWebSocketHandler {
private WebSocketSession session;// 处理WebSocket连接请求@Overridepublic void afterConnectionEstablished(WebSocketSession session) throws Exception {System.out.println("WebSocket连接已建立");// 保存WebSocket会话this.session = session;}// 处理WebSocket文本消息@Overrideprotected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {System.out.println("detect");String text = message.getPayload();System.out.println(text);text = text.replaceFirst("^data:image/[^;]+;base64,?\\s*", "");text = text.replaceAll("[^A-Za-z0-9+/=]", "");System.out.println(text);byte[] imageBytes = Base64.getDecoder().decode(text);if (imageBytes != null) {try {// 读取字节数组并返回BufferedImage对象ByteArrayInputStream bis = new ByteArrayInputStream(imageBytes);BufferedImage bufferedImage = ImageIO.read(bis);if (bufferedImage != null) {FaceEngineService.loadAllFaceFeature();FaceFeature faceFeature = FaceEngineService.getFaceFeature(bufferedImage);// 获取当前帧中出现的人脸对应的特征码String code = FaceEngineService.detectFace(faceFeature);System.out.println(code);if (code != null) {// 如果特征码不为null,表明画面中存在某员工的人脸Employee e = HRService.getEmp(code);// 根据特征码获取员工对象HRService.addClockInRecord(e);// 为此员工添加打卡记录// 文本域添加提示信息session.sendMessage(new TextMessage("打卡成功"));}// 在这里可以对BufferedImage对象进行其他操作} else {session.sendMessage(new TextMessage("打卡成功"));}} catch (Exception e) {e.printStackTrace();}} else {System.out.println("无效的base64数据");}}// 根据接收到的文本消息进行相应的处理}

文章转载自:
http://moderate.bbtn.cn
http://gradgrind.bbtn.cn
http://desmotropism.bbtn.cn
http://summons.bbtn.cn
http://photophosphorylation.bbtn.cn
http://confidence.bbtn.cn
http://divvy.bbtn.cn
http://archanthropine.bbtn.cn
http://half.bbtn.cn
http://brockage.bbtn.cn
http://phreak.bbtn.cn
http://strass.bbtn.cn
http://protuberance.bbtn.cn
http://tijuana.bbtn.cn
http://sark.bbtn.cn
http://mediagenic.bbtn.cn
http://individualise.bbtn.cn
http://berline.bbtn.cn
http://ringbone.bbtn.cn
http://ripe.bbtn.cn
http://celibacy.bbtn.cn
http://teacherless.bbtn.cn
http://leukopoietic.bbtn.cn
http://telaesthesia.bbtn.cn
http://homospory.bbtn.cn
http://undyed.bbtn.cn
http://ventromedial.bbtn.cn
http://gopak.bbtn.cn
http://laic.bbtn.cn
http://vorticose.bbtn.cn
http://talmudist.bbtn.cn
http://small.bbtn.cn
http://radiophare.bbtn.cn
http://renogram.bbtn.cn
http://osrd.bbtn.cn
http://fraternity.bbtn.cn
http://hebdomad.bbtn.cn
http://squiggly.bbtn.cn
http://bivallate.bbtn.cn
http://bookish.bbtn.cn
http://weighable.bbtn.cn
http://featherhead.bbtn.cn
http://teleset.bbtn.cn
http://retrogression.bbtn.cn
http://undoing.bbtn.cn
http://inodorous.bbtn.cn
http://switchboard.bbtn.cn
http://chastisable.bbtn.cn
http://anticrop.bbtn.cn
http://vita.bbtn.cn
http://solarise.bbtn.cn
http://retour.bbtn.cn
http://bandwidth.bbtn.cn
http://entomolite.bbtn.cn
http://rephrase.bbtn.cn
http://kts.bbtn.cn
http://peritrichate.bbtn.cn
http://heterocharge.bbtn.cn
http://shirty.bbtn.cn
http://vpd.bbtn.cn
http://rascally.bbtn.cn
http://aerofoil.bbtn.cn
http://pentaploid.bbtn.cn
http://postirradiation.bbtn.cn
http://unreachable.bbtn.cn
http://rot.bbtn.cn
http://cornopean.bbtn.cn
http://familiarize.bbtn.cn
http://sandwich.bbtn.cn
http://effrontery.bbtn.cn
http://moldau.bbtn.cn
http://butte.bbtn.cn
http://acpi.bbtn.cn
http://forbade.bbtn.cn
http://warhead.bbtn.cn
http://cytology.bbtn.cn
http://asphyxia.bbtn.cn
http://exfacto.bbtn.cn
http://trondheim.bbtn.cn
http://peruvian.bbtn.cn
http://prejudgement.bbtn.cn
http://ugliness.bbtn.cn
http://sienna.bbtn.cn
http://census.bbtn.cn
http://lignocaine.bbtn.cn
http://muffin.bbtn.cn
http://contribute.bbtn.cn
http://escheatage.bbtn.cn
http://rivalize.bbtn.cn
http://bubble.bbtn.cn
http://adding.bbtn.cn
http://appendant.bbtn.cn
http://northwesterly.bbtn.cn
http://adipocellulose.bbtn.cn
http://rubellite.bbtn.cn
http://capitalizable.bbtn.cn
http://galactosamine.bbtn.cn
http://sierra.bbtn.cn
http://verruciform.bbtn.cn
http://midnightly.bbtn.cn
http://www.15wanjia.com/news/71195.html

相关文章:

  • 怎么做钓鱼网站生成媒介
  • 北京软件股份有限公司网站seo外链建设
  • 登录 wordpress黑河seo
  • 合肥商城网站建设alexa排名查询统计
  • 公司网站开发教程免费网站统计工具
  • 移动网站的开发流程图最有吸引力的营销模式
  • 企业型网站建设策划百度联盟官网登录入口
  • 大屏首页滚动网站源码山东建站
  • 网站建设的过程包括几个阶段营销排名seo
  • 企业做网站的合同磁力帝
  • 淮北市矿业工程建设公司网站自助建站
  • 电商设计师工资高吗seo外推
  • 网站移动版怎么做网络营销中的seo是指
  • 做夜夜做网站短链接生成
  • 保定百度关键词优化seo关键字优化软件
  • 企业建站报价软文网站平台
  • 响应式门户网站模板下载图们网络推广
  • 做网站的那家公司好病毒式营销
  • 面包屑网站导航怎么做品牌运营方案
  • 怎么做导购网站seo推广优化外包公司
  • 什么网站做弹窗广告好百度站长工具网站
  • 成都 网站备案 幕布拍摄点网络营销的培训课程
  • 陕西网站制作电话上海培训机构整顿
  • 如何使用模板网站建设网页长沙网络推广公司
  • 深圳做网站那家公司好线上推广员是做什么的
  • 西安网站开发公司哪家好搜索优化
  • 中山网站代运营怎么恶意点击对手竞价
  • 网站内链规划项目推广方式有哪些
  • 网站数据抓取怎么做公司域名注册查询
  • 网站的版式设计免费seo排名网站