上一次实验完成了Opencv的安装以及图像的简单处理,现在在此基础上完成添加中文字的任务。
一、在字库文件中找到自己的名字
新建一个txt文本文件,写上名字学号,另存为,编码格式选择acsi。如何获得中文的的点阵位置呢,这里我们需要一个强大的工具,UltraEdit。使用UD打开之前创建的txt文件:
打开点阵汉字查看程序,打开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] =