Commit e1067ae1 LN

1

1 个父辈 9ff72174
...@@ -32,7 +32,7 @@ namespace TSA_V.DeviceLibrary ...@@ -32,7 +32,7 @@ namespace TSA_V.DeviceLibrary
LogUtil.info("HTTP服务已启动,正在监听9876端口..."); LogUtil.info("HTTP服务已启动,正在监听9876端口...");
Task.Factory.StartNew(() => Task.Factory.StartNew(() =>
{ {
Run(); Run();
}); });
} }
return true; return true;
......
...@@ -465,27 +465,42 @@ namespace TSA_V ...@@ -465,27 +465,42 @@ namespace TSA_V
{ {
//AccAOI.FrmAoiSetting frmAoiSetting = new FrmAoiSetting(); //AccAOI.FrmAoiSetting frmAoiSetting = new FrmAoiSetting();
//frmAoiSetting.Show(); //frmAoiSetting.Show();
string createnew = ResourceCulture.GetString(ResourceCulture.CreateNew, "新建"); try
AOIManager.LoadAOIFile(null, "");
List<string> listb = new List<string>(AOIManager.FileList);
listb.Insert(0, createnew);
FrmSelectPoint frma = new FrmSelectPoint(ResourceCulture.GetString("FrmBoardSelect_Text", "请选择AOI"), listb, listb.Count > 1 ? 1 : 0);
DialogResult result = frma.ShowDialog();
if (result.Equals(DialogResult.OK))
{ {
string aoiName = listb[frma.SelectIndex]; IOManager.IOMove(IOManager.Device_Led, IO_VALUE.LOW);
PTipSoundProcess.AOIopen = true;
string path = Application.StartupPath + ConfigAppSettings.GetValue(Setting_Init.AOIFileConfig);
string fileName = ""; string createnew = ResourceCulture.GetString(ResourceCulture.CreateNew, "新建");
if (!aoiName.Equals("")) AOIManager.LoadAOIFile(null, "");
List<string> listb = new List<string>(AOIManager.FileList);
listb.Insert(0, createnew);
FrmSelectPoint frma = new FrmSelectPoint(ResourceCulture.GetString("FrmBoardSelect_Text", "请选择AOI"), listb, listb.Count > 1 ? 1 : 0);
DialogResult result = frma.ShowDialog();
if (result.Equals(DialogResult.OK))
{ {
fileName = path + aoiName; string aoiName = listb[frma.SelectIndex];
string path = Application.StartupPath + ConfigAppSettings.GetValue(Setting_Init.AOIFileConfig);
string fileName = "";
if (!aoiName.Equals(""))
{
fileName = path + aoiName;
}
AccAOI.AOIResourceCulture.SetCurrentCulture(ResourceCulture.CurrLanguage);
if (aoiName == createnew)
fileName = "";
FrmAoiSetting frm = new FrmAoiSetting(fileName, null, path);
frm.ShowDialog();
} }
AccAOI.AOIResourceCulture.SetCurrentCulture(ResourceCulture.CurrLanguage); }
if (aoiName == createnew) catch (Exception ex)
fileName = ""; {
FrmAoiSetting frm = new FrmAoiSetting(fileName, null, path);
frm.ShowDialog(); }
finally
{
PTipSoundProcess.AOIopen = false ;
IOManager.IOMove(IOManager.Device_Led, IO_VALUE.HIGH);
} }
} }
......
...@@ -4,6 +4,7 @@ using System; ...@@ -4,6 +4,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Management;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
...@@ -51,12 +52,6 @@ namespace TSA_V ...@@ -51,12 +52,6 @@ namespace TSA_V
[MTAThread] [MTAThread]
static void Main() static void Main()
{ {
//DatumPoint datumPoint = new DatumPoint("YR1", "1", 2, 61.309f, 133.04f, "CRD", 6.06f, -4.31f);
//DatumPoint datumPoint = new DatumPoint("YR1", "1", 2, 61.309f, 133.04f, "CRD", 0, 0);
//LearningControl.TrainModel();
//datumPoint = LearningControl.TestData(datumPoint);
string ext2v = "111101111111".Substring(4, 1);
try try
{ {
// 方法四相对于方法三而言应该可以说是一个改进, // 方法四相对于方法三而言应该可以说是一个改进,
...@@ -152,8 +147,36 @@ namespace TSA_V ...@@ -152,8 +147,36 @@ namespace TSA_V
} }
} }
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) private static void Test()
{
//DatumPoint datumPoint = new DatumPoint("YR1", "1", 2, 61.309f, 133.04f, "CRD", 6.06f, -4.31f);
//DatumPoint datumPoint = new DatumPoint("YR1", "1", 2, 61.309f, 133.04f, "CRD", 0, 0);
//LearningControl.TrainModel();
//datumPoint = LearningControl.TestData(datumPoint);
//string ext2v = "111101111111".Substring(4, 1);
//DsDevice[] videoInputDevices = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
// int cameraCount = videoInputDevices.Length;
// Console.WriteLine("Number of built-in cameras: " + cameraCount);
int cameraCount = 0;
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PnPEntity WHERE Caption LIKE '%camera%'");
ManagementObjectCollection devices = searcher.Get();
foreach (ManagementObject device in devices)
{
LogUtil.info("devices : "+device.Path.Path );
cameraCount++;
}
LogUtil.info("Number of built-in cameras: " + cameraCount);
}
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{ {
LogUnhandledException("CurrentDomain_UnhandledException", e.ToString() + "" + e.ExceptionObject.ToString() + " "); LogUnhandledException("CurrentDomain_UnhandledException", e.ToString() + "" + e.ExceptionObject.ToString() + " ");
} }
......
...@@ -15,7 +15,8 @@ ...@@ -15,7 +15,8 @@
如果你的应用程序需要此虚拟化来实现向后兼容性,则删除此 如果你的应用程序需要此虚拟化来实现向后兼容性,则删除此
元素。 元素。
--> -->
<requestedExecutionLevel level="asInvoker" uiAccess="false" /> <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<!--<requestedExecutionLevel level="asInvoker" uiAccess="false" />-->
</requestedPrivileges> </requestedPrivileges>
<applicationRequestMinimum> <applicationRequestMinimum>
<defaultAssemblyRequest permissionSetReference="Custom" /> <defaultAssemblyRequest permissionSetReference="Custom" />
......
...@@ -148,6 +148,7 @@ ...@@ -148,6 +148,7 @@
<Reference Include="System.Data.SQLite, Version=1.0.113.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL"> <Reference Include="System.Data.SQLite, Version=1.0.113.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<HintPath>..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.113.3\lib\net46\System.Data.SQLite.dll</HintPath> <HintPath>..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.113.3\lib\net46\System.Data.SQLite.dll</HintPath>
</Reference> </Reference>
<Reference Include="System.Management" />
<Reference Include="System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> <Reference Include="System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll</HintPath> <HintPath>..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll</HintPath>
</Reference> </Reference>
...@@ -631,6 +632,9 @@ ...@@ -631,6 +632,9 @@
<Content Include="hands\defMTest.py"> <Content Include="hands\defMTest.py">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="hands\requirements.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="image\alarm2.gif"> <Content Include="image\alarm2.gif">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
......
using HalconDotNet; using HalconDotNet;
using System; using System;
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.IO;
using System.Management;
using System.Windows.Forms; using System.Windows.Forms;
using TSA_V.Common; using TSA_V.Common;
...@@ -13,11 +15,38 @@ namespace TSA_V ...@@ -13,11 +15,38 @@ namespace TSA_V
private static Process process = null; private static Process process = null;
public static void StartClient() public static void StartClient()
{ {
//判断是否启用
if (!Setting_NInit.Device_HandsVideo)
{
LogUtil.info($"hand start : Device_HandsVideo={Setting_NInit.Device_HandsVideo}");
return;
}
if( Setting_NInit.Hand_ServerPort <= 0)
{
LogUtil.info($"hand start : Hand_ServerPort={Setting_NInit.Hand_ServerPort}");
return;
}
int count = GetCameraCount();
if(count<=0)
{
LogUtil.info($"hand start : 未查询到相机");
return;
}
//脚本所在地址 //脚本所在地址
string CurrentPath = System.IO.Directory.GetCurrentDirectory(); string CurrentPath = System.IO.Directory.GetCurrentDirectory();
string ScriptFileName = Application.StartupPath + @"\hands\defMTest.py"; ; string ScriptFileName = Application.StartupPath + @"\hands\defMTest.py";
if(!File.Exists(ScriptFileName))
{
LogUtil.error($"hand start : 文件{ScriptFileName}不存在");
return;
}
string sArguments = ScriptFileName; //脚本执行文件 string sArguments = ScriptFileName; //脚本执行文件
//用于执行程序最后的 //用于执行程序最后的
...@@ -41,16 +70,37 @@ namespace TSA_V ...@@ -41,16 +70,37 @@ namespace TSA_V
process.BeginOutputReadLine(); process.BeginOutputReadLine();
process.OutputDataReceived += new DataReceivedEventHandler(p_OutputDataReceivedText); process.OutputDataReceived += new DataReceivedEventHandler(p_OutputDataReceivedText);
LogUtil.info($"defMTest.py启动成功:{process.ProcessName},{process.Id}");
//process.WaitForExit(); //等待程序执行完退出进程 //process.WaitForExit(); //等待程序执行完退出进程
//process.Close(); //process.Close();
} }
catch (Win32Exception e) catch (Win32Exception e)
{ {
LogUtil.error("出错:" + e.ToString()); LogUtil.error($"文件{ScriptFileName}启动出错:" + e.ToString());
} }
} }
private static int GetCameraCount()
{
int cameraCount = 0;
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PnPEntity WHERE Caption LIKE '%camera%'");
ManagementObjectCollection devices = searcher.Get();
foreach (ManagementObject device in devices)
{
LogUtil.info("devices : " + device.Path.Path);
cameraCount++;
}
}
catch (Exception ex)
{
LogUtil.error("出错:" + ex.ToString());
}
LogUtil.info("Number of built-in cameras: " + cameraCount);
return cameraCount;
}
public static void pythonDetector4(string[] strArr) public static void pythonDetector4(string[] strArr)
{ {
...@@ -58,8 +108,15 @@ namespace TSA_V ...@@ -58,8 +108,15 @@ namespace TSA_V
private static void p_OutputDataReceivedText(object sender, DataReceivedEventArgs e) private static void p_OutputDataReceivedText(object sender, DataReceivedEventArgs e)
{ {
if (!string.IsNullOrEmpty(e.Data)) if (!string.IsNullOrEmpty(e.Data))
{ {
LogUtil.info("pyLog: " + e.Data); if (e.Data.EndsWith("200"))
{
LogUtil.debug("pyLog: " + e.Data);
}
else
{
LogUtil.info("pyLog: " + e.Data);
}
} }
} }
......
...@@ -6,6 +6,8 @@ import base64 ...@@ -6,6 +6,8 @@ import base64
import requests import requests
import json import json
import configparser import configparser
import ctypes
import sys
#from PIL import Image #from PIL import Image
#import io #import io
#import numpy as np #import numpy as np
...@@ -134,7 +136,16 @@ class handDetector: ...@@ -134,7 +136,16 @@ class handDetector:
# 处理其他异常 # 处理其他异常
print(f"readconfig error: {str(e)}") print(f"readconfig error: {str(e)}")
return [0,"http://localhost:8765"] return [0,"http://localhost:8765"]
def is_admin():
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except:
return False
def main(): def main():
if(is_admin()==False):
print("not admin , need run as admin")
ctypes.windll.shell32.ShellExecuteW(None,"runas", sys.executable, __file__, None, 1)
return
input_str="" input_str=""
# api_url="http://localhost:8765/rest/api/v1/imgUpload" # api_url="http://localhost:8765/rest/api/v1/imgUpload"
# camera_index=0 # camera_index=0
...@@ -148,22 +159,27 @@ def main(): ...@@ -148,22 +159,27 @@ def main():
detector.__init__(False,2,0.5,0.5) detector.__init__(False,2,0.5,0.5)
while True: while True:
success, img = cap.read() success, img = cap.read()
img = detector.findHands(img) if(success):
lmList = detector.findPosition(img) img = detector.findHands(img)
# if len(lmList) != 0: lmList = detector.findPosition(img)
# print(lmList[4]) # if len(lmList) != 0:
# cTime = time.time() # print(lmList[4])
# fps = 1 / (cTime - pTime) # cTime = time.time()
# pTime = cTime # fps = 1 / (cTime - pTime)
# cv2.imwrite("1.jpg",img) # pTime = cTime
# cv2.putText(img, str(int(fps)), (10, 70), cv2.FONT_HERSHEY_PLAIN, 3,(255, 0, 255), 3) # cv2.imwrite("1.jpg",img)
input_str=detector.image_to_base64(img) # cv2.putText(img, str(int(fps)), (10, 70), cv2.FONT_HERSHEY_PLAIN, 3,(255, 0, 255), 3)
# detector.save_input_to_txt(input_str, "input.txt") input_str=detector.image_to_base64(img)
# detector.base64_to_image(input_str,"input.jpg") # detector.save_input_to_txt(input_str, "input.txt")
detector.post_string_to_http_api(input_str,api_url) # detector.base64_to_image(input_str,"input.jpg")
# cv2.imshow("Image", img) detector.post_string_to_http_api(input_str,api_url)
# cv2.waitKey(1) # cv2.imshow("Image", img)
# cv2.waitKey(1)
else:
print("camera read error")
break
time.sleep(0.2) time.sleep(0.2)
if __name__ == "__main__": if __name__ == "__main__":
main() main()
opencv-python== 4.8.1.78
opencv-contrib-python==4.9.0.80
mediapipe==0.8.11
\ No newline at end of file \ No newline at end of file
此文件类型无法预览
20240401 20240401
新分支,修改离线编程。 新分支,修改离线编程。
增加手势识别功能。
pip install --no-index --find-links=./packages -r requirements.txt
pip download --requirement requirements.txt --platform any --only-binary=:all: --destination-directory packages
pip freeze > requirements.txt
pip install -r requirements.txt
pip
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!