資源簡介
C# 調用OneNote進行批量文字識別,源碼
功能:把input中的圖片批量識別,輸出到output。
所用環境:VS2010 C#
office套件中的OneNote2013
說明:bin/Debug/temPath中有個noenote文件,可以打開看。
運行的時候:
1、會把圖片加載到這個文件中
2、然后識別
3、然后刪除
然后加載下一張圖片。。。。
這個過程你可以打開OneNote看得到
有時候會抽風,就是識別幾張圖之后,
有個圖一直識別不到,
我也不知道為什么,也不確定是不是一定會,
反正我這里有時會“發愣”,
估計是因為程序里面沒有強制觸發其運行識別,導致識別失敗,(我不知道怎么強制觸發其識別,只得看它心情)
這種情況只要在OneNote中對著那個圖片:右鍵-->復制圖片中的文字,就會觸發它識別,
它一識別,程序也就獲得數據了,
程序就會繼續下去。。。
代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Text;
using?System.xml.Linq;
using?System.xml;
using?System.IO;
using?System.Configuration;
using?System.Drawing;
using?System.Drawing.Imaging;
using?System.Runtime.InteropServices;
using?Microsoft.Office.Interop.OneNote;
namespace?OneNote
{
?????public?class?OrcImage
?????{
?????????string?tmpPath?=?AppDomain.CurrentDomain.baseDirectory?+?@“tmpPath\“;
?
?????????private?Tuple?Getbase64(string?strImgPath)
?????????{
?????????????return?Getbase64(new?FileInfo(strImgPath));
?????????}
?
?????????///?
?????????///?獲取圖片的base64編碼
?????????///?
?????????///?
?????????///?
?????????private?Tuple?Getbase64(FileInfo?file)
?????????{
?????????????using?(MemoryStream?ms?=?new?MemoryStream())
?????????????{
?????????????????Bitmap?bp?=?new?Bitmap(file.FullName);
?????????????????switch?(file.Extension.ToLower())
?????????????????{
?????????????????????case?“.jpg“:
?????????????????????????bp.Save(ms?ImageFormat.Jpeg);
?????????????????????????break;
?
?????????????????????case?“.jpeg“:
?????????????????????????bp.Save(ms?ImageFormat.Jpeg);
?????????????????????????break;
?
?????????????????????case?“.gif“:
?????????????????????????bp.Save(ms?ImageFormat.Gif);
?????????????????????????break;
?
?????????????????????case?“.bmp“:
?????????????????????????bp.Save(ms?ImageFormat.Bmp);
?????????????????????????break;
?
?????????????????????case?“.tiff“:
?????????????????????????bp.Save(ms?ImageFormat.Tiff);
?????????????????????????break;
?
?????????????????????case?“.png“:
?????????????????????????bp.Save(ms?ImageFormat.Png);
?????????????????????????break;
?
?????????????????????case?“.emf“:
?????????????????????????bp.Save(ms?ImageFormat.Emf);
?????????????????????????break;
?
?????????????????????default:
?????????????????????????return?new?Tuple(“不支持的圖片格式。“?0?0);
?????????????????}
?????????????????byte[]?buffer?=?ms.GetBuffer();
?????????????????return?new?Tuple(Convert.Tobase64String(buffer)?bp.Width?bp.Height);
?????????????}
?????????}
?
?????????public?string?Orc_Img(FileInfo?fi)
?????????{
?????????????//?向Onenote2013中插入圖片
?????????????var?onenoteApp?=?new?Microsoft.Office.Interop.OneNote.Application();??//onenote提供的API
?????????????///***************************************************************************************/
?????????????string?sectionID;
?????????????
?????????????onenoteApp.OpenHierarchy(tmpPath?+?“newfile.one“?null?out?sectionID?CreateFileType.cftSection);
?????????????string?pageID?=?“{A975EE72-19C3-4C80-9C0E-EDA576DAB5C6}{1}{B0}“;??//?格式?{guid}{tab}{??}
?????????????onenoteApp.CreateNewPage(sectionID?out?pageID?NewPagestyle.npsBlankPageNotitle);
?????????????/******************************************************************
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????727067??2016-06-11?15:32??批量OCR(C#+onenote2013)\input\0001.jpg
?????文件?????756583??2016-06-11?15:32??批量OCR(C#+onenote2013)\input\0002.jpg
?????文件?????679654??2016-06-11?15:32??批量OCR(C#+onenote2013)\input\0003.jpg
?????文件?????524180??2016-06-11?15:32??批量OCR(C#+onenote2013)\input\0004.jpg
?????文件?????816296??2016-06-11?15:32??批量OCR(C#+onenote2013)\input\0005.jpg
?????文件????1013566??2016-06-11?15:32??批量OCR(C#+onenote2013)\input\0006.jpg
?????文件?????798018??2016-06-11?15:32??批量OCR(C#+onenote2013)\input\0007.jpg
?????文件?????683272??2016-06-11?15:32??批量OCR(C#+onenote2013)\input\0008.jpg
?????文件?????746072??2016-06-11?15:32??批量OCR(C#+onenote2013)\input\0009.jpg
?????文件?????716906??2016-06-11?15:32??批量OCR(C#+onenote2013)\input\0010.jpg
?????文件?????719727??2016-06-11?15:32??批量OCR(C#+onenote2013)\input\0011.jpg
?????文件??????13312??2016-11-26?17:44??批量OCR(C#+onenote2013)\OneNote\OneNote\bin\Debug\OneNote.exe
?????文件??????17920??2016-11-26?17:44??批量OCR(C#+onenote2013)\OneNote\OneNote\bin\Debug\OneNote.pdb
?????文件??????11600??2016-11-26?21:08??批量OCR(C#+onenote2013)\OneNote\OneNote\bin\Debug\OneNote.vshost.exe
?????文件????????490??2010-03-17?22:39??批量OCR(C#+onenote2013)\OneNote\OneNote\bin\Debug\OneNote.vshost.exe.manifest
?????文件???44551640??2016-11-26?20:44??批量OCR(C#+onenote2013)\OneNote\OneNote\bin\Debug\tmpPath\newfile.one
?????文件???????6446??2016-11-26?17:44??批量OCR(C#+onenote2013)\OneNote\OneNote\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件??????23552??2016-11-20?21:08??批量OCR(C#+onenote2013)\OneNote\OneNote\obj\x86\Debug\Interop.Microsoft.Office.Interop.OneNote.dll
?????文件???????1014??2016-11-26?21:08??批量OCR(C#+onenote2013)\OneNote\OneNote\obj\x86\Debug\OneNote.csproj.FileListAbsolute.txt
?????文件????????896??2016-11-21?21:18??批量OCR(C#+onenote2013)\OneNote\OneNote\obj\x86\Debug\OneNote.csproj.ResolveComReference.cache
?????文件??????13312??2016-11-26?17:44??批量OCR(C#+onenote2013)\OneNote\OneNote\obj\x86\Debug\OneNote.exe
?????文件??????17920??2016-11-26?17:44??批量OCR(C#+onenote2013)\OneNote\OneNote\obj\x86\Debug\OneNote.pdb
?????文件???????3732??2016-11-20?21:13??批量OCR(C#+onenote2013)\OneNote\OneNote\OneNote.csproj
?????文件???????8769??2016-11-26?17:44??批量OCR(C#+onenote2013)\OneNote\OneNote\Program.cs
?????文件???????1364??2016-11-19?22:20??批量OCR(C#+onenote2013)\OneNote\OneNote\Properties\AssemblyInfo.cs
?????文件????????863??2016-11-19?22:20??批量OCR(C#+onenote2013)\OneNote\OneNote.sln
????..A..H.?????18944??2016-11-26?21:13??批量OCR(C#+onenote2013)\OneNote\OneNote.suo
?????文件????????407??2016-11-26?18:42??批量OCR(C#+onenote2013)\output\0001.txt
?????文件????????229??2016-11-26?18:42??批量OCR(C#+onenote2013)\output\0002.txt
?????文件????????451??2016-11-26?18:43??批量OCR(C#+onenote2013)\output\0003.txt
............此處省略467個文件信息
- 上一篇:QQ高仿版 GG2014
- 下一篇:鮮花店管理系統asp
評論
共有 條評論