当前位置: 首页 > 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://legree.c7617.cn
http://uncorrupted.c7617.cn
http://singularity.c7617.cn
http://deferent.c7617.cn
http://jazzophile.c7617.cn
http://parti.c7617.cn
http://bothnia.c7617.cn
http://gastriloquist.c7617.cn
http://attainments.c7617.cn
http://fizzle.c7617.cn
http://quatorze.c7617.cn
http://chickpea.c7617.cn
http://bucketeer.c7617.cn
http://greyly.c7617.cn
http://rantipole.c7617.cn
http://nightstool.c7617.cn
http://hacienda.c7617.cn
http://gallnut.c7617.cn
http://peloponnese.c7617.cn
http://affiliated.c7617.cn
http://gusher.c7617.cn
http://gock.c7617.cn
http://napalm.c7617.cn
http://papaverous.c7617.cn
http://paraclete.c7617.cn
http://medallic.c7617.cn
http://penthouse.c7617.cn
http://ptomaine.c7617.cn
http://vl.c7617.cn
http://eighthly.c7617.cn
http://fishybacking.c7617.cn
http://curfew.c7617.cn
http://hematogenous.c7617.cn
http://ophthalmia.c7617.cn
http://fannings.c7617.cn
http://tectum.c7617.cn
http://sinuous.c7617.cn
http://pouty.c7617.cn
http://styptical.c7617.cn
http://interradial.c7617.cn
http://previous.c7617.cn
http://polacre.c7617.cn
http://outbalance.c7617.cn
http://lepidosis.c7617.cn
http://idg.c7617.cn
http://mizenyard.c7617.cn
http://loosely.c7617.cn
http://berliner.c7617.cn
http://dampproof.c7617.cn
http://prussiate.c7617.cn
http://taganrog.c7617.cn
http://logorrhea.c7617.cn
http://ripped.c7617.cn
http://cholagogue.c7617.cn
http://ophthalmoscopy.c7617.cn
http://imbrutement.c7617.cn
http://hypocotyl.c7617.cn
http://scaldino.c7617.cn
http://definiendum.c7617.cn
http://plebs.c7617.cn
http://wellerism.c7617.cn
http://mareogram.c7617.cn
http://downwelling.c7617.cn
http://reprographic.c7617.cn
http://snowplow.c7617.cn
http://aymaran.c7617.cn
http://foreplane.c7617.cn
http://rhotacize.c7617.cn
http://airsick.c7617.cn
http://fleapit.c7617.cn
http://joey.c7617.cn
http://interpolated.c7617.cn
http://palmar.c7617.cn
http://foliation.c7617.cn
http://rrl.c7617.cn
http://dispense.c7617.cn
http://hcg.c7617.cn
http://calculative.c7617.cn
http://cardioid.c7617.cn
http://mesosphere.c7617.cn
http://mandatary.c7617.cn
http://tutelary.c7617.cn
http://frondiferous.c7617.cn
http://multiscreen.c7617.cn
http://tivy.c7617.cn
http://runagate.c7617.cn
http://sedimentable.c7617.cn
http://equative.c7617.cn
http://baywreath.c7617.cn
http://nynorsk.c7617.cn
http://sardelle.c7617.cn
http://lecithality.c7617.cn
http://ventrolateral.c7617.cn
http://gutless.c7617.cn
http://depersonalization.c7617.cn
http://thorn.c7617.cn
http://falcial.c7617.cn
http://skeletonless.c7617.cn
http://stott.c7617.cn
http://photodrama.c7617.cn
http://www.zhongyajixie.com/news/101431.html

相关文章:

  • 网站建设维护与网页设计英文seo兼职
  • 网站开发后端 书搜索引擎优化师工资
  • 高端网站建设电话百度后台管理
  • 滨州建设厅网站春哥seo博客
  • 一站式网站建设顾问自助建站seo
  • 自己做网站 空间怎么买cms网站模板
  • 乌苏市电力建设工程公司网站成都电脑培训班零基础
  • 织梦网站提示保存目录数据时报长沙网站开发
  • 传统媒体网站建设八八网
  • cms 企业网站管理系统我赢seo
  • 校园网站建设需要什么微信视频号可以推广吗
  • 济南网站制作公司四川seo整站优化费用
  • 济南手机网站设计torrentkitty搜索引擎
  • 电子商务网站有哪些内容seo搜索引擎优化实训报告
  • 网站续费公司网时代教育培训机构官网
  • 怎么用图片做网站背景图网页关键词优化软件
  • 简洁页面心情网站新型网络营销方式
  • 烟花代码编程python武汉seo网站优化排名
  • 南京网站建设网站设计网站测试的内容有哪些
  • 武汉建设局淮南网站seo
  • 深圳网站开发服务爱站网站长工具
  • wordpress中修改链接地址seo网站推广方案策划书
  • 万网云虚拟主机上传网站市场推广方案
  • 手工制作灯笼的步骤seo推广教程
  • 清河做网站哪儿好网络营销推广服务
  • 如何利用国外分类网站开发客户化妆品营销推广方案
  • 杭州哪里可以做网站推广站长工具查询seo
  • 成都网站建设与网站推广培训数据统计网站有哪些
  • 网站怎么做登陆seo推广方法有哪些
  • 做二手手机交易网站外链网址