树莓派+Opencv(二)中文字库

上一次实验完成了Opencv的安装以及图像的简单处理,现在在此基础上完成添加中文字的任务。

一、在字库文件中找到自己的名字

新建一个txt文本文件,写上名字学号,另存为,编码格式选择acsi。如何获得中文的的点阵位置呢,这里我们需要一个强大的工具,UltraEdit。使用UD打开之前创建的txt文件:
其中E1D4就是点阵位置
打开点阵汉字查看程序,打开HZKf2424字库文件,在工具栏选择望远镜图标,也就是搜索图标,搜索E1D4:
在这里插入图片描述
在这里插入图片描述
点击ok后出现的第一个字就是要搜索的字:
在这里插入图片描述

#include <stdio.h>
#include <stdlib.h>
#include <cxcore.h>
#include <highgui.h>
#include <direct.h>
#include<iostream>
using namespace std;
using namespace cv;

const int CC_SIZE = 16;
const int SAFE_WIDTH = 10;
const int CC_NUMBER = 15;
//姓名
unsigned char name[7] = "嵩";
unsigned int name_code[3][2];

// 学号
unsigned int id_code[12][2] = {
    {
    0xa3, 0xb6 },{
    0xa3, 0xb3 },{
    0xa3, 0xb1 },{
    0xa3, 0xb6 },{
    0xa3, 0xb0 },{
    0xa3, 0xb7 },{
    0xa3, 0xb0 },{
    0xa3, 0xb4 },{
    0xa3, 0xb0 },{
    0xa3, 0xb3 },{
    0xa3, 0xb2 },{
    0xa3, 0xb5 } };

unsigned char mat[16][2];

FILE* HZK16;
IplImage* img;

void get_area_position_codes();

void get_mat(int a_code, int p_code);

void open_file();

void draw_one_cc(int num);

void release();


int main()
{
   
	open_file();
	get_area_position_codes();
	int i, j;
	for (i = 0; i < 3; ++i)
	{
   
		get_mat(name_code[i][0], name_code[i][1]);
		draw_one_cc(i);
	}
	for (j = 0; j < 12; ++j)
	{
   
		get_mat(id_code[j][0] - 0xa0, id_code[j][1] - 0xa0);
		draw_one_cc(i + j);
	}
	cvShowImage("IMAGE", img);
	cvWaitKey(0);
	release();
	return 0;
}

void get_area_position_codes()
{
   
	for (int i = 0; i < 3; ++i)
		for (int j = 0; j < 2; ++j)
			name_code[i][j] =
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值