物联网(java版本)臻识摄像头+威视显示屏

硬件准备

臻识摄像头,威视显示屏(如下图)

出口配置

入口配置

核心部分代码展示

/**
     * 臻识设备识别车牌反馈数据
     * @param license           车牌号
     * @param serialno          设备序列号
     * @param imageFile         大图
     * @param imageFragmentFile 小图
     * @param response          请求
     * @throws IOException
     */
    public void addRecord(HttpServletRequest request, String license, String serialno, String imageFile, String imageFragmentFile, HttpServletResponse response) throws IOException {

//        System.out.println("-----------------进入车牌识别操作 ---------------------" + "车牌:" +  license + "  设备序列号:" + serialno);

        // 根据序列号查询设备   -- 没有设备直接开闸   --- 写入错误日志
        PlateDevice plateDevice = plateDeviceService.selectByExample(serialno);
        if(StringUtils.isEmpty(plateDevice)){
//            System.out.println("-----------------根据序列号未查询到车牌识别设备信息---------------------");
            ZenithUtils.open(response);
            return;
        }

        //获取设备的配置信息
        PlateConfig plateConfig = plateConfigService.selectByExample(plateDevice.getDevDistrictId());
        if(plateConfig == null){
//            System.out.println("-----------------未找到小区的车牌系统配置信息---------------------");
            ZenithUtils.open(response);
            return;
        }

        //判断该设备序列号是那个出口的
        if(plateDevice.getInOut() == 1){
            // 入口设备操作
//            System.out.println("------------------device start in---------------------");
            isIn(request, license,plateDevice,plateConfig, response, imageFile, imageFragmentFile);
        }else{
            // 出口设备操作
//            System.out.println("------------------device start out---------------------");
            // 出口设备判断是否需要收费.// 如果不用直接通行
            if(plateRecordService.updateByExampleSelective(request, license,serialno,plateDevice.getHeId(),plateDevice.getCompanyId(),plateDevice.getDevDistrictId(), imageFile, imageFragmentFile)){
                ZenithUtils.openExitDoor(license, response);

                //更新物联小区停车数量
                plateConfigService.updateByExampleSelective(plateDevice.getDevDistrictId(), plateConfig.getCarNumber(), "add");
            }else{
                PlateRecord plateRecord = plateRecordService.selectByExample(license,serialno,plateDevice.getHeId(),plateDevice.getCompanyId());

                if(plateRecord != null){

                    long nd = 1000 * 24 * 60 * 60;//每天毫秒数
                    long nh = 1000 * 60 * 60;//每小时毫秒数
                    long nm = 1000 * 60;//每分钟毫秒数
                    long diff = plateRecord.getoTime().getTime() - plateRecord.getiTime().getTime(); // 获得两个时间的毫秒时间差异
                    long min = diff/60/1000;  // 计算差多少分钟
//                    System.out.println("相差分钟" + min);

                    //播报支付金额
                    ZenithUtils.openChargeDoor(license, plateRecord.getMoney(), min, response);
                }
            }
        }

    }



    /**
     * 入口操作
     * @param license  车牌号
     * @param plateDevice    设备信息
     * @param response 请求
     * @throws IOException
     */
    public void isIn(HttpServletRequest request, String license, PlateDevice plateDevice,PlateConfig plateConfig , HttpServletResponse response, String imageFile, String imageFragmentFile) throws IOException {

        //判断物联小区的配置信息---是否开启 【没车位时是否控制外来车辆(0没车位也允许1没车位时不允许】
        if(plateConfig.getForeignControl().equals("1") && plateConfig.getCarNumber() <=0 ){
            //车位已满,禁止入内 【如果开启车位检测】
            ZenithUtils.openForbidCarNum(license,response);
        }

//        System.out.println("-----------------进入车牌识别操作(入口操作)---------------------");
        //默认初始物联小区 车牌识别系统的运行模式。0 普通模式  1 封闭模式
        String devDistrictModel = "0";
        if(plateConfig != null){
            devDistrictModel = plateConfig.getDevDistrictModel();
        }


        //查看业主表是否是业主车牌
        PlateOwnerCarNumberExample plateOwnerCarNumberExample = new PlateOwnerCarNumberExample();
        PlateOwnerCarNumberExample.Criteria criteria1 = plateOwnerCarNumberExample.createCriteria();
        criteria1.andCarNumberEqualTo(license);
        criteria1.andHeIdEqualTo(plateDevice.getHeId());
        criteria1.andCompanyIdEqualTo(plateDevice.getCompanyId());
        criteria1.andStatusEqualTo("0");
        criteria1.andIsDelEqualTo("0");
        List<PlateOwnerCarNumber> plateOwnerCarNumberList = plateOwnerCarNumberDAO.selectByExample(plateOwnerCarNumberExample);

        //判断是否封闭模式
        if(!devDistrictModel.equals("0")){
//            System.out.println("------进入封闭模式------");
            //小区处于封闭模式  查看是否是属于本小区车辆, 车辆的过期时间是否过期 【判断是否可以通行】
            if(sealOff(license, plateDevice,response)){

                ZenithUtils.openEntranceDoor(license,plateConfig.getCarNumber()-1,response);

                // 变更小区车位信息
                plateConfigService.updateByExampleSelective(plateDevice.getDevDistrictId(), plateConfig.getCarNumber(), "del");

                //插入对应的通行记录
                plateRecordService.insertSelective(request, license, plateDevice.getSerialno(), plateDevice.getHeId(), plateDevice.getCompanyId(),imageFile, imageFragmentFile);
                return;
            }else{

                //禁止通行
                ZenithUtils.openForbidModel(license,response);
                return;
            }
        }else{

            //非封闭模式
            if(plateOwnerCarNumberList.size() > 0){

                System.out.println("业主车辆");

                //允许通行
                ZenithUtils.openEntranceDoor(license,plateConfig.getCarNumber()-1,response);
            }else{

                System.out.println("外来车辆, 临时停车");

                ZenithUtils.openEntranceFeeDoor(license,plateConfig.getCarNumber()-1,response);
            }

            //插入对应的通行记录
            // 变更小区车位信息
            plateConfigService.updateByExampleSelective(plateDevice.getDevDistrictId(), plateConfig.getCarNumber(), "del");

            //插入对应的通行记录
            plateRecordService.insertSelective(request, license, plateDevice.getDeviceSerial(), plateDevice.getHeId(), plateDevice.getCompanyId(),imageFile, imageFragmentFile);
        }
    }


    /**
     * 小区处于封闭模式  查看是否是属于本小区车辆, 车辆的过期时间是否过期
     */
    public boolean sealOff(String license, PlateDevice plateDevice, HttpServletResponse response) throws IOException{
//        System.out.println("-------------------处于封闭模式------------------------------");

        PlateOwnerCarNumber plateOwnerCarNumber = plateOwnerCarNumberService.selectByExample(license, plateDevice.getHeId());
        if(plateOwnerCarNumber != null){
            if(DateUtils.compare_date(new Date(), plateOwnerCarNumber.getStartTime()) != -1 && DateUtils.compare_date(plateOwnerCarNumber.getEndTime(), new Date()) != -1){
                return true;
            }else{
                return false;
            }
        }else{
            PlateVisitorCarNumber plateVisitorCarNumber = plateVisitorCarNumberService.selectByExample(license, plateDevice.getHeId());
            if(plateVisitorCarNumber != null){
                if(DateUtils.compare_date(new Date(), plateOwnerCarNumber.getStartTime()) != -1 && DateUtils.compare_date(plateOwnerCarNumber.getEndTime(), new Date()) != -1){
                    return true;
                }else{
                    return false;
                }
            }else{
                return false;
            }
        }
    }
if (StringUtils.isBlank(huaXiaDataVo.getCam_id()) || "0".equals(huaXiaDataVo.getCam_id())) {
            logger.info("设备mac号是空或者0");
            return;
        }
        /**
         * 设备id
         */
        String deviceidcode = huaXiaDataVo.getCam_id();
        /**
         *出入口类型,in 表示入口,out 表示出口
         */
        String direction = huaXiaDataVo.getVdc_type();

        Base64 base64 = new Base64();
        /**
         * 全景图,
         */
        String ImageFile1 = huaXiaDataVo.getPicture();
        if (ImageFile1 != null) {
            byte[] img = base64.decode(ImageFile1);
            InputStream inputStream = new ByteArrayInputStream(img);
            if ("in".equals(direction)) {
                ImageFile1 = this.aliyunService.uploadFile(inputStream, "driveIn/" + System.currentTimeMillis() + Math.random() + ".jpg");

            } else if ("out".equals(direction)) {
                ImageFile1 = this.aliyunService.uploadFile(inputStream, "driveOut/" + System.currentTimeMillis() + Math.random() + ".jpg");

            }
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

        /**
         * 车牌特写图
         */
        String ImageFile2 = huaXiaDataVo.getCloseup_pic();
        if (ImageFile2 != null && !"-888".equals(ImageFile2)) {
            byte[] img = base64.decode(ImageFile2);
            InputStream inputStream = new ByteArrayInputStream(img);
            if ("in".equals(direction)) {
                ImageFile2 = this.aliyunService.uploadFile(inputStream, "driveIn/" + System.currentTimeMillis() + Math.random() + ".jpg");
            } else if ("out".equals(direction)) {
                ImageFile2 = this.aliyunService.uploadFile(inputStream, "driveOut/" + System.currentTimeMillis() + Math.random() + ".jpg");

            }
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        } else {
            ImageFile2 = ImageFile1;
        }

        /**
         * 车牌号
         */
        String plageNo = huaXiaDataVo.getPlate_num();
        /**
         * 查询该设备是否已经分配道闸出入口
         */
        String park_id = huaXiaDataVo.getPark_id();
        StcParkLanepp stcParkLanepp = rspLuWaiService.selectDeviceidParkLaneIs(deviceidcode);
        //检查对应泊位及分配情况

        if (stcParkLanepp == null) {
            logger.info("找不到该出入口,设备号是" + deviceidcode);
            return;
        }

        stcParkLanepp.setDeviceId(deviceidcode);
        if (stcParkLanepp.getStatus() != 0) {
            logger.info("车道已停用" + stcParkLanepp.getId());
            return;
        }

        String parkid = stcParkLanepp.getParkid();
        if (!park_id.equals(parkid)) {
            logger.info("设备ID对应的停车场id  与数据库对应的停车场id不一致");
            return;
        }


        Integer laneType = stcParkLanepp.getLaneType();

        String laneTypetemp = laneType == 0 ? "in" : "out";
        if (!laneTypetemp.equals(direction)) {
            logger.info("设备ID设置的出入口与对应的出入口不匹配");
            return;
        }
        Date time = null;
        final String start_time = huaXiaDataVo.getStart_time();
        Long sec = Long.parseLong(start_time);
        if (null != sec) {
            time = new Date(sec * 1000);
        } else {
            time = new Date();
        }
        logger.info("" + time);

      //  logger.info(">>>>>开始处理订单:DeviceID={}, count={}", deviceidcode);


        //判断该设备序列号是那个出口的
        if (in.equalsIgnoreCase(inorout)) {
            // 入口设备操作
//            System.out.println("------------------device start in---------------------");
            isIn(response, stcParkLanepp, huaXiaDataVo, time, ImageFile1, ImageFile2, plageNo, parkid);
        } else {
            // 出口设备操作
//            System.out.println("------------------device start out---------------------");
            // 出口设备判断是否需要收费.// 如果不用直接通行
            driveOut(response, huaXiaDataVo,  stcParkLanepp,  huaXiaDataVo,  time, ImageFile1, ImageFile2, plageNo, parkid);
        }

您们的朋友,java微技术

 

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
PHP是一种常用的服务器端编程语言,可以用于开发各种web应用程序。对接摄像机意味着将PHP应用程序与摄像机进行连接与通信。 首先,我们需要确定与摄像机的通信方式。通常,摄像机会提供SDK或API,用于与其他应用程序进行数据交互。我们可以通过阅读摄像机的文档或联系厂商了解可用的通信方式。 一般而言,我们可以使用PHP的网络相关函数和库来与摄像机进行通信。例如,可以使用cURL库发送HTTP请求与摄像机进行交互。这包括向摄像机发送命令、获取图像或视频流等操作。 在进行通信前,我们需要确保服务器端已经安装并配置好PHP、网络环境及相关依赖库。在PHP代码中,我们可以使用cURL函数来实现与摄像机的通信。首先,我们需要设置与摄像机通信的URL,并通过cURL函数设置参数,例如设置请求方法、请求头、请求体、超时时间等。 然后,我们可以发送请求并获取响应,根据需求对摄像机的回应进行处理。可以使用cURL函数提供的方法来获取响应的状态码、响应体等信息。根据返回的数据进行相应的处理,例如解析响应体中的数据、保存图像或视频等。 最后,我们可以将处理后的数据展示在web页面上,例如通过HTML将图像或视频嵌入到页面中,以便用户观看。可以使用PHP的图像处理库对图像进行进一步的编辑或分析。 总之,使用PHP对接摄像机需要了解摄像机的通信方式,并使用PHP的cURL库来实现与摄像机的通信。这样可以实现诸如发送命令、获取图像或视频流等操作,以满足各种应用场景的需求。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值