Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
张东亮
/
NS100
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 76c15bc5
由
贾鹏旭
编写于
2023-09-19 15:44:36 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
1.数据源匹配不到数据问题
2.开启软件,自动请求http问题 3.ocr识别结束,行合并逻辑(新方法) 4.
1 个父辈
6fd78454
显示空白字符变更
内嵌
并排
正在显示
19 个修改的文件
包含
299 行增加
和
33 行删除
BLL/BLL.csproj
BLL/Extension/Item_General.cs
BLL/PaddleOCRHelper.cs
BLL/Replacekeywords.cs
BLL/ServerCommunication.cs
ExtensionGroup/Alcoelectro.cs
ExtensionGroup/Inventec.cs
ExtensionGroup/KaiFa.cs
ExtensionGroup/PanaCIM.cs
Model/Model.csproj
Model/StringIntPair.cs
SmartScan/Form/FrmMain.Designer.cs
SmartScan/Program.cs
SmartScan/SetControl/UsrMaterialTemplate.cs
paddleOCR/PaddleHelper.cs
paddleOCR/PaddleSharpAPI.cs
paddleOCR/paddleOCR.csproj
paddleOCR/service/IService.cs
paddleOCR/service/Service.cs
BLL/BLL.csproj
查看文件 @
76c15bc
...
@@ -59,6 +59,13 @@
...
@@ -59,6 +59,13 @@
<Reference Include="log4net, Version=2.0.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<Reference Include="log4net, Version=2.0.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.12\lib\net45\log4net.dll</HintPath>
<HintPath>..\packages\log4net.2.0.12\lib\net45\log4net.dll</HintPath>
</Reference>
</Reference>
<Reference Include="MvCameraControl.Net, Version=3.2.0.2, Culture=neutral, PublicKeyToken=52fddfb3f94be800, processorArchitecture=AMD64">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\IDHIKCamera\bin\Debug\MvCameraControl.Net.dll</HintPath>
</Reference>
<Reference Include="MvCodeReaderSDK.Net">
<HintPath>..\..\..\..\IDHIKCamera\bin\Debug\MvCodeReaderSDK.Net.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
</Reference>
...
...
BLL/Extension/Item_General.cs
查看文件 @
76c15bc
...
@@ -86,16 +86,7 @@ namespace BLL
...
@@ -86,16 +86,7 @@ namespace BLL
{
{
extensions
[
i
].
Control
.
ForeColor
=
Color
.
White
;
extensions
[
i
].
Control
.
ForeColor
=
Color
.
White
;
if
(
key
.
ContainsKey
(
extensions
[
i
].
Key
))
if
(
key
.
ContainsKey
(
extensions
[
i
].
Key
))
extensions
[
i
].
Control
.
Text
=
key
[
extensions
[
i
].
Key
].
Replace
(
"<OCR>"
,
""
);
/*.Replace("<OCR>","")*/
;
extensions
[
i
].
Control
.
Text
=
key
[
extensions
[
i
].
Key
].
Replace
(
"<OCR>"
,
""
);
//if (key.ContainsKey(extensions[i].Key))
//{
// if (key[extensions[i].Key].StartsWith("<OCR>"))
// {
// extensions[i].Control.BackColor = Color.Yellow;
// }
// extensions[i].Control.Text = key[extensions[i].Key].Replace("<OCR>", "");
//}
}
}
}
}
Application
.
DoEvents
();
Application
.
DoEvents
();
...
@@ -120,29 +111,22 @@ namespace BLL
...
@@ -120,29 +111,22 @@ namespace BLL
}
}
if
(
extensions
!=
null
&&
!
extensions
[
0
].
Control
.
InvokeRequired
)
if
(
extensions
!=
null
&&
!
extensions
[
0
].
Control
.
InvokeRequired
)
{
{
if
(
key
.
ContainsKey
(
Config
.
DataSource_DataKey
)
&&
ExtraFileData
.
AllData
.
ContainsKey
(
key
[
Config
.
DataSource_DataKey
]))
//使用key填充时,请处理字段开头的<OCR>字段
string
CleanData
=
key
[
Config
.
DataSource_DataKey
].
Replace
(
"<OCR>"
,
""
);
if
(
key
.
ContainsKey
(
Config
.
DataSource_DataKey
)
&&
ExtraFileData
.
AllData
.
ContainsKey
(
CleanData
))
{
{
var
extraData
=
ExtraFileData
.
AllData
[
key
[
Config
.
DataSource_DataKey
]
];
var
extraData
=
ExtraFileData
.
AllData
[
CleanData
];
foreach
(
var
d
in
extraData
)
foreach
(
var
d
in
extraData
)
{
{
key
[
d
.
Key
]
=
d
.
Value
;
key
[
d
.
Key
]
=
d
.
Value
;
}
}
}
}
//第二次刷新界面
//第二次刷新界面
for
(
int
i
=
0
;
i
<
extensions
.
Count
;
i
++)
for
(
int
i
=
0
;
i
<
extensions
.
Count
;
i
++)
{
{
extensions
[
i
].
Control
.
ForeColor
=
Color
.
White
;
extensions
[
i
].
Control
.
ForeColor
=
Color
.
White
;
if
(
key
.
ContainsKey
(
extensions
[
i
].
Key
))
if
(
key
.
ContainsKey
(
extensions
[
i
].
Key
))
extensions
[
i
].
Control
.
Text
=
key
[
extensions
[
i
].
Key
].
Replace
(
"<OCR>"
,
""
);
/*.Replace("<OCR>", "");*/
extensions
[
i
].
Control
.
Text
=
key
[
extensions
[
i
].
Key
].
Replace
(
"<OCR>"
,
""
);
//if (key.ContainsKey(extensions[i].Key))
//{
// if (key[extensions[i].Key].StartsWith("<OCR>"))
// {
// extensions[i].Control.BackColor = Color.Yellow;
// }
// extensions[i].Control.Text = key[extensions[i].Key].Replace("<OCR>", ""); ;
//}
}
}
}
}
if
(!
updatereelid
(
key
,
out
errmsg
))
if
(!
updatereelid
(
key
,
out
errmsg
))
...
...
BLL/PaddleOCRHelper.cs
查看文件 @
76c15bc
...
@@ -17,7 +17,8 @@ namespace BLL
...
@@ -17,7 +17,8 @@ namespace BLL
{
{
public
class
PaddleOCRHelper
public
class
PaddleOCRHelper
{
{
static
string
baseUrl
=
ConfigHelper
.
Config
.
Get
(
"PaddleServiceBase"
,
"http://localhost:8090/paddle/getOcr"
);
//static string baseUrl = ConfigHelper.Config.Get("PaddleServiceBase", "http://localhost:8090/paddle/getOcr");
static
string
baseUrl
=
ConfigHelper
.
Config
.
Get
(
"paddleOcr_HttpPath"
,
"http://localhost:8090/paddle/getOcr"
);
/// <summary>
/// <summary>
/// 开始检测
/// 开始检测
/// </summary>
/// </summary>
...
...
BLL/Replacekeywords.cs
查看文件 @
76c15bc
...
@@ -144,13 +144,11 @@ namespace BLL
...
@@ -144,13 +144,11 @@ namespace BLL
/// </summary>
/// </summary>
public
Dictionary
<
string
,
string
>
filteredData
{
get
;
set
;
}
public
Dictionary
<
string
,
string
>
filteredData
{
get
;
set
;
}
}
}
public
class
ResponseItem
public
class
ResponseItem
{
{
public
string
Name
{
get
;
set
;
}
public
string
Name
{
get
;
set
;
}
public
string
Value
{
get
;
set
;
}
public
string
Value
{
get
;
set
;
}
}
}
public
class
ResponseDatas
public
class
ResponseDatas
{
{
public
List
<
List
<
ResponseItem
>>
Items
{
get
;
set
;
}
public
List
<
List
<
ResponseItem
>>
Items
{
get
;
set
;
}
...
...
BLL/ServerCommunication.cs
查看文件 @
76c15bc
...
@@ -28,12 +28,12 @@ namespace BLL
...
@@ -28,12 +28,12 @@ namespace BLL
object
serverclock
=
new
object
();
object
serverclock
=
new
object
();
public
ServerCommunication
()
public
ServerCommunication
()
{
{
readLazyData
();
server
=
BLLCommon
.
config
.
SmfServer
;
server
=
BLLCommon
.
config
.
SmfServer
;
CID
=
BLLCommon
.
config
.
CID
;
CID
=
BLLCommon
.
config
.
CID
;
//Common.config.Save();
//Common.config.Save();
if
(
server
.
ToLower
().
StartsWith
(
"http"
))
if
(
server
.
ToLower
().
StartsWith
(
"http"
))
{
{
readLazyData
();
serverConnectTimer
.
Interval
=
1000
;
serverConnectTimer
.
Interval
=
1000
;
serverConnectTimer
.
AutoReset
=
true
;
serverConnectTimer
.
AutoReset
=
true
;
serverConnectTimer
.
Enabled
=
true
;
serverConnectTimer
.
Enabled
=
true
;
...
@@ -165,6 +165,8 @@ namespace BLL
...
@@ -165,6 +165,8 @@ namespace BLL
showMsglist
.
Enqueue
(
m
);
showMsglist
.
Enqueue
(
m
);
}
}
public
void
SendData
(
object
data
)
{
public
void
SendData
(
object
data
)
{
if
(!
server
.
ToLower
().
StartsWith
(
"http"
))
return
;
var
m
=
new
EquipMsg
();
var
m
=
new
EquipMsg
();
m
.
module
=
"NEOSCAN"
;
m
.
module
=
"NEOSCAN"
;
m
.
type
=
msgType
.
DATA
;
m
.
type
=
msgType
.
DATA
;
...
...
ExtensionGroup/Alcoelectro.cs
查看文件 @
76c15bc
...
@@ -395,5 +395,10 @@ namespace ExtensionGroup
...
@@ -395,5 +395,10 @@ namespace ExtensionGroup
{
{
throw
new
NotImplementedException
();
throw
new
NotImplementedException
();
}
}
public
void
Print
(
bool
match
,
Dictionary
<
string
,
string
>
key
)
{
throw
new
NotImplementedException
();
}
}
}
}
}
ExtensionGroup/Inventec.cs
查看文件 @
76c15bc
...
@@ -21,7 +21,7 @@ namespace ExtensionGroup
...
@@ -21,7 +21,7 @@ namespace ExtensionGroup
private
string
reelIDKey
=
""
;
private
string
reelIDKey
=
""
;
private
bool
needPrint
=
false
;
private
bool
needPrint
=
false
;
public
event
IExtension
.
PrintDelegate
Printing
;
public
event
IExtension
.
PrintDelegate
Printing
;
public
event
IExtension
.
PrintDelegate
SaveRetrospect
;
public
Inventec
()
public
Inventec
()
{
{
...
@@ -373,7 +373,19 @@ namespace ExtensionGroup
...
@@ -373,7 +373,19 @@ namespace ExtensionGroup
}
}
public
bool
SetKey
(
string
[]
originalCode
,
Dictionary
<
string
,
string
>
key
,
bool
hasMatch
,
out
string
errmsg
)
{
throw
new
NotImplementedException
();
}
public
void
Print
(
bool
match
,
Dictionary
<
string
,
string
>
key
)
{
throw
new
NotImplementedException
();
}
public
void
DrawTextBackground
(
Dictionary
<
string
,
string
>
key
)
{
throw
new
NotImplementedException
();
}
}
}
}
}
ExtensionGroup/KaiFa.cs
查看文件 @
76c15bc
...
@@ -16,6 +16,7 @@ namespace ExtensionGroup
...
@@ -16,6 +16,7 @@ namespace ExtensionGroup
private
int
reelID
=
0
;
private
int
reelID
=
0
;
private
List
<
ExtensionControl
>
extensions
;
private
List
<
ExtensionControl
>
extensions
;
public
event
IExtension
.
PrintDelegate
Printing
;
public
event
IExtension
.
PrintDelegate
Printing
;
public
event
IExtension
.
PrintDelegate
SaveRetrospect
;
public
KaiFa
()
{
}
public
KaiFa
()
{
}
...
@@ -129,5 +130,19 @@ namespace ExtensionGroup
...
@@ -129,5 +130,19 @@ namespace ExtensionGroup
Printing
?.
Invoke
(
key
);
Printing
?.
Invoke
(
key
);
}
}
public
bool
SetKey
(
string
[]
originalCode
,
Dictionary
<
string
,
string
>
key
,
bool
hasMatch
,
out
string
errmsg
)
{
throw
new
NotImplementedException
();
}
public
void
Print
(
bool
match
,
Dictionary
<
string
,
string
>
key
)
{
throw
new
NotImplementedException
();
}
public
void
DrawTextBackground
(
Dictionary
<
string
,
string
>
key
)
{
throw
new
NotImplementedException
();
}
}
}
}
}
ExtensionGroup/PanaCIM.cs
查看文件 @
76c15bc
...
@@ -19,6 +19,7 @@ namespace ExtensionGroup
...
@@ -19,6 +19,7 @@ namespace ExtensionGroup
private
ServerContent
[]
serverContent
;
private
ServerContent
[]
serverContent
;
private
string
reelIDKey
=
""
;
private
string
reelIDKey
=
""
;
public
event
IExtension
.
PrintDelegate
Printing
;
public
event
IExtension
.
PrintDelegate
Printing
;
public
event
IExtension
.
PrintDelegate
SaveRetrospect
;
public
PanaCIM
()
public
PanaCIM
()
{
{
...
@@ -359,6 +360,20 @@ namespace ExtensionGroup
...
@@ -359,6 +360,20 @@ namespace ExtensionGroup
new
FaceMessageBox
(
""
,
Language
.
Dialog
(
LanguageDialogKey
.
SAVE_SUCCEED
),
System
.
Windows
.
Forms
.
MessageBoxButtons
.
OK
).
ShowDialog
();
new
FaceMessageBox
(
""
,
Language
.
Dialog
(
LanguageDialogKey
.
SAVE_SUCCEED
),
System
.
Windows
.
Forms
.
MessageBoxButtons
.
OK
).
ShowDialog
();
}
}
public
bool
SetKey
(
string
[]
originalCode
,
Dictionary
<
string
,
string
>
key
,
bool
hasMatch
,
out
string
errmsg
)
{
throw
new
NotImplementedException
();
}
public
void
Print
(
bool
match
,
Dictionary
<
string
,
string
>
key
)
{
throw
new
NotImplementedException
();
}
public
void
DrawTextBackground
(
Dictionary
<
string
,
string
>
key
)
{
throw
new
NotImplementedException
();
}
}
}
}
}
Model/Model.csproj
查看文件 @
76c15bc
...
@@ -101,6 +101,7 @@
...
@@ -101,6 +101,7 @@
<Compile Include="PrintLabelTemplate.cs" />
<Compile Include="PrintLabelTemplate.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SizeConversion.cs" />
<Compile Include="SizeConversion.cs" />
<Compile Include="StringIntPair.cs" />
<Compile Include="TemplateState.cs" />
<Compile Include="TemplateState.cs" />
<Compile Include="UserLevel.cs" />
<Compile Include="UserLevel.cs" />
</ItemGroup>
</ItemGroup>
...
...
Model/StringIntPair.cs
0 → 100644
查看文件 @
76c15bc
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
Model
{
/// <summary>
/// ocr矩阵合并
/// </summary>
public
class
StringIntPair
{
public
string
StringValue
{
get
;
set
;
}
public
int
IntValue
{
get
;
set
;
}
public
StringIntPair
(
string
StringValue
,
int
IntValue
)
{
this
.
StringValue
=
StringValue
;
this
.
IntValue
=
IntValue
;
}
}
}
SmartScan/Form/FrmMain.Designer.cs
查看文件 @
76c15bc
...
@@ -260,12 +260,12 @@ namespace SmartScan
...
@@ -260,12 +260,12 @@ namespace SmartScan
//
//
this
.
AutoScaleMode
=
System
.
Windows
.
Forms
.
AutoScaleMode
.
None
;
this
.
AutoScaleMode
=
System
.
Windows
.
Forms
.
AutoScaleMode
.
None
;
this
.
ClientSize
=
new
System
.
Drawing
.
Size
(
1096
,
815
);
this
.
ClientSize
=
new
System
.
Drawing
.
Size
(
1096
,
815
);
this
.
Controls
.
Add
(
this
.
PicShow
);
this
.
Controls
.
Add
(
this
.
LblUserName
);
this
.
Controls
.
Add
(
this
.
LblUserName
);
this
.
Controls
.
Add
(
this
.
LblVersion
);
this
.
Controls
.
Add
(
this
.
LblVersion
);
this
.
Controls
.
Add
(
this
.
BtnMatchedName
);
this
.
Controls
.
Add
(
this
.
BtnMatchedName
);
this
.
Controls
.
Add
(
this
.
CboLanguage
);
this
.
Controls
.
Add
(
this
.
CboLanguage
);
this
.
Controls
.
Add
(
this
.
PnlExtension
);
this
.
Controls
.
Add
(
this
.
PnlExtension
);
this
.
Controls
.
Add
(
this
.
PicShow
);
this
.
Controls
.
Add
(
this
.
LblIOExist
);
this
.
Controls
.
Add
(
this
.
LblIOExist
);
this
.
Controls
.
Add
(
this
.
LblCameraExist
);
this
.
Controls
.
Add
(
this
.
LblCameraExist
);
this
.
Controls
.
Add
(
this
.
BtnTriggerIO
);
this
.
Controls
.
Add
(
this
.
BtnTriggerIO
);
...
@@ -288,12 +288,12 @@ namespace SmartScan
...
@@ -288,12 +288,12 @@ namespace SmartScan
this
.
Controls
.
SetChildIndex
(
this
.
BtnTriggerIO
,
0
);
this
.
Controls
.
SetChildIndex
(
this
.
BtnTriggerIO
,
0
);
this
.
Controls
.
SetChildIndex
(
this
.
LblCameraExist
,
0
);
this
.
Controls
.
SetChildIndex
(
this
.
LblCameraExist
,
0
);
this
.
Controls
.
SetChildIndex
(
this
.
LblIOExist
,
0
);
this
.
Controls
.
SetChildIndex
(
this
.
LblIOExist
,
0
);
this
.
Controls
.
SetChildIndex
(
this
.
PicShow
,
0
);
this
.
Controls
.
SetChildIndex
(
this
.
PnlExtension
,
0
);
this
.
Controls
.
SetChildIndex
(
this
.
PnlExtension
,
0
);
this
.
Controls
.
SetChildIndex
(
this
.
CboLanguage
,
0
);
this
.
Controls
.
SetChildIndex
(
this
.
CboLanguage
,
0
);
this
.
Controls
.
SetChildIndex
(
this
.
BtnMatchedName
,
0
);
this
.
Controls
.
SetChildIndex
(
this
.
BtnMatchedName
,
0
);
this
.
Controls
.
SetChildIndex
(
this
.
LblVersion
,
0
);
this
.
Controls
.
SetChildIndex
(
this
.
LblVersion
,
0
);
this
.
Controls
.
SetChildIndex
(
this
.
LblUserName
,
0
);
this
.
Controls
.
SetChildIndex
(
this
.
LblUserName
,
0
);
this
.
Controls
.
SetChildIndex
(
this
.
PicShow
,
0
);
this
.
ResumeLayout
(
false
);
this
.
ResumeLayout
(
false
);
}
}
...
...
SmartScan/Program.cs
查看文件 @
76c15bc
...
@@ -113,7 +113,6 @@ namespace SmartScan
...
@@ -113,7 +113,6 @@ namespace SmartScan
process
.
StartInfo
.
WorkingDirectory
=
".\\paddle"
;
process
.
StartInfo
.
WorkingDirectory
=
".\\paddle"
;
if
(
File
.
Exists
(
".\\paddle\\paddleOCR.exe"
))
if
(
File
.
Exists
(
".\\paddle\\paddleOCR.exe"
))
process
.
Start
();
process
.
Start
();
}
}
//else
//else
//{
//{
...
...
SmartScan/SetControl/UsrMaterialTemplate.cs
查看文件 @
76c15bc
...
@@ -308,7 +308,7 @@ namespace SmartScan
...
@@ -308,7 +308,7 @@ namespace SmartScan
MaterialCode
code
=
mateCopy
[
mateIndex
].
Code
[
codeIndex
];
MaterialCode
code
=
mateCopy
[
mateIndex
].
Code
[
codeIndex
];
List
<
MaterialCodeMatch
>
match
=
mateCopy
[
mateIndex
].
Match
.
FindAll
(
s
=>
s
.
CodeID
==
code
.
ID
);
List
<
MaterialCodeMatch
>
match
=
mateCopy
[
mateIndex
].
Match
.
FindAll
(
s
=>
s
.
CodeID
==
code
.
ID
);
FrmCodeExtract
frm
=
new
(
code
.
Text
,
code
.
ID
,
code
.
CodeType
,
match
);
FrmCodeExtract
frm
=
new
(
code
.
Text
.
Replace
(
" "
,
""
)
,
code
.
ID
,
code
.
CodeType
,
match
);
DialogResult
dr
=
frm
.
ShowDialog
();
DialogResult
dr
=
frm
.
ShowDialog
();
if
(
dr
==
DialogResult
.
OK
)
if
(
dr
==
DialogResult
.
OK
)
{
{
...
...
paddleOCR/PaddleHelper.cs
查看文件 @
76c15bc
...
@@ -44,6 +44,25 @@ namespace paddleOCR
...
@@ -44,6 +44,25 @@ namespace paddleOCR
}
}
return
result
;
return
result
;
}
}
[
HandleProcessCorruptedStateExceptions
]
public
static
string
StartCPlusOcrRewrite
(
string
imgPath
)
{
string
result
=
""
;
try
{
PaddleSharpAPI
.
OCRHandleRewrite
(
imgPath
,
out
result
);
}
catch
(
Exception
ex
)
{
VisionAPI
.
log
.
Error
(
"StartCPlusOcr err"
,
ex
);
}
finally
{
}
return
result
;
}
static
List
<
T
>
DeserializeJsonToList
<
T
>(
string
json
)
where
T
:
class
static
List
<
T
>
DeserializeJsonToList
<
T
>(
string
json
)
where
T
:
class
{
{
JsonSerializer
serializer
=
new
JsonSerializer
();
JsonSerializer
serializer
=
new
JsonSerializer
();
...
...
paddleOCR/PaddleSharpAPI.cs
查看文件 @
76c15bc
using
log4net
;
using
log4net
;
using
log4net.Util
;
using
log4net.Util
;
using
Model
;
using
PaddleOCRSharp
;
using
PaddleOCRSharp
;
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
...
@@ -277,5 +278,168 @@ namespace paddleOCR
...
@@ -277,5 +278,168 @@ namespace paddleOCR
return
true
;
return
true
;
}
}
}
}
public
static
bool
OCRHandleRewrite
(
string
imgPath
,
out
string
result
)
{
result
=
""
;
sw
.
Restart
();
if
(
string
.
IsNullOrEmpty
(
imgPath
))
{
return
false
;
}
if
(
Directory
.
Exists
(
baseDir
))
{
Directory
.
Delete
(
baseDir
,
true
);
}
Directory
.
CreateDirectory
(
baseDir
);
EyemImage
image
=
new
EyemImage
();
EyemImage
tpDstImg
=
new
EyemImage
();
int
flag
;
log
.
Info
(
$
"OCRHandleRewrite:OCRHandleRewrite:准备读取图像:{imgPath}"
);
flag
=
VisionAPI
.
eyemImageRead
(
imgPath
,
-
1
,
out
image
);
log
.
Info
(
$
"OCRHandleRewrite:读取图像:{imgPath},rtnCode={flag}"
);
///实例分割
{
RotateBox
container
=
new
RotateBox
();
flag
=
VisionAPI
.
eyemNNInstanceSegment
(
image
,
0.15f
,
ref
container
,
out
tpDstImg
);
log
.
Info
(
$
"OCRHandleRewrite:标签分割完成,rtncode={flag}"
);
Bitmap
b
=
VisionAPI
.
eyemCvtToBitmap
(
tpDstImg
);
log
.
Info
(
$
"OCRHandleRewrite:转换为Bitmap"
);
b
?.
Save
(
$
"labelSplit.jpg"
,
ImageFormat
.
Jpeg
);
log
.
Info
(
$
"OCRHandleRewrite:保存分割结果图:labelSplit.jpg"
);
VisionAPI
.
eyemImageFree
(
ref
tpDstImg
);
for
(
int
i
=
0
;
i
<
25
;
i
++)
{
EyemImage
tpDstImg1
=
new
EyemImage
();
if
(
i
<
container
.
p1
.
Length
&&
container
.
p1
[
i
].
iX
!=
0
)
{
flag
=
VisionAPI
.
eyemAchvRotateImage
(
image
,
container
.
p1
[
i
],
container
.
p2
[
i
],
container
.
p3
[
i
],
container
.
p4
[
i
],
out
tpDstImg1
);
//if (flag == 0)
{
if
(!
Directory
.
Exists
(
$
"{baseDir}label{i}"
))
Directory
.
CreateDirectory
(
$
"{baseDir}label{i}"
);
Bitmap
lbl
=
VisionAPI
.
eyemCvtToBitmap
(
tpDstImg1
);
lbl
?.
Save
(
$
"{baseDir}label{i}\\1.jpg"
,
ImageFormat
.
Jpeg
);
lbl
?.
RotateFlip
(
RotateFlipType
.
Rotate180FlipNone
);
lbl
?.
Save
(
$
"{baseDir}label{i}\\2.jpg"
,
ImageFormat
.
Jpeg
);
log
.
Info
(
$
"OCRHandleRewrite:获取标签图像并保存:{baseDir}label{i}"
);
}
VisionAPI
.
eyemImageFree
(
ref
tpDstImg1
);
}
}
VisionAPI
.
eyemImageFree
(
ref
image
);
}
log
.
Info
(
$
"OCRHandleRewrite:分隔标签耗时:{sw.ElapsedMilliseconds}ms"
);
sw
.
Restart
();
DirectoryInfo
directoryInfo
=
new
DirectoryInfo
(
baseDir
);
var
files
=
directoryInfo
.
GetDirectories
();
if
(
files
!=
null
&&
files
.
Length
==
0
)
{
if
(!
Directory
.
Exists
(
$
"{baseDir}label"
))
Directory
.
CreateDirectory
(
$
"{baseDir}label"
);
log
.
Info
(
$
"OCRHandleRewrite:无分割的标签,将原图传入名为label.jpg"
);
byte
[]
bytes
;
using
(
FileStream
fs
=
new
FileStream
(
imgPath
,
FileMode
.
Open
))
{
bytes
=
new
byte
[
fs
.
Length
];
fs
.
Read
(
bytes
,
0
,
bytes
.
Length
);
}
MemoryStream
memoryStream
=
new
MemoryStream
(
bytes
);
Bitmap
bitmap
=
new
Bitmap
(
memoryStream
);
bitmap
.
Save
(
$
"{baseDir}label\\label.jpg"
);
}
log
.
Info
(
$
"OCRHandleRewrite:开始OCR识别"
);
StringBuilder
stringBuilder
=
new
StringBuilder
();
List
<
string
>
stringLists
=
new
List
<
string
>();
foreach
(
var
dir
in
directoryInfo
.
GetDirectories
())
{
float
maxScore
=
0f
;
List
<
TextBlock
>
list
=
new
List
<
TextBlock
>();
foreach
(
var
item
in
dir
.
GetFiles
())
{
float
score
=
0f
;
var
imagebyte
=
File
.
ReadAllBytes
(
item
.
FullName
);
var
res
=
engine
.
DetectText
(
imagebyte
);
StringBuilder
sb
=
new
StringBuilder
();
res
.
TextBlocks
.
ForEach
(
s
=>
{
score
+=
s
.
Score
;
sb
.
AppendLine
(
s
.
Text
);
});
//Bitmap bitmap = new Bitmap(item.FullName);
//foreach (var items in res.TextBlocks)
//{
// using (Graphics g = Graphics.FromImage(bitmap))
// {
// g.DrawPolygon(new Pen(Brushes.Red, 2), items.BoxPoints.Select(x => new PointF() { X = x.X, Y = x.Y }).ToArray());
// }
//}
//// 保存带有绘制边界框的图像
//bitmap.Save("C:\\Users\\BOO\\Desktop\\项目\\ns100\\NS100\\paddleOCR\\bin\\Debug\\LabelOut\\label0\\1_with_boxes.jpg");
//// 最后不要忘记释放Bitmap对象
//bitmap.Dispose();
log
.
Info
(
$
"OCRHandleRewrite:【{item.FullName}】结果:【{score}】【{sb.ToString().Replace("
\
r
", "").Replace("
\
n
", "
;
")}】"
);
if
(
score
>
maxScore
)
{
maxScore
=
score
;
list
=
res
.
TextBlocks
;
}
}
#
region
ocr
文字统一一行
//矩形中心点的相差阈值
int
threshold
=
int
.
Parse
(
ConfigHelper
.
Config
.
Get
(
"paddleOcr_RowThreshold"
,
"10"
));
List
<
StringIntPair
>
mergedTextlist
=
new
List
<
StringIntPair
>();
double
lastYAvg
=
0
;
foreach
(
var
entity
in
list
)
{
double
avgY
=
entity
.
BoxPoints
.
Average
(
a
=>
a
.
Y
);
if
(
Math
.
Abs
(
lastYAvg
-
avgY
)<
threshold
)
{
mergedTextlist
.
Add
(
new
StringIntPair
(
entity
.
Text
,
entity
.
BoxPoints
[
0
].
X
));
}
else
{
if
(
mergedTextlist
.
Count
!=
0
)
{
var
stringdata
=
mergedTextlist
.
OrderBy
(
a
=>
a
.
IntValue
);
string
str
=
""
;
foreach
(
var
item
in
stringdata
)
{
str
+=
item
.
StringValue
+
" "
;
}
stringLists
.
Add
(
str
);
mergedTextlist
.
Clear
();
}
mergedTextlist
.
Add
(
new
StringIntPair
(
entity
.
Text
,
entity
.
BoxPoints
[
0
].
X
));
}
lastYAvg
=
avgY
;
}
if
(
mergedTextlist
.
Count
!=
0
)
{
var
stringdata
=
mergedTextlist
.
OrderBy
(
a
=>
a
.
IntValue
);
string
str
=
""
;
foreach
(
var
item
in
stringdata
)
{
str
+=
item
.
StringValue
+
" "
;
}
stringLists
.
Add
(
str
);
mergedTextlist
.
Clear
();
}
log
.
Info
(
$
"OCRHandleRewrite:矩形中心点相差阈值为:{threshold}"
);
#
endregion
log
.
Info
(
$
"OCRHandleRewrite:使用识别分数【{maxScore}】"
);
}
log
.
Info
(
$
"OCRHandleRewrite:OCR识别完成"
);
sw
.
Stop
();
log
.
Info
(
"OCRHandleRewrite:识别耗时:"
+
sw
.
ElapsedMilliseconds
.
ToString
()
+
"ms"
);
string
[]
strs
=
stringLists
.
ToArray
();
foreach
(
string
str
in
strs
)
{
if
(
string
.
IsNullOrEmpty
(
str
))
continue
;
result
+=
str
+
";"
;
}
if
(
result
.
EndsWith
(
";"
))
{
result
=
result
.
Substring
(
0
,
result
.
Length
-
1
);
}
log
.
Info
(
$
"OCRHandleRewrite:识别结果[{strs.Length}]:"
+
result
);
return
true
;
}
}
}
}
}
paddleOCR/paddleOCR.csproj
查看文件 @
76c15bc
...
@@ -153,6 +153,12 @@
...
@@ -153,6 +153,12 @@
<ItemGroup>
<ItemGroup>
<Content Include="pp.ico" />
<Content Include="pp.ico" />
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Model\Model.csproj">
<Project>{20E61A3D-BF87-4A99-9756-7FE13D2DAA6E}</Project>
<Name>Model</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\PaddleOCRSharp.2.3.0\build\PaddleOCRSharp.targets" Condition="Exists('..\packages\PaddleOCRSharp.2.3.0\build\PaddleOCRSharp.targets')" />
<Import Project="..\packages\PaddleOCRSharp.2.3.0\build\PaddleOCRSharp.targets" Condition="Exists('..\packages\PaddleOCRSharp.2.3.0\build\PaddleOCRSharp.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
...
...
paddleOCR/service/IService.cs
查看文件 @
76c15bc
...
@@ -3,6 +3,7 @@ using System.ServiceModel.Web;
...
@@ -3,6 +3,7 @@ using System.ServiceModel.Web;
using
System.IO
;
using
System.IO
;
using
System.Runtime.Serialization
;
using
System.Runtime.Serialization
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
Model
;
namespace
DeviceLibrary
namespace
DeviceLibrary
{
{
...
@@ -13,6 +14,10 @@ namespace DeviceLibrary
...
@@ -13,6 +14,10 @@ namespace DeviceLibrary
[
OperationContract
]
[
OperationContract
]
[
WebInvoke
(
UriTemplate
=
"/paddle/getOcr?ver={ver}&imgPath={imgPath}"
,
Method
=
"GET"
,
BodyStyle
=
WebMessageBodyStyle
.
Bare
,
RequestFormat
=
WebMessageFormat
.
Json
,
ResponseFormat
=
WebMessageFormat
.
Json
)]
[
WebInvoke
(
UriTemplate
=
"/paddle/getOcr?ver={ver}&imgPath={imgPath}"
,
Method
=
"GET"
,
BodyStyle
=
WebMessageBodyStyle
.
Bare
,
RequestFormat
=
WebMessageFormat
.
Json
,
ResponseFormat
=
WebMessageFormat
.
Json
)]
Result
Readocr
(
string
ver
,
string
imgPath
);
Result
Readocr
(
string
ver
,
string
imgPath
);
[
OperationContract
]
[
WebInvoke
(
UriTemplate
=
"/paddle/SelectOcrMethod?ver={ver}&imgPath={imgPath}"
,
Method
=
"GET"
,
BodyStyle
=
WebMessageBodyStyle
.
Bare
,
RequestFormat
=
WebMessageFormat
.
Json
,
ResponseFormat
=
WebMessageFormat
.
Json
)]
Result
SelectOcrMethod
(
string
ver
,
string
imgPath
);
}
}
[
DataContract
]
[
DataContract
]
...
...
paddleOCR/service/Service.cs
查看文件 @
76c15bc
...
@@ -6,6 +6,7 @@ using System.IO;
...
@@ -6,6 +6,7 @@ using System.IO;
using
System.Runtime.Serialization
;
using
System.Runtime.Serialization
;
using
System.Reflection
;
using
System.Reflection
;
using
paddleOCR
;
using
paddleOCR
;
using
static
log4net
.
Appender
.
RollingFileAppender
;
namespace
DeviceLibrary
namespace
DeviceLibrary
{
{
...
@@ -40,6 +41,15 @@ namespace DeviceLibrary
...
@@ -40,6 +41,15 @@ namespace DeviceLibrary
result
.
msg
=
$
"Paddle Ocr elapsed:{(DateTime.Now-dateTime).TotalSeconds.ToString("
f2
")}s"
;
result
.
msg
=
$
"Paddle Ocr elapsed:{(DateTime.Now-dateTime).TotalSeconds.ToString("
f2
")}s"
;
return
result
;
return
result
;
}
}
public
Result
SelectOcrMethod
(
string
ver
,
string
imgPath
)
{
Result
result
=
new
Result
();
DateTime
dateTime
=
DateTime
.
Now
;
result
.
data
=
PaddleHelper
.
StartCPlusOcrRewrite
(
imgPath
);
result
.
msg
=
$
"Paddle StartCPlusOcrRewrite elapsed:{(DateTime.Now - dateTime).TotalSeconds.ToString("
f2
")}s"
;
return
result
;
}
}
}
public
class
Service
public
class
Service
...
@@ -57,8 +67,8 @@ namespace DeviceLibrary
...
@@ -57,8 +67,8 @@ namespace DeviceLibrary
}
}
catch
(
Exception
ex
)
catch
(
Exception
ex
)
{
{
VisionAPI
.
log
.
Info
(
$
"启动OCR服务失败:{ex.Message}"
);
State
=
false
;
State
=
false
;
}
}
}
}
...
@@ -72,7 +82,7 @@ namespace DeviceLibrary
...
@@ -72,7 +82,7 @@ namespace DeviceLibrary
}
}
catch
(
Exception
ex
)
catch
(
Exception
ex
)
{
{
VisionAPI
.
log
.
Info
(
$
"关闭OCR服务失败:{ex.Message}"
);
}
}
}
}
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论