Commit ffb447c6 王海洋

添加Ai拍照接口

1 个父辈 de54abbe
...@@ -66,7 +66,7 @@ namespace BLL ...@@ -66,7 +66,7 @@ namespace BLL
} }
[HandleProcessCorruptedStateExceptions] [HandleProcessCorruptedStateExceptions]
static string StartCplusOcr(string imgPath) public static string StartCplusOcr(string imgPath)
{ {
LogNet.log.Error("进入OcrGet请求"); LogNet.log.Error("进入OcrGet请求");
string json=Http.Get($"{baseUrl}?ver=cplus&imgPath={imgPath}"); string json=Http.Get($"{baseUrl}?ver=cplus&imgPath={imgPath}");
...@@ -74,7 +74,7 @@ namespace BLL ...@@ -74,7 +74,7 @@ namespace BLL
Result result= JsonConvert.DeserializeObject<Result>(json); Result result= JsonConvert.DeserializeObject<Result>(json);
return result?.data??""; return result?.data??"";
} }
static string StartPythonOcr(string imgPath) public static string StartPythonOcr(string imgPath)
{ {
if (!AppIsRun()) if (!AppIsRun())
{ {
......
...@@ -21,6 +21,10 @@ namespace Model ...@@ -21,6 +21,10 @@ namespace Model
WebResultCamera WorkWithCamera(); WebResultCamera WorkWithCamera();
[OperationContract] [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)] [WebInvoke(Method = "POST", UriTemplate = "NeoScan/WorkWithCode", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
WebResultCode WorkWithCode(Stream json); WebResultCode WorkWithCode(Stream json);
[OperationContract] [OperationContract]
...@@ -47,11 +51,14 @@ namespace Model ...@@ -47,11 +51,14 @@ namespace Model
public string Msg { get; set; } public string Msg { get; set; }
[DataMember] [DataMember]
public WebCodeAll[] Data { get; set; } public WebCodeAll[] Data { get; set; }
[DataMember]
public string Text { get; set; }
public WebResultCamera() public WebResultCamera()
{ {
ErrorCode = 0; ErrorCode = 0;
Msg = "OK"; Msg = "OK";
Text = "";
} }
} }
......
...@@ -277,6 +277,7 @@ namespace SmartScan ...@@ -277,6 +277,7 @@ namespace SmartScan
this.Controls.Add(this.BtnStart); this.Controls.Add(this.BtnStart);
this.Icon = global::SmartScan.Properties.Resources.NEO_64; this.Icon = global::SmartScan.Properties.Resources.NEO_64;
this.Name = "FrmMain"; this.Name = "FrmMain";
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "Form1"; this.Text = "Form1";
this.TitleFont = new System.Drawing.Font("宋体", 16.2F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.TitleFont = new System.Drawing.Font("宋体", 16.2F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.TitleHeight = 50; this.TitleHeight = 50;
......
...@@ -23,6 +23,7 @@ namespace SmartScan ...@@ -23,6 +23,7 @@ namespace SmartScan
public FrmMain() public FrmMain()
{ {
InitializeComponent(); InitializeComponent();
BtnStart.Tag = "not"; BtnStart.Tag = "not";
if (Config.AppUI_HideLogo) if (Config.AppUI_HideLogo)
...@@ -273,8 +274,17 @@ namespace SmartScan ...@@ -273,8 +274,17 @@ namespace SmartScan
CboLanguage.Items.AddRange(Language.Name.ToArray()); CboLanguage.Items.AddRange(Language.Name.ToArray());
CboLanguage.SelectedText = BLLCommon.config.Language; CboLanguage.SelectedText = BLLCommon.config.Language;
BLLCommon.AutoGenRules = AutoGenRule.LoadFile(); 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()) if (CheckCamera() && CheckIOModule())
{ {
...@@ -452,7 +462,7 @@ namespace SmartScan ...@@ -452,7 +462,7 @@ namespace SmartScan
} }
Common.frmWaitting.Close(); Common.frmWaitting.Close();
} }
public void SetWaittingMsg(string msg,int keepsec=3) public void SetWaittingMsg (string msg,int keepsec=3)
{ {
if (Common.frmMain.InvokeRequired) if (Common.frmMain.InvokeRequired)
{ {
......
...@@ -22,7 +22,7 @@ namespace SmartScan ...@@ -22,7 +22,7 @@ namespace SmartScan
//this.Height = 738; //this.Height = 738;
this.Top = 15; this.Top = 15;
this.Left = 0; this.Left = 0;
WebService.Open();//启动条码匹配服务
LogNet.log = log4net.LogManager.GetLogger("SmartScan"); LogNet.log = log4net.LogManager.GetLogger("SmartScan");
} }
......
...@@ -120,6 +120,7 @@ namespace SmartScan ...@@ -120,6 +120,7 @@ namespace SmartScan
Application.Run(new FrmLoading(back)); //预加载,完成后自动退出 Application.Run(new FrmLoading(back)); //预加载,完成后自动退出
Common.frmMain = new FrmMain(); Common.frmMain = new FrmMain();
Common.frmWaitting = new FrmWaitting(); Common.frmWaitting = new FrmWaitting();
WebService.Open();//启动条码匹配服务
if (back) if (back)
{ {
var fsp = new FrmSetPlus(); var fsp = new FrmSetPlus();
......
using BLL; using Asa.FaceControl;
using BLL;
using DocumentFormat.OpenXml;
using Model; using Model;
using Newtonsoft.Json; using Newtonsoft.Json;
using SmartScan.PlusSettingFrm; using SmartScan.PlusSettingFrm;
...@@ -7,9 +9,13 @@ using System.Collections.Generic; ...@@ -7,9 +9,13 @@ using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Runtime.Serialization.Formatters.Binary; using System.Runtime.Serialization.Formatters.Binary;
using System.ServiceModel; using System.ServiceModel;
using System.ServiceModel.Activation; using System.ServiceModel.Activation;
using System.Web;
using System.Web.UI.WebControls;
namespace SmartScan namespace SmartScan
{ {
...@@ -33,6 +39,84 @@ namespace SmartScan ...@@ -33,6 +39,84 @@ namespace SmartScan
Common.frmMain.Invoke(new Action(() => { msg = Common.frmMain.WebTouchWork(); })); Common.frmMain.Invoke(new Action(() => { msg = Common.frmMain.WebTouchWork(); }));
return new WebResultCamera() { Data = msg }; 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) public WebResultCode WorkWithCode(Stream json)
{ {
...@@ -335,7 +419,8 @@ namespace SmartScan ...@@ -335,7 +419,8 @@ namespace SmartScan
} }
return workCodeKeyword; return workCodeKeyword;
#endregion #endregion
} }
} }
} }
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!