From b3e51a565dc1d88e3bdc0c3b3ff034ffafe76761 Mon Sep 17 00:00:00 2001 From: lvyuankang <1344032923@qq.com> Date: Tue, 4 Jun 2024 14:18:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B3=A8=E9=87=8A=E6=B7=BB=E5=8A=A0=E5=86=B2?= =?UTF-8?q?=E7=AA=81=E5=9B=9E=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/ets/entryability/EntryAbility.ts | 13 +- entry/src/main/ets/pages/Index.ets | 13 +- entry/src/main/ets/pages/UserInfo.ets | 2 +- .../ets/pages/compontents/FaceCompare.ets | 430 +++++++++--------- entry/src/main/module.json5 | 5 +- 5 files changed, 246 insertions(+), 217 deletions(-) diff --git a/entry/src/main/ets/entryability/EntryAbility.ts b/entry/src/main/ets/entryability/EntryAbility.ts index a393f1d3..815dcc77 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ts +++ b/entry/src/main/ets/entryability/EntryAbility.ts @@ -32,8 +32,17 @@ export default class EntryAbility extends UIAbility { globalThis.judgeVersion = '2024.11.22.14' globalThis.videoVersion= '1.0' // globalThis.version = '2022.03.14.01' - - globalThis.context = this.context; + //视频遮挡 + globalThis.spzd={ + spzd1:false, + spzd2:false, + spzd3:false, + spzd4:false, + } + globalThis.singlePlay=false //单机模式 + globalThis.signNum=0//心跳指令编号 + globalThis.lsh='0000000000000'//学员流水号 + globalThis.statue=1//考试状态 globalThis.pathDir = this.context.filesDir; console.info('jiangsong globalThis.pathDir = ' + globalThis.pathDir); // this.requestPermission(this.context) diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index ba9ed73a..f0856609 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -9,10 +9,14 @@ import { getUDP, getUDP2 } from '../common/utils/GlobalUdp'; import { initJudgeUdp } from '../common/utils/UdpJudge'; import { getTCP } from '../common/utils/GlobalTcp'; import testNapi from '@ohos.hiserialsdk'; +import { + getEsCarModel, +} from '../common/service/initable' import { getDoubleCeneterTable, getliushuiNum, getSingleCenterTable, + setliushuiNum, takePhotoFn } from '../common/service/indexService'; import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl'; @@ -31,6 +35,7 @@ struct Index { @State ratio: number = 1700 / 960 @State loading: boolean = true @State fd: number = -1; + private interval=null; private context = getContext(this) as common.UIAbilityContext; fileHelper =null; build() { @@ -78,6 +83,7 @@ struct Index { if (globalThis.timeInfo?.mode == '3') { await getDoubleCeneterTable() } else if (globalThis.timeInfo?.mode == '1') { + //单中心 await getSingleCenterTable() } else { promptAction.showToast({ @@ -135,8 +141,6 @@ struct Index { GestureGroup(GestureMode.Exclusive, TapGesture({ count: 2 }) .onAction(() => { - // takePhotoFn(this.context) - globalThis.singlePlay = !globalThis.singlePlay this.isSingle = globalThis.singlePlay }) @@ -201,7 +205,6 @@ struct Index { tmpList.push(string2Bytes(str.charCodeAt(i), 1 * 8)[0]) } const param= {id: 31,list:tmpList,carNo: globalThis.carInfo.carNo,placeId: globalThis.carInfo.examinationRomId} - // globalThis.udpClient2.initHeartSendMsg(param,this.context) globalThis.udpClient2.sendMsg(param, this.context) } @@ -209,11 +212,12 @@ struct Index { this.loading = false this.createAlbum() this.userAuth(); + //plc getUDP() getUDP2() clearInterval(this.interval) this.interval=setInterval(() => { - setliushuiNum() + setliushuiNum(this.context) getliushuiNum() this.heartMsg() }, 1000) @@ -275,7 +279,6 @@ struct Index { // await this.getModel() // const arr = [0x55, 0xaa, 0x01, 0x00, 0x02, 0x01, 0x03, 0x00] // globalThis.udpClientByTopLine.sendMsg(Array2Byte(arr).buffer) - console.info(testNapi) } async getModel() { const context = this.context; diff --git a/entry/src/main/ets/pages/UserInfo.ets b/entry/src/main/ets/pages/UserInfo.ets index b85f1953..1bbac21e 100644 --- a/entry/src/main/ets/pages/UserInfo.ets +++ b/entry/src/main/ets/pages/UserInfo.ets @@ -6,7 +6,7 @@ import AccountTable from '../common/database/tables/AccountTable'; import USER from '../common/constants/USER'; import { dateFormat, getCurrentTime } from '../common/utils/tools'; import MA_SYSSET from '../common//constants/MA_SYSSET'; -import FaceCompare from './compontents/faceCompareByhaikang' +import FaceCompare from './compontents/FaceCompare' // import { initJudgeUdp } from '../common/utils/UdpJudge' import { writeObjectOut } from '../api/judge' import testNapi from "@ohos.idcard"; diff --git a/entry/src/main/ets/pages/compontents/FaceCompare.ets b/entry/src/main/ets/pages/compontents/FaceCompare.ets index f9492f7a..650bb765 100644 --- a/entry/src/main/ets/pages/compontents/FaceCompare.ets +++ b/entry/src/main/ets/pages/compontents/FaceCompare.ets @@ -1,38 +1,72 @@ -import camera from '@ohos.multimedia.camera'; -import { cameraService } from '../../common/service/cameraService'; -import { voiceService } from '../../common/service/voiceService'; -import { faceCompare } from '../../api/userInfo'; -import prompt from '@ohos.prompt'; -import grantPermission from '../../common/utils/PermissionUtils'; -import CameraModel from '../../common/service/CameraModel'; +//@ts-ignore -let previewWidth; -let previewHeight; +import util from '@ohos.util'; -const PERMISSIONS: Array = [ - 'ohos.permission.CAMERA'] +import { voiceService } from '../../common/service/voiceService' +import { faceCompare } from '../../api/userInfo' +import FileUtil from '../../common/utils/File' +import { VideoConfig } from '../interfaces' +import common from '@ohos.app.ability.common'; + +import { string2Bytes } from '../../common/utils/tools' +import { takePhoto } from '../../common/service/videoService' +import { GlobalConfig } from '../../config/index' @Component export default struct FaceCompare { - @State imageBase64: string = 'data:image/jpeg;base64,' - @Prop sfzh: string; - @Prop firstImage: string; - @Link showFaceCompare: boolean; - @Link faceCompareSucess: boolean; - @State imageThumbnail: string = ''; - private mXComponentController: XComponentController = new XComponentController(); - private cameraModel: CameraModel = new CameraModel(); - private cameraObj = null; - private timer = null; //人脸比对执行任务定时器 - private stopClose = false; // 阻止用户关闭此组件 - private times = 1; //人脸比对失败次数, 超过3次将不会自动比对,需要点击重新打开重新触发 - private vocObj = null; - private surfaceId: string = ''; - constructor() { super() } + @State imageBase64: string = 'data:image/jpeg;base64,' + @Prop sfzh: string; + @Prop lsh: string; + @Prop firstImage: string; + @Link faceCompareSucess: number; + @Link showFaceCompare: boolean; + @Link getqkFlag: boolean; + @Link faceCatchImg: string; + @State imageThumbnail: string = ''; + private times = 1; //人脸比对失败次数, 超过3次将不会自动比对,需要点击重新打开重新触发 + private vocObj = null; + @State callBackFlag: boolean = false; + @State @Watch('clearIntervalFn') showFaceCompareFlag: Boolean = false; + @State video_url: string = 'rtsp://admin:12345qwe@192.168.5.41:8000/h264/ch2/main/av_stream' + @State previewUri: Resource = $r('app.media.2_nor') + @State curRate: PlaybackSpeed = PlaybackSpeed.Speed_Forward_1_00_X + @State showControls: boolean = false + private controller: VideoController = new VideoController() + @State isAutoPlay: boolean = true + @State signNum: number = 0; + private fileUtil: FileUtil + private interval: any + @State param: VideoConfig = { + spls: '', + videoNum: '1', + faceFlag: false, + pztd: '1', + ljlx: '', + ip: '192.168.7.112', + port: '554', + userName: 'admin', + pwd: '12345qwe', + td1: '1', + td2: '2', + td3: '3', + td4: '4', + videoRecord1: false, + videoRecord2: false, + videoRecord3: false, + videoRecord4: false, + rlls: '1', + spzd4:false, + spzd3:false, + spzd2:false, + spzd1:false, + zdyz:'500', + } + private context = getContext(this) as common.UIAbilityContext; + build() { Column() { Column() { @@ -44,29 +78,22 @@ export default struct FaceCompare { Row() { Row() { - XComponent({ - id: 'componentId', - type: 'surface', - controller: this.mXComponentController + Video({ + src: this.showFaceCompare ? `rtsp://${this.param.userName}:${this.param.pwd}@${this.param.ip}:${this.param.port}/h264/ch${this.param.rlls}/main/av_stream` : '', + previewUri: this.previewUri, + currentProgressRate: PlaybackSpeed.Speed_Forward_1_00_X, + controller: this.controller, }) - .onLoad(() => { - // this.mXComponentController.setXComponentSurfaceSize({surfaceWidth:640,surfaceHeight:480}); - // let surfaceId = this.mXComponentController.getXComponentSurfaceId() - // console.log('jiangsong: xcomponentController this.surfaceId = ' + surfaceId) - this.mXComponentController.setXComponentSurfaceSize({ surfaceWidth: 640, surfaceHeight: 480 }); - this.surfaceId = this.mXComponentController.getXComponentSurfaceId(); - this.cameraModel.initCamera(this.surfaceId); - - this.readyToTakePhoto(this.surfaceId) - - }) + .muted(true) .width('100%') .height('100%') - .backgroundColor(Color.Black) + .autoPlay(this.isAutoPlay) + .controls(this.showControls) } .width('48%') .height('100%') + Row() { Image(this.firstImage) .width('100%') @@ -106,9 +133,7 @@ export default struct FaceCompare { .backgroundImageSize({ width: '100%', height: '100%' }) .onClick(async () => { this.times = 1; - // this.takePhoto('face_check.mp3'); - this.readyToTakePhoto(this.surfaceId); - // await this.cameraObj.releaseSource() + }) } .width('88.9%') @@ -134,24 +159,14 @@ export default struct FaceCompare { .backgroundImage($r('app.media.close')) .backgroundImageSize({ width: '100%', height: '100%' }) .onClick(() => { - // prompt.showToast({ - // message: '人脸比对程序正在执行,请等待程序执行完毕。', - // duration: 3000 - // }); - this.showFaceCompare = false - this.faceCompareSucess = false - return - console.log('jiangsong close the faceCompare componet'); - if (!this.stopClose) { - this.showFaceCompare = false + this.controller.stop() + this.vocObj && this.vocObj.releasePlayer() + this.showFaceCompare = !this.showFaceCompare + this.showFaceCompareFlag=!this.showFaceCompareFlag + this.faceCompareSucess = -1 + globalThis.statue = 2 + - } else { - prompt.showToast({ - message: '人脸比对程序正在执行,请等待程序执行完毕。', - duration: 3000 - }); - this.showFaceCompare = false - } }) } .width('100%') @@ -161,178 +176,177 @@ export default struct FaceCompare { } onPageShow() { - this.cameraModel.initCamera(this.surfaceId); } async aboutToAppear() { - // this.cameraModel.initCamera(this.surfaceId); - await grantPermission().then(res => { - if (this.surfaceId) { - this.cameraModel.initCamera(this.surfaceId); - } - }).catch(rej => { - }) - - this.surfaceId = this.mXComponentController.getXComponentSurfaceId(); - // this.cameraModel.setTakePictureHandleCallback(this.takePictureHandle.bind(this)); + const fileUtil = new FileUtil(this.context) + this.fileUtil = fileUtil + this.getVideoConfig() } - // takePictureHandle = (thumbnail: string) => { - // this.imageThumbnail = thumbnail; - // }; - - async initCamera(surfaceId: string) { - //动态获取隐私权限 - let context = getContext(this) as any - await context.requestPermissionsFromUser(PERMISSIONS) - console.log('grantPermission,requestPermissionsFromUser'); - // 创建CameraManager对象 - let cameraManager = await camera.getCameraManager(context) - if (!cameraManager) { - console.error('Failed to get the CameraManager instance'); - } - // 获取相机列表 - let cameraArray = await cameraManager.getSupportedCameras() - if (!cameraArray) { - console.error('Failed to get the cameras'); - } - for (let index = 0; index < cameraArray.length; index++) { - console.log('cameraId : ' + cameraArray[index].cameraId) // 获取相机ID - console.log('cameraPosition : ' + cameraArray[index].cameraPosition) // 获取相机位置 - console.log('cameraType : ' + cameraArray[index].cameraType) // 获取相机类型 - console.log('connectionType : ' + cameraArray[index].connectionType) // 获取相机连接类型 - } - - // 创建相机输入流 - let cameraInput = await cameraManager.createCameraInput(cameraArray[0]) - - // 打开相机 - await cameraInput.open().then(() => { - console.log('opencamera succ.'); - }).catch(function (err) { - console.log("opencamera failed with error:" + err); - }); - - // 获取相机设备支持的输出流能力 - let cameraOutputCap = await cameraManager.getSupportedOutputCapability(cameraArray[0]); - if (!cameraOutputCap) { - console.error("outputCapability outputCapability == null || undefined") - } else { - console.log("outputCapability: " + JSON.stringify(cameraOutputCap)); - } - - //获取相机支持的输出能力--支持的预览配置信息 - let previewProfilesArray = cameraOutputCap.previewProfiles; - if (!previewProfilesArray) { - console.error("createOutput previewProfilesArray == null || undefined") - } else { - console.log("previewProfiles:" + JSON.stringify(previewProfilesArray[0])) - previewWidth = previewProfilesArray[0].size.width; - previewHeight = previewProfilesArray[0].size.height; - } - - // 创建预览输出流,其中参数 surfaceId 参考下面 XComponent 组件,预览流为XComponent组件提供的surface - let previewOutput = await cameraManager.createPreviewOutput(previewProfilesArray[0], surfaceId) - if (!previewOutput) { - console.error("Failed to create the PreviewOutput instance.") - } else { - console.log("create the PreviewOutput instance succ.") - } - - //创建会话 - let captureSession = await cameraManager.createCaptureSession() - if (!captureSession) { - console.error('Failed to create the CaptureSession instance.'); - return; - } - console.log('Callback returned with the CaptureSession instance.' + captureSession); - - // 开始配置会话 - await captureSession.beginConfig() - - // 向会话中添加相机输入流 - await captureSession.addInput(cameraInput) - - // 向会话中添加预览输入流 - await captureSession.addOutput(previewOutput) - - // 提交会话配置 - await captureSession.commitConfig() - // 启动会话 - await captureSession.start().then(() => { - console.log('captureSession start success.'); - }).catch(function (err) { - console.log("captureSession start failed with error:" + err); - }); + clearIntervalFn() { + this.callBackFlag = false + clearInterval(this.interval) + this.vocObj && this.vocObj.releasePlayer() } - async aboutToDisappear() { - clearTimeout(this.timer) - this.vocObj.releasePlayer() - this.cameraObj.releaseSource() + getqkFn() { + let tmpList = []; + tmpList.push(string2Bytes(globalThis.signNum, 1 * 8)[0]) + const param = { + id: 41, + list: tmpList, + carNo: globalThis.carInfo.carNo, + placeId: globalThis.carInfo.examinationRoomId + } + globalThis.udpClient2.sendMsg(param, this.context) } - async readyToTakePhoto(surfaceId) { - this.surfaceId = surfaceId; - this.cameraObj = new cameraService(surfaceId); + async faceComparFn() { + console.log('mmmmm0',1) - setTimeout(() => { - this.showFaceCompare = false - this.faceCompareSucess = true; - }, 3000) - return - await this.cameraObj.initCamera((img) => { - console.log('jiangsong getPhoto res.' + img.slice(0, 100)) - this.imageBase64 = 'data:image/jpeg;base64,' + img; - const firstImage = this.firstImage.substr(22) + takePhoto(this.param, this.context, 'jt/',0,({base64})=>{ faceCompare({ sfzh: this.sfzh, - firstImage: firstImage, - // sfzh: '321281198605076819', - // firstImage: this.firstImage, - secondImage: img, + firstImage: this.firstImage.substr(22), + secondImage: base64, type: 2, verifyType: 1 }).then(res => { + console.log('mmmmm8',res) + if (res) { - console.log('jiangsong face compare success' + JSON.stringify(res)) - this.showFaceCompare = false - this.faceCompareSucess = true; + this.controller.stop() + this.showFaceCompare = !this.showFaceCompare + this.showFaceCompareFlag=!this.showFaceCompareFlag + this.faceCompareSucess = 1; + // this.faceCatchImg = result + this.vocObj.playAudio({ + type: 1, + name: 'yzcg.wav' + }) } else { - console.log('jiangsong face compare faild') + this.times++; //3s后开始语音提示 - this.timer = setTimeout(() => { - this.takePhoto('face_fail.mp3'); - }, 3000) + this.vocObj.playAudio({ + type: 1, + name: 'face_fail.mp3' + }) + } }) - }); - this.vocObj = new voiceService(async (status) => { - console.log('jiangsong voiceService callback. status == ' + status) - if (status == 'completed') { - this.cameraObj.takePhoto(); + }) + console.log('mmmmm8',9) + + + + + } + + async heartMsg(context) { + let tmpList = [] + const str = this.lsh + for (let i = 0;i < str.length; i++) { + tmpList.push(string2Bytes(str.charCodeAt(i), 1 * 8)[0]) + } + const param = { + id: 46, + list: tmpList, + carNo: globalThis.carInfo.carNo, + placeId: globalThis.carInfo.examinationRoomId, + sendCallback: () => { + this.callBackFlag = true + } + } + globalThis.udpClient2 && globalThis.udpClient2.sendMsg(param, this.context) + clearInterval(this.interval) + this.interval = setInterval(() => { + if (this.callBackFlag) { + const param2 = { + id: 47, + list: tmpList, + carNo: globalThis.carInfo.carNo, + placeId: globalThis.carInfo.examinationRoomId, + } + globalThis.udpClient2 && globalThis.udpClient2.sendMsg(param2, this.context) + } + }, 1000) + globalThis.udpClient2.setMsgCallBack((val) => { + if (val.id == '48') { + if (val.body[13] == '1') { + this.showFaceCompareFlag=!this.showFaceCompareFlag + this.showFaceCompare = !this.showFaceCompare + this.vocObj && this.vocObj.releasePlayer() + this.faceCompareSucess = 1 + clearInterval(this.interval) + } else if (val.body[13] == '0' && this.callBackFlag) { + globalThis.statue = 2 + this.vocObj && this.vocObj.playAudio({ + type: 1, + name: 'face_chekc_fail.wav' + }) + } + } + }) + + } + + async getVideoConfig() { + console.log('faceEnterIn') + this.vocObj = new voiceService(async (status, val, next) => { + if (status == 'idle') { + if (val == 'face_check.mp3' || val == 'face_fail.mp3') { + if (this.times >= 3) { + globalThis.statue = 3 + this.faceCompareSucess = -1; + this.vocObj && this.vocObj.playAudio({ + type: 1, + name: 'face_checking.wav' + }) + this.heartMsg(this.context) + } else { + setTimeout(() => { + this.faceComparFn() + }, 2000) + } + } else if (val == 'yzcg.wav') { + this.showFaceCompare = !this.showFaceCompare + this.showFaceCompareFlag=!this.showFaceCompareFlag + globalThis.statue = 4 + this.faceCompareSucess = 1; + this.vocObj && this.vocObj.releasePlayer() + + } else if (val == 'face_chekc_fail.wav') { + this.vocObj && this.vocObj.releasePlayer() + this.faceCompareSucess = -1 + this.showFaceCompare = !this.showFaceCompare + this.showFaceCompareFlag=!this.showFaceCompareFlag + } } }); - //3s后开始语音提示 - this.timer = setTimeout(() => { - this.takePhoto('face_check.mp3'); - }, 3000) + const data = await this.fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/config3.txt'); + console.log('faceEnterIn,data',data) + + setTimeout(() => { + this.vocObj && this.vocObj.playAudio({ + type: 1, + name: 'face_check.mp3' + }) + }, 1000) + this.param = JSON.parse(data) + this.param.userName = JSON.parse(data).userName + this.param.ip = this.param.ip + this.param.pwd = this.param.pwd + this.param.port = this.param.port + this.param.rlls = this.param.rlls + this.controller.start() } - takePhoto(name) { - this.stopClose = true; - if (this.times > 3) { - this.stopClose = false; - return; - } - this.times++; - this.vocObj.playAudio({ - type: 1, - name: name - }) + + async aboutToDisappear() { + } } -// export default FaceCompare \ No newline at end of file diff --git a/entry/src/main/module.json5 b/entry/src/main/module.json5 index f32cc5b7..7eaa0e8a 100644 --- a/entry/src/main/module.json5 +++ b/entry/src/main/module.json5 @@ -6,7 +6,10 @@ "mainElement": "EntryAbility", "deviceTypes": [ "default", - "tablet" + "tablet", + "pad", + "wearable", + "car", ], "deliveryWithInstall": true, "installationFree": false,