Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
张东亮
/
NS100
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit a291af67
由
张东亮
编写于
2023-04-23 15:27:18 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
OCR识别结果放入条码一起
1 个父辈
01fa4104
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
96 行增加
和
54 行删除
BLL/MaterialEdit.cs
BLL/Setting_Str.cs
SmartScan/SetControl/UsrMaterialTemplate.Designer.cs
SmartScan/SetControl/UsrMaterialTemplate.cs
paddleOCR/PaddleSharpAPI.cs
BLL/MaterialEdit.cs
查看文件 @
a291af6
...
...
@@ -156,7 +156,7 @@ namespace BLL
//保存需要识别ocr的区域
CurrntBitmap
?.
Save
(
@"ocr.jpg"
,
System
.
Drawing
.
Imaging
.
ImageFormat
.
Jpeg
);
regOcrCodes
=
OcrRecognize
(
"..\\ocr.jpg"
);
LogNet
.
log
.
Info
(
$
"OCR 识别结果:{
string.Join("
,
", regOcrCodes)
}"
);
LogNet
.
log
.
Info
(
$
"OCR 识别结果:{
regOcrCodes
}"
);
}
//优先匹配
...
...
@@ -396,7 +396,7 @@ namespace BLL
isCodeUsed
=
new
bool
[
code
.
Count
];
int
matchCount
=
0
;
bool
isMatch
=
false
;
List
<
MaterialCode
OCR
>
ocrlist
=
new
List
<
MaterialCodeOCR
>();
List
<
MaterialCode
>
ocrlist
=
new
List
<
MaterialCode
>();
List
<
BarcodeInfo
>
ocrcode
=
new
List
<
BarcodeInfo
>();
//命中规则的条码索引
List
<
int
>
MatchCodeIndex
=
new
List
<
int
>();
...
...
@@ -424,14 +424,6 @@ namespace BLL
}
}
//var ocrmatch = mateTemp[index].Ocr.FindAll(o => o.CodeID == codeMatch[0].CodeID);
//foreach (var o in ocrmatch)
//{
// ocrlist.Add(o);
// ocrcode.Add(code[j]);
//}
//break;
}
}
...
...
@@ -442,26 +434,21 @@ namespace BLL
}
if
(
Config
.
Func_EnabledOCR
)
{
foreach
(
var
o
in
mateTemp
[
index
].
Ocr
)
{
ocrlist
.
Add
(
o
);
//ocrcode.Add(code[j]);
}
int
ocrCount
=
ocrlist
.
Count
;
if
(
ocrlist
.
Count
>
0
)
List
<
MaterialCodeMatch
>
codeMatch
=
mateTemp
[
index
].
Match
.
FindAll
(
match
=>
match
.
CodeType
.
Equals
(
Setting_Str
.
OCR
));
int
ocrCount
=
codeMatch
.
Count
;
if
(
ocrCount
>
0
)
{
LogNet
.
log
.
Info
(
$
"{mateTemp[index].Name} 开始OCR匹配 [{ocrCount}]"
);
for
(
int
i
=
0
;
i
<
ocrlist
.
Count
;
i
++)
//
for (int i = 0; i < ocrlist.Count; i++)
{
List
<
MaterialCodeMatch
>
codeMatch
=
mateTemp
[
index
].
Match
.
FindAll
(
match
=>
match
.
CodeID
==
ocrlist
[
i
].
ID
);
foreach
(
string
regCode
in
regOcrCodes
.
Split
(
';'
))
{
if
(
string
.
IsNullOrEmpty
(
regCode
))
continue
;
var
x
=
new
BarcodeInfo
()
{
Text
=
regCode
,
CodeType
=
"OCR"
};
var
x
=
new
BarcodeInfo
()
{
Text
=
regCode
,
CodeType
=
Setting_Str
.
OCR
};
Dictionary
<
string
,
string
>
matchKey
=
CodeMatch
(
x
,
codeMatch
);
if
(
matchKey
!=
null
)
{
foreach
(
string
key
in
matchKey
.
Keys
)
{
if
(!
keyword
.
ContainsKey
(
key
))
...
...
BLL/Setting_Str.cs
查看文件 @
a291af6
...
...
@@ -9,5 +9,6 @@ namespace BLL
{
public
class
Setting_Str
{
public
const
string
OCR
=
"OCR"
;
}
}
SmartScan/SetControl/UsrMaterialTemplate.Designer.cs
查看文件 @
a291af6
此文件的差异被折叠,
点击展开。
SmartScan/SetControl/UsrMaterialTemplate.cs
查看文件 @
a291af6
...
...
@@ -56,10 +56,11 @@ namespace SmartScan
{
List
<
string
>
item
=
new
();
for
(
int
i
=
0
;
i
<
mateCopy
[
mateIndex
].
Code
.
Count
;
i
++)
{
item
.
Add
(
FormatCode
(
i
));
}
return
item
.
ToArray
();
}
private
string
FormatCode
(
int
index
)
{
MaterialCode
code
=
mateCopy
[
mateIndex
].
Code
[
index
];
...
...
@@ -70,9 +71,16 @@ namespace SmartScan
string
s
=
string
.
Format
(
"({0}) "
,
index
+
1
)
+
text
;
if
(
code
.
ID
==
mateCopy
[
mateIndex
].
PrimaryCode
)
s
+=
" <P>"
;
//条码的关键字
List
<
string
>
arr
=
new
();
List
<
MaterialCodeMatch
>
math
=
mateCopy
[
mateIndex
].
Match
.
FindAll
(
s
=>
s
.
CodeID
==
mateCopy
[
mateIndex
].
Code
[
index
].
ID
);
for
(
int
j
=
0
;
j
<
math
.
Count
;
j
++)
arr
.
Add
(
math
[
j
].
Keyword
);
if
(
arr
.
Count
>
0
)
s
+=
" <OCR>"
;
arr
=
new
();
for
(
int
i
=
0
;
i
<
mateCopy
[
mateIndex
].
Match
.
Count
;
i
++)
{
if
(
code
.
ID
==
mateCopy
[
mateIndex
].
Match
[
i
].
CodeID
)
...
...
@@ -82,16 +90,27 @@ namespace SmartScan
s
+=
" ["
+
string
.
Join
(
","
,
arr
)
+
"]"
;
//OCR的关键字
arr
=
new
();
List
<
MaterialCodeOCR
>
codeOcr
=
mateCopy
[
mateIndex
].
Ocr
.
FindAll
(
s
=>
s
.
CodeID
==
code
.
ID
);
for
(
int
i
=
0
;
i
<
codeOcr
.
Count
;
i
++)
{
List
<
MaterialCodeMatch
>
math
=
mateCopy
[
mateIndex
].
Match
.
FindAll
(
s
=>
s
.
CodeID
==
codeOcr
[
i
].
ID
);
for
(
int
j
=
0
;
j
<
math
.
Count
;
j
++)
arr
.
Add
(
math
[
j
].
Keyword
);
}
if
(
arr
.
Count
>
0
)
s
+=
" [OCR:"
+
string
.
Join
(
","
,
arr
)
+
"]"
;
//arr = new();
//List<MaterialCode> codeOcr = mateCopy[mateIndex].Code.FindAll(s => s.CodeType.Equals(Setting_Str.OCR));
//for (int i = 0; i < codeOcr.Count; i++)
//{
// List<MaterialCodeMatch> math = mateCopy[mateIndex].Match.FindAll(s => s.CodeID == codeOcr[i].ID);
// for (int j = 0; j < math.Count; j++)
// arr.Add(math[j].Keyword);
//}
//if (arr.Count > 0)
// s += " [OCR"+ "]";// + string.Join(",", arr) +
//arr = new();
//List<MaterialCodeOCR> codeOcr = mateCopy[mateIndex].Ocr.FindAll(s => s.CodeID == code.ID);
//for (int i = 0; i < codeOcr.Count; i++)
//{
// List<MaterialCodeMatch> math = mateCopy[mateIndex].Match.FindAll(s => s.CodeID == codeOcr[i].ID);
// for (int j = 0; j < math.Count; j++)
// arr.Add(math[j].Keyword);
//}
//if (arr.Count > 0)
// s += " [OCR:" + string.Join(",", arr) + "]";
return
s
;
}
...
...
@@ -119,8 +138,8 @@ namespace SmartScan
if
(
dr
!=
DialogResult
.
OK
)
return
;
if
(
string
.
IsNullOrWhiteSpace
(
input
.
InputValue
))
return
;
//检查是否有已存在的名称
var
find
=
mateCopy
.
Find
(
s
=>
s
.
Name
.
Equals
(
input
.
InputValue
));
if
(
find
!=
null
)
var
find
=
mateCopy
.
Find
(
s
=>
s
.
Name
.
Equals
(
input
.
InputValue
));
if
(
find
!=
null
)
{
string
hint
=
Asa
.
FaceControl
.
Language
.
Dialog
(
"KeyExists"
);
hint
=
hint
.
Replace
(
"[name]"
,
input
.
InputValue
);
...
...
@@ -226,9 +245,9 @@ namespace SmartScan
List
<
CameraVisionLib
.
Model
.
BarcodeInfo
>
info
=
Common
.
cameraVision
.
GetBarCode
(
bmp
);
LstCode
.
Items
.
Clear
();
ImgShow
.
CodeCenterClear
();
mateCopy
[
mateIndex
].
Match
.
Clear
();
mateCopy
[
mateIndex
].
Code
.
Clear
();
mateCopy
[
mateIndex
].
Ocr
.
Clear
();
mateCopy
[
mateIndex
].
Match
.
Clear
();
mateCopy
[
mateIndex
].
PrimaryCode
=
-
1
;
mateCopy
[
mateIndex
].
State
=
TemplateState
.
Unsaved
;
Common
.
mateMaxCodeID
=
info
.
Count
;
...
...
@@ -271,7 +290,7 @@ namespace SmartScan
if
(
codeIndex
==
-
1
)
return
;
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
);
DialogResult
dr
=
frm
.
ShowDialog
();
if
(
dr
==
DialogResult
.
OK
)
...
...
@@ -288,8 +307,43 @@ namespace SmartScan
private
void
BtnOcrCode_Click
(
object
sender
,
EventArgs
e
)
{
if
(
codeIndex
==
-
1
)
return
;
if
(
bmp
==
null
)
return
;
//保存需要识别ocr的区域
bmp
?.
Save
(
@"ocrt.jpg"
,
System
.
Drawing
.
Imaging
.
ImageFormat
.
Jpeg
);
string
[]
regOcrCodes
=
PaddleOCRHelper
.
StartTest
(
"..\\ocrt.jpg"
).
Split
(
';'
);
LstCode
.
Items
.
Clear
();
var
ocrs
=
mateCopy
[
mateIndex
].
Code
.
FindAll
(
s
=>
s
.
CodeType
.
Equals
(
Setting_Str
.
OCR
));
foreach
(
var
code
in
ocrs
)
{
mateCopy
[
mateIndex
].
Code
.
Remove
(
code
);
}
mateCopy
[
mateIndex
].
Match
.
Clear
();
mateCopy
[
mateIndex
].
Ocr
.
Clear
();
if
(
regOcrCodes
.
Length
==
0
)
{
string
text
=
Language
.
Dialog
(
LanguageDialogKey
.
CODE_COUNT
);
new
FaceMessageBox
(
""
,
text
,
MessageBoxButtons
.
OK
).
ShowDialog
();
return
;
}
mateCopy
[
mateIndex
].
State
=
TemplateState
.
Unsaved
;
int
startidx
=
Common
.
mateMaxCodeID
+
1
;
foreach
(
var
ocr
in
regOcrCodes
)
{
if
(
string
.
IsNullOrEmpty
(
ocr
))
continue
;
MaterialCode
code
=
new
()
{
ID
=
startidx
,
Text
=
ocr
,
CodeType
=
Setting_Str
.
OCR
};
mateCopy
[
mateIndex
].
Code
.
Add
(
code
);
startidx
++;
}
LstCode
.
Items
.
AddRange
(
FormatCode
());
LstCode
.
SelectedIndex
=
codeIndex
=
-
1
;
//if (codeIndex == -1) return;
//var m = mateCopy[mateIndex].Match.Find(m=>m.CodeID==codeIndex);
//if (m == null)
//{
...
...
@@ -302,21 +356,21 @@ namespace SmartScan
// new FaceMessageBox("", text, MessageBoxButtons.OK).ShowDialog();
// return;
//}
List
<
MaterialCodeOCR
>
codeOcr
=
mateCopy
[
mateIndex
].
Ocr
.
FindAll
(
s
=>
s
.
CodeID
==
mateCopy
[
mateIndex
].
Code
[
codeIndex
].
ID
);
//
List<MaterialCodeOCR> codeOcr = mateCopy[mateIndex].Ocr.FindAll(s => s.CodeID == mateCopy[mateIndex].Code[codeIndex].ID);
FrmCodeOCR
frm
=
new
(
mateCopy
[
mateIndex
].
Code
[
codeIndex
],
codeOcr
,
mateCopy
[
mateIndex
].
Match
,
mateCopy
[
mateIndex
].
Image
);
DialogResult
dr
=
frm
.
ShowDialog
();
if
(
dr
==
DialogResult
.
OK
)
{
for
(
int
i
=
0
;
i
<
frm
.
codeOcr
.
Count
;
i
++)
mateCopy
[
mateIndex
].
Match
.
RemoveAll
(
s
=>
s
.
CodeID
==
frm
.
codeOcr
[
i
].
ID
);
mateCopy
[
mateIndex
].
Ocr
.
RemoveAll
(
s
=>
s
.
CodeID
==
mateCopy
[
mateIndex
].
Code
[
codeIndex
].
ID
);
mateCopy
[
mateIndex
].
Ocr
.
AddRange
(
frm
.
codeOcr
);
mateCopy
[
mateIndex
].
Match
.
AddRange
(
frm
.
codeMatch
);
mateCopy
[
mateIndex
].
State
=
TemplateState
.
Unsaved
;
LstCode
.
Items
[
codeIndex
]
=
FormatCode
(
codeIndex
);
}
//
FrmCodeOCR frm = new(mateCopy[mateIndex].Code[codeIndex], codeOcr, mateCopy[mateIndex].Match, mateCopy[mateIndex].Image);
//
DialogResult dr = frm.ShowDialog();
//
if (dr == DialogResult.OK)
//
{
//
for (int i = 0; i < frm.codeOcr.Count; i++)
//
mateCopy[mateIndex].Match.RemoveAll(s => s.CodeID == frm.codeOcr[i].ID);
//
mateCopy[mateIndex].Ocr.RemoveAll(s => s.CodeID == mateCopy[mateIndex].Code[codeIndex].ID);
//
mateCopy[mateIndex].Ocr.AddRange(frm.codeOcr);
//
mateCopy[mateIndex].Match.AddRange(frm.codeMatch);
//
mateCopy[mateIndex].State = TemplateState.Unsaved;
//
LstCode.Items[codeIndex] = FormatCode(codeIndex);
//
}
}
private
void
BtnPrimaryCode_Click
(
object
sender
,
EventArgs
e
)
...
...
paddleOCR/PaddleSharpAPI.cs
查看文件 @
a291af6
...
...
@@ -145,7 +145,7 @@ namespace paddleOCR
var
res
=
engine
.
DetectText
(
imagebyte
);
StringBuilder
sb
=
new
StringBuilder
();
res
.
TextBlocks
.
ForEach
(
s
=>
{
score
+=
s
.
Score
;
sb
.
AppendLine
(
s
.
Text
);
});
log
.
Info
(
$
"【{item.FullName}】
识别
结果:【{score}】【{sb.ToString().Replace("
\
r
", "").Replace("
\
n
", "
;
")}】"
);
log
.
Info
(
$
"【{item.FullName}】结果:【{score}】【{sb.ToString().Replace("
\
r
", "").Replace("
\
n
", "
;
")}】"
);
if
(
score
>
maxScore
)
{
maxScore
=
score
;
...
...
@@ -225,7 +225,7 @@ namespace paddleOCR
{
result
=
result
.
Substring
(
0
,
result
.
Length
-
1
);
}
log
.
Info
(
"识别结果
:"
+
result
);
log
.
Info
(
$
"识别结果[{strs.Length}]
:"
+
result
);
return
true
;
}
/// <summary>
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论