Atitit 项目wechat微信截屏生成vcf通讯录384 个 384个人 42个节拍,平均每个8个人 技术点 im图像裁剪, ocr Tesseract Vcf格式 /wechatTel
Atitit 项目wechat微信截屏生成vcf通讯录384 个
384个人 42个节拍,平均每个8个人
技术点
im图像裁剪, ocr Tesseract
Vcf格式
/wechatTelbookOcrVcf/src/aaa/wechatTelbookOcrVcfMainCls.java
package aaa;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.List;
import java.util.Map;
import javax.imageio.ImageIO;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.log4j.Logger;
import com.alibaba.fastjson.JSON;
import com.attilax.io.FilenameUtilsT55;
import com.attilax.ocr.OcrXV2t55;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import ezvcard.Ezvcard;
import ezvcard.VCard;
import ezvcard.VCardVersion;
import ezvcard.parameter.TelephoneType;
import net.coobird.thumbnailator.Thumbnails;
public class wechatTelbookOcrVcfMainCls {
static List vcfList = Lists.newArrayList();
static org.apache.log4j.Logger logger = Logger.getLogger(OcrXV2t55.class);
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// 输入图片地址 yaobuyao tif ,,sh yyo d effect ..n test by myself...paa
String dir = "D:\\addbook";
String orcMaindir_tesseractDir = "D:\\0workspace\\Tesseract";
File[] fs = new File(dir).listFiles();
int now = 0;int forIdx_cutImg = 0;
for (File f : fs) {
if(f.isDirectory())continue;
logger.info(f);
now++;
String ext =FilenameUtils.getExtension(f.getAbsolutePath());
if(ext.equals("txt"))
continue;
if( f.getAbsolutePath().endsWith("cut.png") )
continue;
forIdx_cutImg++;
String srcimg = "D:\\bawei\\Screenshot_2019-05-09-18-57-58-500_com.tencent.mm.png";
srcimg=f.getAbsolutePath();
Rectangle rect = new Rectangle(282, 258, 430, 36);
// ocr rzt
String valCode = new OcrXV2t55().getTxtWithCache(orcMaindir_tesseractDir, f.getAbsolutePath());
System.out.println("txt:" + valCode);
//
String ocrRztfile=getOcrRztfile(f);
List<String> list=FileUtils.readLines(new File(ocrRztfile),"utf8");
for (String line : list) {
processLine(line);
}
Map traceM = logtracForItem(now, forIdx_cutImg, f, valCode);
}
String s = Joiner.on("\r\n").join(vcfList);
FileUtils.write(new File("D:\\00000\\bawei_alltel_t66_384gren.vcf"), s, "utf8");
System.out.println(s);
System.out.println("--");
}
private static String getOcrRztfile(File f) {
String path=f.getParent();
String mainname=FilenameUtils.getBaseName(f.getAbsolutePath());
return path+"\\"+mainname+".txt";
}
private static void processLine(String line) {
line=line.trim();
line=line.replaceAll(" ", "");
if(line.length()<10)
return;
String tel = RegexUtil.getTel(line);
if(tel.trim().length()<5)
return;
VCard vcard = new VCard();
vcard.setFormattedName( "t6"+line );
vcard.addTelephoneNumber(tel, TelephoneType.CELL);
// vcard.addNickname( new Nickname().set csvReader.get(1));
String str = Ezvcard.write(vcard).version(VCardVersion.V3_0).go();
vcfList.add(str);
}
private static Map logtracForItem(int now, int forIdx_cutImg, File f, String valCode) {
Map traceM=Maps.newLinkedHashMap();
traceM.put("f", f);
traceM.put("forIndex", now);
traceM.put("txt", valCode);
traceM.put("forIdx_cutImg", forIdx_cutImg);
logger.info(JSON.toJSONString(traceM,true));
return traceM;
}
}