Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
李娜
/
Line-Smart-Workstation
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit e1067ae1
由
LN
编写于
2024-04-10 14:39:34 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
1
1 个父辈
9ff72174
隐藏空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
173 行增加
和
55 行删除
DeviceLibrary/tool/HVideoManager.cs
TSA-V/FrmMenu.cs
TSA-V/Program.cs
TSA-V/Properties/app.manifest
TSA-V/Smart-Workstation.csproj
TSA-V/hands/HandClientManager.cs
TSA-V/hands/defMTest.py
TSA-V/hands/requirements-.txt
TSA-V/hands/requirements.txt
TSA-V/记录.txt
DeviceLibrary/tool/HVideoManager.cs
查看文件 @
e1067ae
...
...
@@ -32,7 +32,7 @@ namespace TSA_V.DeviceLibrary
LogUtil
.
info
(
"HTTP服务已启动,正在监听9876端口..."
);
Task
.
Factory
.
StartNew
(()
=>
{
Run
();
Run
();
});
}
return
true
;
...
...
TSA-V/FrmMenu.cs
查看文件 @
e1067ae
...
...
@@ -465,27 +465,42 @@ namespace TSA_V
{
//AccAOI.FrmAoiSetting frmAoiSetting = new FrmAoiSetting();
//frmAoiSetting.Show();
string
createnew
=
ResourceCulture
.
GetString
(
ResourceCulture
.
CreateNew
,
"新建"
);
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
))
try
{
string
aoiName
=
listb
[
frma
.
SelectIndex
];
string
path
=
Application
.
StartupPath
+
ConfigAppSettings
.
GetValue
(
Setting_Init
.
AOIFileConfig
);
string
fileName
=
""
;
if
(!
aoiName
.
Equals
(
""
))
IOManager
.
IOMove
(
IOManager
.
Device_Led
,
IO_VALUE
.
LOW
);
PTipSoundProcess
.
AOIopen
=
true
;
string
createnew
=
ResourceCulture
.
GetString
(
ResourceCulture
.
CreateNew
,
"新建"
);
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
)
fileName
=
""
;
FrmAoiSetting
frm
=
new
FrmAoiSetting
(
fileName
,
null
,
path
);
frm
.
ShowDialog
();
}
catch
(
Exception
ex
)
{
}
finally
{
PTipSoundProcess
.
AOIopen
=
false
;
IOManager
.
IOMove
(
IOManager
.
Device_Led
,
IO_VALUE
.
HIGH
);
}
}
...
...
TSA-V/Program.cs
查看文件 @
e1067ae
...
...
@@ -4,6 +4,7 @@ using System;
using
System.Collections.Generic
;
using
System.Diagnostics
;
using
System.Linq
;
using
System.Management
;
using
System.Runtime.InteropServices
;
using
System.Threading
;
using
System.Threading.Tasks
;
...
...
@@ -51,12 +52,6 @@ namespace TSA_V
[
MTAThread
]
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
{
// 方法四相对于方法三而言应该可以说是一个改进,
...
...
@@ -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
()
+
" "
);
}
...
...
TSA-V/Properties/app.manifest
查看文件 @
e1067ae
...
...
@@ -15,7 +15,8 @@
如果你的应用程序需要此虚拟化来实现向后兼容性,则删除此
元素。
-->
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<!--<requestedExecutionLevel level="asInvoker" uiAccess="false" />-->
</requestedPrivileges>
<applicationRequestMinimum>
<defaultAssemblyRequest permissionSetReference="Custom" />
...
...
TSA-V/Smart-Workstation.csproj
查看文件 @
e1067ae
...
...
@@ -148,6 +148,7 @@
<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>
</Reference>
<Reference Include="System.Management" />
<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>
</Reference>
...
...
@@ -631,6 +632,9 @@
<Content Include="hands\defMTest.py">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="hands\requirements.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="image\alarm2.gif">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
...
...
TSA-V/hands/HandClientManager.cs
查看文件 @
e1067ae
using
HalconDotNet
;
using
System
;
using
System.ComponentModel
;
using
System.Diagnostics
;
using
System.Diagnostics
;
using
System.IO
;
using
System.Management
;
using
System.Windows.Forms
;
using
TSA_V.Common
;
...
...
@@ -13,11 +15,38 @@ namespace TSA_V
private
static
Process
process
=
null
;
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
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
;
//脚本执行文件
//用于执行程序最后的
...
...
@@ -41,16 +70,37 @@ namespace TSA_V
process
.
BeginOutputReadLine
();
process
.
OutputDataReceived
+=
new
DataReceivedEventHandler
(
p_OutputDataReceivedText
);
LogUtil
.
info
(
$
"defMTest.py启动成功:{process.ProcessName},{process.Id}"
);
//process.WaitForExit(); //等待程序执行完退出进程
//process.Close();
}
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
)
{
...
...
@@ -58,8 +108,15 @@ namespace TSA_V
private
static
void
p_OutputDataReceivedText
(
object
sender
,
DataReceivedEventArgs
e
)
{
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
);
}
}
}
...
...
TSA-V/hands/defMTest.py
查看文件 @
e1067ae
...
...
@@ -6,6 +6,8 @@ import base64
import
requests
import
json
import
configparser
import
ctypes
import
sys
#from PIL import Image
#import io
#import numpy as np
...
...
@@ -134,7 +136,16 @@ class handDetector:
# 处理其他异常
print
(
f
"readconfig error: {str(e)}"
)
return
[
0
,
"http://localhost:8765"
]
def
is_admin
():
try
:
return
ctypes
.
windll
.
shell32
.
IsUserAnAdmin
()
except
:
return
False
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
=
""
# api_url="http://localhost:8765/rest/api/v1/imgUpload"
# camera_index=0
...
...
@@ -148,22 +159,27 @@ def main():
detector
.
__init__
(
False
,
2
,
0.5
,
0.5
)
while
True
:
success
,
img
=
cap
.
read
()
img
=
detector
.
findHands
(
img
)
lmList
=
detector
.
findPosition
(
img
)
# if len(lmList) != 0:
# print(lmList[4])
# cTime = time.time()
# fps = 1 / (cTime - pTime)
# pTime = cTime
# cv2.imwrite("1.jpg",img)
# cv2.putText(img, str(int(fps)), (10, 70), cv2.FONT_HERSHEY_PLAIN, 3,(255, 0, 255), 3)
input_str
=
detector
.
image_to_base64
(
img
)
# detector.save_input_to_txt(input_str, "input.txt")
# detector.base64_to_image(input_str,"input.jpg")
detector
.
post_string_to_http_api
(
input_str
,
api_url
)
# cv2.imshow("Image", img)
# cv2.waitKey(1)
if
(
success
):
img
=
detector
.
findHands
(
img
)
lmList
=
detector
.
findPosition
(
img
)
# if len(lmList) != 0:
# print(lmList[4])
# cTime = time.time()
# fps = 1 / (cTime - pTime)
# pTime = cTime
# cv2.imwrite("1.jpg",img)
# cv2.putText(img, str(int(fps)), (10, 70), cv2.FONT_HERSHEY_PLAIN, 3,(255, 0, 255), 3)
input_str
=
detector
.
image_to_base64
(
img
)
# detector.save_input_to_txt(input_str, "input.txt")
# detector.base64_to_image(input_str,"input.jpg")
detector
.
post_string_to_http_api
(
input_str
,
api_url
)
# cv2.imshow("Image", img)
# cv2.waitKey(1)
else
:
print
(
"camera read error"
)
break
time
.
sleep
(
0.2
)
if
__name__
==
"__main__"
:
main
()
TSA-V/hands/requirements-.txt
0 → 100644
查看文件 @
e1067ae
opencv-python== 4.8.1.78
opencv-contrib-python==4.9.0.80
mediapipe==0.8.11
\ No newline at end of file
TSA-V/hands/requirements.txt
0 → 100644
查看文件 @
e1067ae
此文件类型无法预览
TSA-V/记录.txt
查看文件 @
e1067ae
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!
Cancel
请
注册
或
登录
后发表评论