基本信息
源码名称:c++ 将文本转换成图片(txt2img)
源码大小:1.03M
文件格式:.rar
开发语言:C/C++
更新时间:2019-03-10
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍


//txt2img <img_path> <text> <width> <height> <x> <y> <R> <G> <B>

#include <cv.h>
#include <cxcore.h>
#include <highgui.h>

#include <stdlib.h>
#include <stdio.h>

#include <fstream>
#include <string>
#include <iostream>
using namespace std;

int main(int argc,char *argv[])
{
    IplImage *src=NULL;
    char *text;
    int width,height;
    int R,G,B;
    int x,y;
    if(argc==10 )
    {
        text=argv[2];
        width=atoi(argv[3]);
        height=atoi(argv[4]);
        x=atoi(argv[5]);
        y=atoi(argv[6]);
        R=atoi(argv[7]);
        G=atoi(argv[8]);
        B=atoi(argv[9]);

        src=cvCreateImage(cvSize(width,height),IPL_DEPTH_8U,3);
        if(!src)
        {
            printf("Can not create the image.\n");
            return -1;
        }
        cvZero(src);

        cvNamedWindow("src",1);

        CvFont font;
        cvInitFont(&font,CV_FONT_HERSHEY_SIMPLEX,1.0,1.0,0,1,8);
        cvPutText(src,text,cvPoint(x,y),&font,CV_RGB(R,G,B));

        cvShowImage("src",src);
        cvWaitKey(5000);
        cvSaveImage(argv[1],src);
        cvDestroyWindow("src");
        cvReleaseImage(&src);
        return 0;
    }

    CvFont font;
    cvInitFont(&font,CV_FONT_HERSHEY_SIMPLEX,1.0,1.0,0,1,8);

    ifstream setting("Setting.txt");
    string buf1;
    getline(setting,buf1);
    width=atoi(buf1.c_str());
    getline(setting,buf1);
    height=atoi(buf1.c_str());
    getline(setting,buf1);
    x=atoi(buf1.c_str());
    getline(setting,buf1);
    y=atoi(buf1.c_str());
    getline(setting,buf1);
    R=atoi(buf1.c_str());
    getline(setting,buf1);
    G=atoi(buf1.c_str());
    getline(setting,buf1);
    B=atoi(buf1.c_str());
    setting.close();

    ifstream text_list("textlist.txt");
    string buf;
    while(text_list)
    {
        if(getline(text_list,buf))
        {
            string save_dir="result/";
			string filename;
			filename.append(buf.c_str());
			filename.append(".jpg");
            src=cvCreateImage(cvSize(width,height),IPL_DEPTH_8U,3);
            if(!src) break;
            cvZero(src);
            cvPutText(src,buf.c_str(),cvPoint(x,y),&font,CV_RGB(R,G,B));
            cout<<"processing..."<<endl;
            cvSaveImage(save_dir.append(filename.c_str()).c_str(),src);
			cvReleaseImage(&src);
        }
    }
    cout<<"done..."<<endl;
    text_list.close();

    return 0;
}