密码标签生成、数据集嵌入黑盒水印模块源码及打包项目

liyan 168d3777f3 修改数据集处理脚本,修改项目说明文档,添加测试代码 9 months ago
tests 168d3777f3 修改数据集处理脚本,修改项目说明文档,添加测试代码 9 months ago
watermark_generate 168d3777f3 修改数据集处理脚本,修改项目说明文档,添加测试代码 9 months ago
.gitignore c508cabbea 修改日志控制接口地址,修改提交忽略文件 9 months ago
MANIFEST.in 4546a382fa 修改打包配置,修改项目说明文件 9 months ago
README.md 168d3777f3 修改数据集处理脚本,修改项目说明文档,添加测试代码 9 months ago
setup.py 420f175acd 修改打包配置 9 months ago

README.md

密码标签获取,数据集嵌入黑盒水印源码及打包项目

功能列表

  • 密码标签生成
  • 密码标签自检(测试)
  • 密码标签验证
  • 图像嵌入密码标签
  • 图像提取密码标签
  • 图像处理功能自检
  • 日志模板
  • 日志记录

分支说明

  • master分支只包含项目打包配置和密码标签获取,数据集嵌入黑盒水印源码

安装依赖

pip install -r requirements.txt

文件组成

.
├── MANIFEST.in  # 打包过滤文件
├── README.md  # 描述文件
├── setup.py  # 打包配置文件
├── tests  # 测试目录
│   └── test_dataset_process.py  # 测试数据集处理
└── watermark_generate  # 水印生成源码
    ├── __init__.py
    ├── blind_watermark  # 图片嵌入盲水印源码
    │   ├── __init__.py
    │   ├── att.py 
    │   ├── blind_watermark.py
    │   ├── bwm_core.py
    │   ├── cli_tools.py
    │   ├── pool.py
    │   └── recover.py
    ├── controller  # 对外提供的http接口
    │   ├── __init__.py
    │   ├── dataset_controller.py  # 数据集处理接口,包括图片嵌入水印处理、图片提取水印、水印功能自检
    │   ├── log_controller.py  # 日志控制接口,支持控制日志级别,控制日志输出大小
    │   └── secret_controller.py  # 密码标签生成接口,包括密码标签生成、密码标签验证、密码标签功能自检
    ├── domain  # 对外提供http接口的参数与响应
    │   ├── __init__.py
    │   ├── dataset_domain.py
    │   └── secret_domain.py
    ├── requirements.txt  # 项目依赖文件,安装依赖使用
    ├── resource  # 静态资源文件夹
    │   └── test.jpg  # 用于图片水印功能自检的测试图片,可根据需求更改
    ├── run.py  # 服务运行脚本
    └── tools  #工具脚本目录
        ├── __init__.py
        ├── dataset_process.py  # 数据集处理脚本
        ├── logger_tool.py  # 日志工具脚本
        ├── picture_watermark.py  # 图片水印嵌入提取工具
        └── secret_func.py  # 密码标签生成与验证工具,需要根据密码机实际提供接口进行修改,目前只有模拟实现

AI水印黑盒水印HTTP接口

Base URLs:

Authentication

POST 日志调整接口

POST /znwr/jit/ai/v1/log_setting

Body 请求参数

{
  "level": "string",
  "size": 0
}

请求参数

名称 位置 类型 必选 中文名 说明
body body object none
» level body string 输出日志级别 debug、info、warning、error
» size body number 日志最大大小限制 单位KB

返回示例

200 Response

{
  "code": 0,
  "msg": "string"
}

返回结果

状态码 状态码含义 说明 数据模型
200 OK 成功 VerifyLabelResp

模型密码标签生成模块

POST 密码标签生成

POST /znwr/jit/ai/v1/crypto-label

Body 请求参数

{
  "info": {
    "owner": {
      "name": "string",
      "id": "string"
    },
    "model": {
      "name": "string",
      "id": "string",
      "version": "string",
      "date": "2019-08-24T14:15:22Z"
    }
  }
}

请求参数

名称 位置 类型 必选 中文名 说明
body body GenLabelForm none

返回示例

200 Response

{
  "code": 0,
  "msg": "string",
  "label": "string",
  "cert": "string"
}

返回结果

状态码 状态码含义 说明 数据模型
200 OK 成功 GenLabelResp

POST 密码标签功能自检

POST /znwr/jit/ai/v1/crypto-check

返回示例

200 Response

{
  "code": 0,
  "msg": "string"
}

返回结果

状态码 状态码含义 说明 数据模型
200 OK 成功 VerifyLabelResp

POST 密码标签嵌入图像

POST /znwr/jit/ai/v1/picture_embed

Body 请求参数

file: string
label: string

请求参数

名称 位置 类型 必选 中文名 说明
body body object none
» file body string(binary) 待嵌入的图像信息
» label body string 密码标签

返回示例

200 Response

{
  "code": 0,
  "msg": "string"
}

返回结果

状态码 状态码含义 说明 数据模型
200 OK 成功 VerifyLabelResp

POST 图像处理功能自检

POST /znwr/jit/ai/v1/picture_check

返回示例

200 Response

{
  "code": 0,
  "msg": "string"
}

返回结果

状态码 状态码含义 说明 数据模型
200 OK 成功 VerifyLabelResp

模型密码标签验证模块

POST 密码标签验证

POST /znwr/jit/ai/v1/verify-label

Body 请求参数

{
  "label": "string",
  "info": "string",
  "cert": "string"
}

请求参数

名称 位置 类型 必选 中文名 说明
body body VerifyLabelForm none

返回示例

200 Response

{
  "code": 0,
  "msg": "string"
}

返回结果

状态码 状态码含义 说明 数据模型
200 OK 成功 VerifyLabelResp

POST 图片提取密码标签

POST /znwr/jit/ai/v1/picture_extract

Body 请求参数

file: file://C:\Users\hikari\Desktop\test_embed.jpg

请求参数

名称 位置 类型 必选 中文名 说明
body body object none
» file body string(binary) none

返回示例

200 Response

{
  "code": 0,
  "msg": "string",
  "label": "string"
}

返回结果

状态码 状态码含义 说明 数据模型
200 OK 成功 ExtractLabelResp

数据模型

ExtractLabelResp

{
  "code": 0,
  "msg": "string",
  "label": "string"
}

属性

名称 类型 必选 约束 中文名 说明
code integer true none 错误码 none
msg string true none 错误信息 none
label string true none 密码标签 none

RespStatus

{
  "code": 0,
  "msg": "string"
}

属性

名称 类型 必选 约束 中文名 说明
code integer true none 错误码 none
msg string true none 错误信息 none

VerifyLabelResp

{
  "code": 0,
  "msg": "string"
}

属性

名称 类型 必选 约束 中文名 说明
code integer true none 错误码 none
msg string true none 错误信息 none

VerifyLabelForm

{
  "label": "string",
  "info": "string",
  "cert": "string"
}

属性

名称 类型 必选 约束 中文名 说明
label string true none 密码标签 none
info string true none 模型信息 none
cert string true none 签名证书 none

GenLabelResp

{
  "code": 0,
  "msg": "string",
  "label": "string",
  "cert": "string"
}

属性

名称 类型 必选 约束 中文名 说明
code integer true none 错误码 none
msg string true none 错误信息 none
label string true none 生成标签 base64格式
cert string true none 签名证书 base64格式

GenLabelForm

{
  "info": {
    "owner": {
      "name": "string",
      "id": "string"
    },
    "model": {
      "name": "string",
      "id": "string",
      "version": "string",
      "date": "2019-08-24T14:15:22Z"
    }
  }
}

属性

名称 类型 必选 约束 中文名 说明
info object true none 生成标签信息 none
» owner object true none 模型所有者信息 none
»» name string true none 所有者 none
»» id string true none id none
» model object true none 模型信息 none
»» name string true none 模型名 none
»» id string true none 模型id none
»» version string true none 模型版本 none
»» date string(date-time) true none 创建日期 none

代码集成

from watermark_generate.tools.dataset_process import dataset_embed_label, process_dataset_label
from watermark_generate.tools.picture_watermark import extract

if __name__ == '__main__':
    label = '012ABCDEF'
    src_img_path = '../VOC2007/test/'
    dst_img_path = '../VOC2007/test_wm'
    label_path = '../VOC2007/test_labels'
    
    # 图片嵌入密码标签
    dataset_embed_label(label, src_img_path, dst_img_path)

    # 数据集处理测试
    process_dataset_label(dst_img_path, label_path, percentage=5)
    
    # 水印提取测试
    secret = extract('../VOC2007/test_wm/000044.jpg', secret_len=len(label))
    print(label == secret)

模块打包

python setup.py sdist

项目目录会生成dist目录,其中watermark_generate-1.0.tar.gz即为发布包

安装模块

pip install watermark_codec-1.0.tar.gz