Ubuntu中图片与文字的叠加


一、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);
        
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值