文章目录
一、opencv的简单使用
1、文档准备
建立一个文件夹,将此次需要用到的文件装在同一文件夹下。
本次需要用到的文件如下,图片自行选取,logo.txt文件为将要与图片重叠的字,其它为字库文件。
字库文件提取链接:
https://pan.baidu.com/s/1wAWeAX9R0hzqSuBx_dxJjw
提取码:4455
2、相关代码
1、打开Ubuntu终端,进行文件夹并编辑代码。
cd optp/build
vim wz.cpp
代码如下:
#include<iostream>
#include<opencv/cv.h>
#include"opencv2/opencv.hpp"
#include<opencv/cxcore.h>
#include<opencv/highgui.h>
#include<math.h>
using namespace cv;
using namespace std;
void paint_chinese(Mat& image,int x_offset,int y_offset,unsigned long offset);
void paint_ascii(Mat& image,int x_offset,int y_offset,unsigned long offset);
void put_text_to_image(int x_offset,int y_offset,String image_path,char* logo_path);
int main(){
String image_path="star.jpeg";
char* logo_path=(char*)"logo.txt";
put_text_to_image(70,620,image_path,logo_path);//安排文字从图片像素坐标(70,
620)开始显示
return 0;
}
//在图片上绘制文字的起点坐标
void paint_ascii(Mat& image,int x_offset,int y_offset,unsigned long offset){
Point p;
p.x = x_offset;
p.y = y_offset;
//存放ascii字膜
char buff[16];
//打开ascii字库文件
FILE *ASCII;
if ((ASCII = fopen("Asci0816.zf", "rb")) == NULL){
printf("Can't open ascii.zf,Please check the path!");
//getch();
exit(0);