Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
张东亮
/
NS100
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit ffb447c6
由
王海洋
编写于
2025-03-06 09:20:12 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
添加Ai拍照接口
1 个父辈
de54abbe
显示空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
110 行增加
和
6 行删除
BLL/PaddleOCRHelper.cs
Model/IWeb.cs
SmartScan/Form/FrmMain.Designer.cs
SmartScan/Form/FrmMain.cs
SmartScan/PlusSettingFrm/FrmSetPlus.cs
SmartScan/Program.cs
SmartScan/WebCallWork.cs
BLL/PaddleOCRHelper.cs
查看文件 @
ffb447c
...
...
@@ -66,7 +66,7 @@ namespace BLL
}
[
HandleProcessCorruptedStateExceptions
]
static
string
StartCplusOcr
(
string
imgPath
)
public
static
string
StartCplusOcr
(
string
imgPath
)
{
LogNet
.
log
.
Error
(
"进入OcrGet请求"
);
string
json
=
Http
.
Get
(
$
"{baseUrl}?ver=cplus&imgPath={imgPath}"
);
...
...
@@ -74,7 +74,7 @@ namespace BLL
Result
result
=
JsonConvert
.
DeserializeObject
<
Result
>(
json
);
return
result
?.
data
??
""
;
}
static
string
StartPythonOcr
(
string
imgPath
)
public
static
string
StartPythonOcr
(
string
imgPath
)
{
if
(!
AppIsRun
())
{
...
...
Model/IWeb.cs
查看文件 @
ffb447c
...
...
@@ -21,6 +21,10 @@ namespace Model
WebResultCamera
WorkWithCamera
();
[
OperationContract
]
[
WebGet
(
UriTemplate
=
"NeoScan/Neotel"
,
BodyStyle
=
WebMessageBodyStyle
.
Bare
,
RequestFormat
=
WebMessageFormat
.
Json
,
ResponseFormat
=
WebMessageFormat
.
Json
)]
WebResultCamera
GetCamera
();
[
OperationContract
]
[
WebInvoke
(
Method
=
"POST"
,
UriTemplate
=
"NeoScan/WorkWithCode"
,
BodyStyle
=
WebMessageBodyStyle
.
Bare
,
RequestFormat
=
WebMessageFormat
.
Json
,
ResponseFormat
=
WebMessageFormat
.
Json
)]
WebResultCode
WorkWithCode
(
Stream
json
);
[
OperationContract
]
...
...
@@ -47,11 +51,14 @@ namespace Model
public
string
Msg
{
get
;
set
;
}
[
DataMember
]
public
WebCodeAll
[]
Data
{
get
;
set
;
}
[
DataMember
]
public
string
Text
{
get
;
set
;
}
public
WebResultCamera
()
{
ErrorCode
=
0
;
Msg
=
"OK"
;
Text
=
""
;
}
}
...
...
SmartScan/Form/FrmMain.Designer.cs
查看文件 @
ffb447c
...
...
@@ -277,6 +277,7 @@ namespace SmartScan
this
.
Controls
.
Add
(
this
.
BtnStart
);
this
.
Icon
=
global
::
SmartScan
.
Properties
.
Resources
.
NEO_64
;
this
.
Name
=
"FrmMain"
;
this
.
StartPosition
=
System
.
Windows
.
Forms
.
FormStartPosition
.
Manual
;
this
.
Text
=
"Form1"
;
this
.
TitleFont
=
new
System
.
Drawing
.
Font
(
"宋体"
,
16.2F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
TitleHeight
=
50
;
...
...
SmartScan/Form/FrmMain.cs
查看文件 @
ffb447c
...
...
@@ -23,6 +23,7 @@ namespace SmartScan
public
FrmMain
()
{
InitializeComponent
();
BtnStart
.
Tag
=
"not"
;
if
(
Config
.
AppUI_HideLogo
)
...
...
@@ -273,8 +274,17 @@ namespace SmartScan
CboLanguage
.
Items
.
AddRange
(
Language
.
Name
.
ToArray
());
CboLanguage
.
SelectedText
=
BLLCommon
.
config
.
Language
;
BLLCommon
.
AutoGenRules
=
AutoGenRule
.
LoadFile
();
if
(
BLLCommon
.
config
.
OpenMaximize
)
Maximize
();
//if (BLLCommon.config.OpenMaximize) Maximize();
this
.
StartPosition
=
FormStartPosition
.
Manual
;
// 获取主屏幕的分辨率
Rectangle
screenBounds
=
Screen
.
PrimaryScreen
.
Bounds
;
// 设置窗体位置为屏幕左边
this
.
Location
=
new
Point
(
0
,
0
);
// 设置窗体大小为屏幕宽度的四分之三,高度为屏幕高度
this
.
Size
=
new
Size
((
int
)(
screenBounds
.
Width
*
0.75
),
screenBounds
.
Height
);
if
(
CheckCamera
()
&&
CheckIOModule
())
{
...
...
@@ -452,7 +462,7 @@ namespace SmartScan
}
Common
.
frmWaitting
.
Close
();
}
public
void
SetWaittingMsg
(
string
msg
,
int
keepsec
=
3
)
public
void
SetWaittingMsg
(
string
msg
,
int
keepsec
=
3
)
{
if
(
Common
.
frmMain
.
InvokeRequired
)
{
...
...
SmartScan/PlusSettingFrm/FrmSetPlus.cs
查看文件 @
ffb447c
...
...
@@ -22,7 +22,7 @@ namespace SmartScan
//this.Height = 738;
this
.
Top
=
15
;
this
.
Left
=
0
;
WebService
.
Open
();
//启动条码匹配服务
LogNet
.
log
=
log4net
.
LogManager
.
GetLogger
(
"SmartScan"
);
}
...
...
SmartScan/Program.cs
查看文件 @
ffb447c
...
...
@@ -120,6 +120,7 @@ namespace SmartScan
Application
.
Run
(
new
FrmLoading
(
back
));
//预加载,完成后自动退出
Common
.
frmMain
=
new
FrmMain
();
Common
.
frmWaitting
=
new
FrmWaitting
();
WebService
.
Open
();
//启动条码匹配服务
if
(
back
)
{
var
fsp
=
new
FrmSetPlus
();
...
...
SmartScan/WebCallWork.cs
查看文件 @
ffb447c
using
BLL
;
using
Asa.FaceControl
;
using
BLL
;
using
DocumentFormat.OpenXml
;
using
Model
;
using
Newtonsoft.Json
;
using
SmartScan.PlusSettingFrm
;
...
...
@@ -7,9 +9,13 @@ using System.Collections.Generic;
using
System.Drawing
;
using
System.IO
;
using
System.Linq
;
using
System.Reflection
;
using
System.Runtime.Serialization.Formatters.Binary
;
using
System.ServiceModel
;
using
System.ServiceModel.Activation
;
using
System.Web
;
using
System.Web.UI.WebControls
;
namespace
SmartScan
{
...
...
@@ -34,6 +40,84 @@ namespace SmartScan
return
new
WebResultCamera
()
{
Data
=
msg
};
}
public
WebResultCamera
GetCamera
()
{
Bitmap
[]
result
=
Camera
.
Capture
();
Bitmap
bmp
;
var
content
=
""
;
//if (result.Length == 0) return null;
if
(
result
.
Length
==
0
)
{
// 当没有捕获到图像时,从本地加载默认图像
string
defaultImagePath
=
"C:\\Users\\HY\\Desktop\\77F1EA37-A9B5-46cb-BFFA-5F201EE0FA41.png"
;
// 替换为你的默认图像路径
content
=
PaddleOCRHelper
.
StartCplusOcr
(
defaultImagePath
);
//string res = PaddleOCRHelper.StartPythonOcr(defaultImagePath);
if
(
File
.
Exists
(
defaultImagePath
))
{
bmp
=
new
Bitmap
(
defaultImagePath
);
}
else
{
return
null
;
}
}
else
{
try
{
bmp
=
result
[
0
];
LogNet
.
log
.
Info
(
"相机拍照结果result【0】"
+
bmp
);
LogNet
.
log
.
Info
(
"ocr开始存图"
);
Assembly
assembly
=
Assembly
.
GetExecutingAssembly
();
string
location
=
assembly
.
Location
;
string
directory
=
System
.
IO
.
Path
.
GetDirectoryName
(
location
);
string
filePath
=
directory
+
"\\ocr.png"
;
// 替换为实际路径
// 保存图像到文件
SaveBitmapToFile
(
bmp
,
filePath
);
LogNet
.
log
.
Info
(
"ocr存图成功"
);
content
=
PaddleOCRHelper
.
StartCplusOcr
(
filePath
);
LogNet
.
log
.
Info
(
"content ocr识别结果:"
+
content
);
}
catch
(
Exception
)
{
bmp
=
result
[
0
];
LogNet
.
log
.
Info
(
"ocr识别解析失败"
);
}
// string res = PaddleOCRHelper.StartPythonOcr(filePath);
}
string
base64String
=
ConvertBitmapToBase64
(
bmp
);
return
new
WebResultCamera
{
Msg
=
base64String
,
Text
=
content
};
}
public
static
void
SaveBitmapToFile
(
Bitmap
bmp
,
string
filePath
)
{
try
{
bmp
.
Save
(
filePath
,
System
.
Drawing
.
Imaging
.
ImageFormat
.
Png
);
}
catch
(
Exception
)
{
LogNet
.
log
.
Info
(
"ocr存图失败"
);
}
}
public
static
string
ConvertBitmapToBase64
(
Bitmap
bitmap
)
{
using
(
MemoryStream
ms
=
new
MemoryStream
())
{
bitmap
.
Save
(
ms
,
System
.
Drawing
.
Imaging
.
ImageFormat
.
Png
);
// 保存为PNG格式
byte
[]
imageBytes
=
ms
.
ToArray
();
return
Convert
.
ToBase64String
(
imageBytes
);
}
}
public
WebResultCode
WorkWithCode
(
Stream
json
)
{
LogNet
.
log
.
Info
(
$
"WebService WorkWithCode 接口被调用"
);
...
...
@@ -336,6 +420,7 @@ namespace SmartScan
return
workCodeKeyword
;
#
endregion
}
}
}
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论