翻页检测文档V4.0
功能:判断何时向服务器发送需要识别的图片,在客户端(android、linux、RTOS)执行算法模块。
翻页检测的功能需要在客户端实现,需要将图灵提供的算法模块集成到设备上。
和V3.0版本的区别
- 提高了翻页的识别率及识别速度
- 为OCR模式及点读识别提供了更方便的输出
- 语文教材识别使用云端OCR功能
C语言版本
1.输入参数:
getMotionResult 参数列表
| 参数名称 | 必选 | 类型 | 描述 |
|---|---|---|---|
| md | 是 | MotionDetection | 翻页检测结构 |
| image | 是 | unsigned char[] | 图像内容-像素值 数据格式:支持RGB,BGR,yuv422 , yuv42 支持大小为640x480 |
| width | 是 | int | 图像-宽度 |
| height | 是 | int | 图像-高度 |
| channels | 是 | int | 图像通道数 |
| imageType | 是 | enum TL_IMAGE_TYPE | 图像-类型:enum 说明:image 的图像内容 |
| nowTime | 是 | long long | 当前的时间戳(毫秒级) |
| ocrFlag | 是 | int | ocrFlag=1:ocr模式 ocrFlag=0:非ocr模式 |
| fingerFlag | 是 | int | fingerFlag=1:指读模式 fingerFlag=0:非指读模式 |
1.1MotionDetection 需要初始化的参数
| 参数 | 必选 | 类型 | 描述 |
|---|---|---|---|
| min_thr | 是 | int | 最小阈值,和上一张图片对比的差异 默认30 调整识别翻页的灵敏度 |
| max_thr | 是 | int | 最大阈值,和上一张图片对比的差异 默认 100 调整识别翻页的灵敏度,想增加翻页检测的灵敏度时,可以适当减小这个值来实现 |
| minThrWaitTime | 是 | int | 最小的阈值等待时间 默认 100ms |
| dstHeight | 是 | int | 缩放图片的高度-默认100 调整识别翻页的灵敏度 |
| cropRate | 是 | int | 裁切图片大小,这里是比例大小默认值为 33 ,一般裁切1/3 调整识别翻页的灵敏度 |
| serverWaitTime | 是 | int | 服务器等待时间,服务端对前端的时间限制,调整识别速度 默认0 |
| timer | 是 | int | 定时对比,单位ms(毫秒) 默认100ms |
| nowTime | 是 | long long | 当前的时间戳(毫秒级) |
1.2图像类型说明
| 图像类型 | 对应参数 |
|---|---|
| GRAY | TL_CV_GRAY2GRAY = 0 |
| BGR | TL_CV_BGR2GRAY = 6 |
| RGB | TL_CV_RGB2GRAY = 7 |
| YUV420 | TL_CV_YUV2GRAY_420 = 106 |
| YUV_NV21 | TL_CV_YUV2GRAY_NV21 = TL_CV_YUV2GRAY_420 |
| YUV_NV12 | TL_CV_YUV2GRAY_NV12 = TL_CV_YUV2GRAY_420 |
| YUV_YV12 | TL_CV_YUV2GRAY_YV12 = TL_CV_YUV2GRAY_420 |
| IYUV | TL_CV_YUV2GRAY_IYUV = TL_CV_YUV2GRAY_420 |
| YUV_I420 | TL_CV_YUV2GRAY_I420 = TL_CV_YUV2GRAY_420 |
| YUV_422P | TL_CV_YUV2GRAY_Y422P = TL_CV_YUV2GRAY_I420 |
| YUV_UYVY | TL_CV_YUV2GRAY_UYVY = 123 |
| YUV_YUY2 | TL_CV_YUV2GRAY_YUY2 = 124 |
| YUV_Y422 | TL_CV_YUV2GRAY_Y422 = TL_CV_YUV2GRAY_UYVY |
| YUV_UYNV | TL_CV_YUV2GRAY_UYNV = TL_CV_YUV2GRAY_UYVY |
| YUV_YVYU | TL_CV_YUV2GRAY_YVYU = TL_CV_YUV2GRAY_YUY2 |
| YUV_YUYV | TL_CV_YUV2GRAY_YUYV = TL_CV_YUV2GRAY_YUY2 |
| YUV_YUNV | TL_CV_YUV2GRAY_YUNV = TL_CV_YUV2GRAY_YUY2 |
2.输出参数:
| 输出参数 | 必选 | 类型 | 描述 |
|---|---|---|---|
| outputImgData | 是 | unsigned char[] | 缩放后图像内容,图像类型与输入的相同 1.输出NULL:则说明未翻页 2.输出不为NULL则表示翻页,且ocrFlag==1时输出图尺寸640x480,ocrFlag为0时输出图尺寸320x240 |
注意:输入需要为640×480的YUV420类型图片,为了节省内存,输出的指针复用了输入的image的内存,勿提早释放输入参数iamge的内存,若ocrFlag==0,取数组的前半部分即是输出。
3.调用方法:
// 先初始化
initMotionDetection(MotionDetection *md,int min_thr,int max_thr,int minThrWaitTime,int dstHeight,int cropRate,int serverWaitTime, int timer,long long nowTime);
// 再调用翻页检测 getMotionResult(MotionDetection md, const unsigned char image, int width, int height, int channels, TL_IMAGE_TYPE imageType, long long nowTime,int ocrFlag, int fingerFlag);
4.文件说明:
| 文件名 | 描述说明 |
|---|---|
| tl_imgproc.c | 图像处理相关算法 |
| tl_imgproc.h | 图像处理-图结构 |
| motion_detect_c.c | 翻页检测核心代码 |
| motion_detect_c.h | 翻页检测头文件 |
5.调用示例:
//初始化翻页的结构体 注意,如果翻页检测在一直调用,该结构信息需要一直保留着
MotionDetection md;
int min_thr = 30;
int max_thr= 100;
int minThrWaitTime = 100;
int dstHeight = 100;
int cropRate = 33;
int serverWaitTime = 0; // 说明:如果是1000ms内只能向服务器发送一次
int timer = 100;// 单位毫秒
long long nowTime = 12312312312;// 毫秒级的时间戳
initMotionDetection(&md,min_thr,max_thr,minThrWaitTime,dstHeight,cropRate,serverWaitTime,timer, nowTime);
// 将MotionDetection 和图片的相关信息传入
// 教材指读(ocr模式开启、指读模式开启)
unsigned char * outImg = getMotionResult(md, yuvData, width, height, channel, TL_CV_YUV2GRAY_UYVY,nowTime,1,1);
// 指读(ocr模式关闭、指读模式开启)
unsigned char * outImg = getMotionResult(md, yuvData, width, height, channel, TL_CV_YUV2GRAY_UYVY,nowTime,0,1);
// 教材(ocr模式开启、指读模式关闭)
unsigned char * outImg = getMotionResult(md, yuvData, width, height, channel, TL_CV_YUV2GRAY_UYVY,nowTime,1,0);
// 普通绘本(ocr模式关闭、指读模式关闭)
unsigned char * outImg = getMotionResult(md, yuvData, width, height, channel, TL_CV_YUV2GRAY_UYVY,nowTime,0,0);
//判断是否翻页
if(outImg != NULL) 表示翻页且返回缩放后的图数据
if(outImg == NULL) 表示未翻页
// 程序结束时释放资源 注意
cvFreeImageTL(md.frame1);