最新程序
This commit is contained in:
parent
c1c0e0697c
commit
132fd6e1b3
@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.8.34316.72
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HisenceYoloDetection", "HisenceYoloDetection\HisenceYoloDetection.csproj", "{0DE28139-2917-4B58-8240-4B4E11114730}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HisenceYoloDetection", "HisenceYoloDetection\HisenceYoloDetection.csproj", "{0DE28139-2917-4B58-8240-4B4E11114730}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XKRS.UI", "XKRS.UI\XKRS.UI.csproj", "{CE386374-EE63-4DF9-8A95-6AECCA4969F8}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -21,6 +23,14 @@ Global
|
||||
{0DE28139-2917-4B58-8240-4B4E11114730}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{0DE28139-2917-4B58-8240-4B4E11114730}.Release|X64.ActiveCfg = Release|X64
|
||||
{0DE28139-2917-4B58-8240-4B4E11114730}.Release|X64.Build.0 = Release|X64
|
||||
{CE386374-EE63-4DF9-8A95-6AECCA4969F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{CE386374-EE63-4DF9-8A95-6AECCA4969F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{CE386374-EE63-4DF9-8A95-6AECCA4969F8}.Debug|X64.ActiveCfg = Debug|Any CPU
|
||||
{CE386374-EE63-4DF9-8A95-6AECCA4969F8}.Debug|X64.Build.0 = Debug|Any CPU
|
||||
{CE386374-EE63-4DF9-8A95-6AECCA4969F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{CE386374-EE63-4DF9-8A95-6AECCA4969F8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{CE386374-EE63-4DF9-8A95-6AECCA4969F8}.Release|X64.ActiveCfg = Release|Any CPU
|
||||
{CE386374-EE63-4DF9-8A95-6AECCA4969F8}.Release|X64.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -31,7 +31,7 @@ namespace HisenceYoloDetection
|
||||
Console.WriteLine($"Error loading image {path1}");
|
||||
return false;
|
||||
}
|
||||
Cv2.Resize(img1, img1, new Size(550, 270));
|
||||
// Cv2.Resize(img1, img1, new Size(550, 270));
|
||||
Mat gimg1 = new Mat();
|
||||
Cv2.CvtColor(img1, gimg1, ColorConversionCodes.BGR2GRAY);
|
||||
Mat thr1 = new Mat();
|
||||
@ -55,7 +55,7 @@ namespace HisenceYoloDetection
|
||||
// Console.WriteLine($"Error loading image {path2}");
|
||||
return false;
|
||||
}
|
||||
Cv2.Resize(img2, img2, new Size(550, 270));
|
||||
// Cv2.Resize(img2, img2, new Size(550, 270));
|
||||
Mat gimg2 = new Mat();
|
||||
Cv2.CvtColor(img2, gimg2, ColorConversionCodes.BGR2GRAY);
|
||||
Mat thr2 = new Mat();
|
||||
@ -93,20 +93,24 @@ namespace HisenceYoloDetection
|
||||
{
|
||||
matCutblack2.SetTo(Scalar.Black);
|
||||
}
|
||||
Cv2.Resize(thr1, thr1, new Size(550, 270));
|
||||
Cv2.Resize(thr2, thr2, new Size(550, 270));
|
||||
DateTime dt= DateTime.Now;
|
||||
string filename= dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString();
|
||||
|
||||
string savePath4 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + "_thr1.png");
|
||||
string savePath4 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename+"_thr1.png");
|
||||
// 保存结果
|
||||
|
||||
Cv2.ImWrite(savePath4, thr1);
|
||||
string savePath3 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + "_thr2.png");
|
||||
string savePath3 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename+"_thr2.png");
|
||||
// 保存结果
|
||||
|
||||
Cv2.ImWrite(savePath3, thr2);
|
||||
|
||||
// 创建卷积核
|
||||
Mat filter1 = new Mat(17, 17, MatType.CV_32F, new Scalar(0));
|
||||
filter1.Row(8).SetTo(new Scalar(0.025));
|
||||
filter1.Col(8).SetTo(new Scalar(0.025));
|
||||
Mat filter1 = new Mat(15, 15, MatType.CV_32F, new Scalar(0));
|
||||
filter1.Row(7).SetTo(new Scalar(0.025));
|
||||
filter1.Col(7).SetTo(new Scalar(0.025));
|
||||
|
||||
// 应用卷积
|
||||
Mat final_result1 = new Mat();
|
||||
@ -175,11 +179,11 @@ namespace HisenceYoloDetection
|
||||
}
|
||||
}
|
||||
|
||||
string savePath2 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + "_Rect.png");
|
||||
string savePath2 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename+"_Rect.png");
|
||||
// 保存结果
|
||||
//string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
|
||||
Cv2.ImWrite(savePath2, img2);
|
||||
string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + "_diff.png");
|
||||
string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename+"_diff.png");
|
||||
// 保存结果
|
||||
//string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png");
|
||||
Cv2.ImWrite(savePath, blackhatImg);
|
||||
@ -188,14 +192,21 @@ namespace HisenceYoloDetection
|
||||
|
||||
public static Rect strChangeRect(string strrect)
|
||||
{
|
||||
string[] rectstr = strrect.Split(",");
|
||||
int areaX = int.Parse(rectstr[0]);
|
||||
int areaY = int.Parse(rectstr[1]);
|
||||
int areaWidth = int.Parse(rectstr[2]);
|
||||
int areaHeight = int.Parse(rectstr[3]);
|
||||
if (!string.IsNullOrEmpty(strrect))
|
||||
{
|
||||
string[] rectstr = strrect.Split(",");
|
||||
int areaX = int.Parse(rectstr[0]);
|
||||
int areaY = int.Parse(rectstr[1]);
|
||||
int areaWidth = int.Parse(rectstr[2]);
|
||||
int areaHeight = int.Parse(rectstr[3]);
|
||||
|
||||
Rect rect = new Rect(areaX, areaY, areaWidth, areaHeight);
|
||||
return rect;
|
||||
}else
|
||||
{
|
||||
return new Rect(0,0,0, 0);
|
||||
}
|
||||
|
||||
Rect rect = new Rect(areaX, areaY, areaWidth, areaHeight);
|
||||
return rect;
|
||||
}
|
||||
|
||||
public static string rectChangeStr(Rect area)
|
||||
|
546
HisenceYoloDetection/HikCamera.cs
Normal file
546
HisenceYoloDetection/HikCamera.cs
Normal file
@ -0,0 +1,546 @@
|
||||
|
||||
using MvCamCtrl.NET;
|
||||
using OpenCvSharp;
|
||||
using OpenCvSharp.Dnn;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace YSDetection
|
||||
{
|
||||
public class HikCamera
|
||||
{
|
||||
[DllImport("kernel32.dll", EntryPoint = "CopyMemory", SetLastError = false)]
|
||||
public static extern void CopyMemory(IntPtr dest, IntPtr src, uint count);
|
||||
|
||||
MyCamera.MV_CC_DEVICE_INFO_LIST m_stDeviceList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
|
||||
int nRet = MyCamera.MV_OK;
|
||||
MyCamera.cbExceptiondelegate pCallBackFunc;
|
||||
private MyCamera device = new MyCamera();
|
||||
bool m_bGrabbing = false;
|
||||
Thread m_hReceiveThread = null;
|
||||
MyCamera.MV_FRAME_OUT_INFO_EX m_stFrameInfo = new MyCamera.MV_FRAME_OUT_INFO_EX();
|
||||
MyCamera.MV_CC_DEVICE_INFO stDevInfo = new MyCamera.MV_CC_DEVICE_INFO();
|
||||
// ch:用于从驱动获取图像的缓存 | en:Buffer for getting image from driver
|
||||
UInt32 m_nBufSizeForDriver = 0;
|
||||
IntPtr m_BufForDriver = IntPtr.Zero;
|
||||
private static Object BufForDriverLock = new Object();
|
||||
bool _snapFlag = false;
|
||||
public MyCamera.cbOutputExdelegate ImageCallback;
|
||||
MyCamera.MV_FRAME_OUT _frame = new MyCamera.MV_FRAME_OUT();
|
||||
readonly ManualResetEvent _snapHandle = new ManualResetEvent(false);
|
||||
|
||||
//ImageSet _bufferImgSet = null;
|
||||
ManualResetEvent _bufferHandle = new ManualResetEvent(false);
|
||||
public Action<DateTime, Mat, int> OnHImageOutput { get; set; }
|
||||
/// <summary>
|
||||
/// 相机拍照计数
|
||||
/// </summary>
|
||||
public volatile int SnapshotCount = 0;
|
||||
public bool Ifsucess = false;
|
||||
public HikCamera() { }
|
||||
private void DeviceListAcq()
|
||||
{
|
||||
// ch:创建设备列表 | en:Create Device List
|
||||
System.GC.Collect();
|
||||
// cbDeviceList.Items.Clear();
|
||||
// m_stDeviceList.nDeviceNum = 0;
|
||||
int nRet = MyCamera.MV_CC_EnumDevices_NET(MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE, ref m_stDeviceList);
|
||||
if (0 != nRet)
|
||||
{
|
||||
// ShowErrorMsg("Enumerate devices fail!", 0);
|
||||
return;
|
||||
}
|
||||
|
||||
// ch:在窗体列表中显示设备名 | en:Display device name in the form list
|
||||
for (int i = 0; i < m_stDeviceList.nDeviceNum; i++)
|
||||
{
|
||||
MyCamera.MV_CC_DEVICE_INFO device = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(m_stDeviceList.pDeviceInfo[i], typeof(MyCamera.MV_CC_DEVICE_INFO));
|
||||
if (device.nTLayerType == MyCamera.MV_GIGE_DEVICE)
|
||||
{
|
||||
MyCamera.MV_GIGE_DEVICE_INFO gigeInfo = (MyCamera.MV_GIGE_DEVICE_INFO)MyCamera.ByteToStruct(device.SpecialInfo.stGigEInfo, typeof(MyCamera.MV_GIGE_DEVICE_INFO));
|
||||
|
||||
if (gigeInfo.chUserDefinedName != "")
|
||||
{
|
||||
//cbDeviceList.Items.Add("GEV: " + gigeInfo.chUserDefinedName + " (" + gigeInfo.chSerialNumber + ")");
|
||||
}
|
||||
else
|
||||
{
|
||||
// cbDeviceList.Items.Add("GEV: " + gigeInfo.chManufacturerName + " " + gigeInfo.chModelName + " (" + gigeInfo.chSerialNumber + ")");
|
||||
}
|
||||
}
|
||||
else if (device.nTLayerType == MyCamera.MV_USB_DEVICE)
|
||||
{
|
||||
MyCamera.MV_USB3_DEVICE_INFO usbInfo = (MyCamera.MV_USB3_DEVICE_INFO)MyCamera.ByteToStruct(device.SpecialInfo.stUsb3VInfo, typeof(MyCamera.MV_USB3_DEVICE_INFO));
|
||||
if (usbInfo.chUserDefinedName != "")
|
||||
{
|
||||
//cbDeviceList.Items.Add("U3V: " + usbInfo.chUserDefinedName + " (" + usbInfo.chSerialNumber + ")");
|
||||
}
|
||||
else
|
||||
{
|
||||
//cbDeviceList.Items.Add("U3V: " + usbInfo.chManufacturerName + " " + usbInfo.chModelName + " (" + usbInfo.chSerialNumber + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ch:选择第一项 | en:Select the first item
|
||||
if (m_stDeviceList.nDeviceNum != 0)
|
||||
{
|
||||
//cbDeviceList.SelectedIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Start()
|
||||
{
|
||||
#region 枚举相机后根据IP地址匹配连接相机
|
||||
//将IP地址转换为字节数组
|
||||
uint intAddress = 0;
|
||||
if (/*(IIConfig.HikCameraType == EnumHelper.HikCameraType.Gige) &&*/ (!string.IsNullOrWhiteSpace("169.254.127.84")))
|
||||
{
|
||||
byte[] IPArr = IPAddress.Parse("169.254.127.84").GetAddressBytes();
|
||||
for (int i = 0; i < IPArr.Length; i++)
|
||||
{
|
||||
intAddress += (uint)(IPArr[i] << (IPArr.Length - 1 - i) * 8);
|
||||
}
|
||||
}
|
||||
|
||||
MyCamera.MV_CC_DEVICE_INFO_LIST m_pDeviceList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
|
||||
|
||||
int nRet = MyCamera.MV_CC_EnumDevices_NET(MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE, ref m_pDeviceList);
|
||||
if (0 != nRet)
|
||||
{
|
||||
throw new Exception($"Enumerate devices fail!");
|
||||
}
|
||||
else
|
||||
{
|
||||
//LogAsync(DateTime.Now, $"搜索获取{m_pDeviceList.nDeviceNum.ToInt()}台相机在线", "");
|
||||
}
|
||||
|
||||
bool isCameraFound = false;
|
||||
for (int i = 0; i < m_pDeviceList.nDeviceNum; i++)
|
||||
{
|
||||
MyCamera.MV_CC_DEVICE_INFO device = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(m_pDeviceList.pDeviceInfo[i], typeof(MyCamera.MV_CC_DEVICE_INFO));
|
||||
IntPtr buffer = IntPtr.Zero;
|
||||
|
||||
if (device.nTLayerType == MyCamera.MV_GIGE_DEVICE)
|
||||
{
|
||||
buffer = Marshal.UnsafeAddrOfPinnedArrayElement(device.SpecialInfo.stGigEInfo, 0);
|
||||
MyCamera.MV_GIGE_DEVICE_INFO stGigEDev = (MyCamera.MV_GIGE_DEVICE_INFO)Marshal.PtrToStructure(buffer, typeof(MyCamera.MV_GIGE_DEVICE_INFO));
|
||||
|
||||
if (stGigEDev.nCurrentIp == intAddress)
|
||||
{
|
||||
stDevInfo = device;
|
||||
isCameraFound = true;
|
||||
}
|
||||
}
|
||||
else if (device.nTLayerType == MyCamera.MV_USB_DEVICE)
|
||||
{
|
||||
//buffer = Marshal.UnsafeAddrOfPinnedArrayElement(device.SpecialInfo.stUsb3VInfo, 0);
|
||||
//MyCamera.MV_USB3_DEVICE_INFO usbInfo = (MyCamera.MV_USB3_DEVICE_INFO)Marshal.PtrToStructure(buffer, typeof(MyCamera.MV_USB3_DEVICE_INFO));
|
||||
//if (usbInfo.chSerialNumber == IConfig.SerialNum)
|
||||
//{
|
||||
// stDevInfo = device;
|
||||
// isCameraFound = true;
|
||||
//}
|
||||
}
|
||||
|
||||
//释放内存空间
|
||||
//Marshal.FreeHGlobal(buffer);
|
||||
|
||||
if (isCameraFound)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!isCameraFound)
|
||||
{
|
||||
throw new Exception($"相机未能找到");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
// ch:创建设备 | en: Create device
|
||||
nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
|
||||
if (MyCamera.MV_OK != nRet)
|
||||
{
|
||||
throw new Exception($"Create device failed:{nRet:x8}");
|
||||
}
|
||||
|
||||
// ch:打开设备 | en:Open device
|
||||
nRet = device.MV_CC_OpenDevice_NET();
|
||||
if (MyCamera.MV_OK != nRet)
|
||||
{
|
||||
throw new Exception($"Open device failed:{nRet:x8}");
|
||||
}
|
||||
|
||||
|
||||
// ch:探测网络最佳包大小(只对GigE相机有效) | en:Detection network optimal package size(It only works for the GigE camera)
|
||||
if (stDevInfo.nTLayerType == MyCamera.MV_GIGE_DEVICE)
|
||||
{
|
||||
int nPacketSize = device.MV_CC_GetOptimalPacketSize_NET();
|
||||
if (nPacketSize > 0)
|
||||
{
|
||||
nRet = device.MV_CC_SetIntValue_NET("GevSCPSPacketSize", (uint)nPacketSize);
|
||||
if (nRet != MyCamera.MV_OK)
|
||||
{
|
||||
Console.WriteLine("Warning: Set Packet Size failed {0:x8}", nRet);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Warning: Get Packet Size failed {0:x8}", nPacketSize);
|
||||
}
|
||||
}
|
||||
|
||||
// ch:注册异常回调函数 | en:Register Exception Callback
|
||||
nRet = device.MV_CC_RegisterExceptionCallBack_NET(pCallBackFunc, IntPtr.Zero);
|
||||
if (MyCamera.MV_OK != nRet)
|
||||
{
|
||||
throw new Exception($"Register expection callback failed:{nRet}");
|
||||
}
|
||||
GC.KeepAlive(pCallBackFunc);
|
||||
|
||||
// ch:设置采集连续模式 | en:Set Continues Aquisition Mode
|
||||
device.MV_CC_SetEnumValue_NET("AcquisitionMode", 2);// ch:工作在连续模式 | en:Acquisition On Continuous Mode
|
||||
if (false)
|
||||
{
|
||||
device.MV_CC_SetEnumValue_NET("TriggerMode", 0); // ch:连续模式 | en:Continuous
|
||||
|
||||
// ch:注册回调函数 | en:Register image callback
|
||||
ImageCallback = new MyCamera.cbOutputExdelegate(ImageCallbackFunc);
|
||||
nRet = device.MV_CC_RegisterImageCallBackEx_NET(ImageCallback, IntPtr.Zero);
|
||||
if (MyCamera.MV_OK != nRet)
|
||||
{
|
||||
throw new Exception("Register image callback failed!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// ch:设置触发模式为off || en:set trigger mode as off
|
||||
nRet = device.MV_CC_SetEnumValue_NET("TriggerMode", 1);
|
||||
if (MyCamera.MV_OK != nRet)
|
||||
{
|
||||
throw new Exception("Set TriggerMode failed!");
|
||||
}
|
||||
|
||||
if (false)
|
||||
{
|
||||
// ch:触发源选择:0 - Line0; | en:Trigger source select:0 - Line0;
|
||||
// 1 - Line1;
|
||||
// 2 - Line2;
|
||||
// 3 - Line3;
|
||||
// 4 - Counter;
|
||||
// 7 - Software;
|
||||
nRet = device.MV_CC_SetEnumValue_NET("TriggerSource", 0);
|
||||
if (MyCamera.MV_OK != nRet)
|
||||
{
|
||||
throw new Exception("Set Line0 Trigger failed!");
|
||||
}
|
||||
|
||||
// ch:注册回调函数 | en:Register image callback
|
||||
ImageCallback = new MyCamera.cbOutputExdelegate(ImageCallbackFunc);
|
||||
nRet = device.MV_CC_RegisterImageCallBackEx_NET(ImageCallback, IntPtr.Zero);
|
||||
if (MyCamera.MV_OK != nRet)
|
||||
{
|
||||
throw new Exception("Register image callback failed!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nRet = device.MV_CC_SetEnumValue_NET("TriggerSource", 7);
|
||||
if (MyCamera.MV_OK != nRet)
|
||||
{
|
||||
throw new Exception("Set Software Trigger failed!");
|
||||
}
|
||||
}
|
||||
}
|
||||
// ch:开启抓图 || en: start grab image
|
||||
nRet = device.MV_CC_StartGrabbing_NET();
|
||||
if (MyCamera.MV_OK != nRet)
|
||||
{
|
||||
throw new Exception($"Start grabbing failed:{nRet:x8}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Ifsucess = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public void Stop()
|
||||
{
|
||||
if(Ifsucess)
|
||||
{
|
||||
// IIConfig.PropertyChanged -= IIConfig_PropertyChanged;
|
||||
|
||||
|
||||
// ch:停止抓图 | en:Stop grab image
|
||||
nRet = device.MV_CC_StopGrabbing_NET();
|
||||
if (MyCamera.MV_OK != nRet)
|
||||
{
|
||||
throw new Exception($"Stop grabbing failed{nRet:x8}");
|
||||
}
|
||||
|
||||
// ch:关闭设备 | en:Close device
|
||||
nRet = device.MV_CC_CloseDevice_NET();
|
||||
if (MyCamera.MV_OK != nRet)
|
||||
{
|
||||
throw new Exception($"Close device failed{nRet:x8}");
|
||||
}
|
||||
|
||||
// ch:销毁设备 | en:Destroy device
|
||||
nRet = device.MV_CC_DestroyDevice_NET();
|
||||
if (MyCamera.MV_OK != nRet)
|
||||
{
|
||||
throw new Exception($"Destroy device failed:{nRet:x8}");
|
||||
}
|
||||
}
|
||||
Ifsucess = false;
|
||||
|
||||
|
||||
}
|
||||
void ImageCallbackFunc(IntPtr pData, ref MyCamera.MV_FRAME_OUT_INFO_EX pFrameInfo, IntPtr pUser)
|
||||
{
|
||||
try
|
||||
{
|
||||
// if (false)
|
||||
// {
|
||||
// // SnapshotCount++;
|
||||
// Interlocked.Increment(ref SnapshotCount);
|
||||
|
||||
|
||||
// // Console.WriteLine($">>>> {IIConfig.Name} 相机硬触发...");
|
||||
|
||||
// //LogAsync(DateTime.Now, LogLevel.Information, $"{Name}相机硬触发");
|
||||
// //Stopwatch sw = new Stopwatch();
|
||||
// //sw.Start();
|
||||
|
||||
// int nWidth = pFrameInfo.nWidth;
|
||||
// int nHeight = pFrameInfo.nHeight;
|
||||
|
||||
// //HImage hImage = new HImage();
|
||||
// //HObject Hobj = new HObject();
|
||||
// //IntPtr pTemp = IntPtr.Zero;
|
||||
// //hImage.GenImage1((HTuple)"byte", nWidth, nHeight, pData);
|
||||
|
||||
// //var imgSet = new ImageSet
|
||||
// //{
|
||||
// // HImage = hImage,
|
||||
// // ImageSaveOption = IConfig.ImageSaveOption.Copy()
|
||||
// //};
|
||||
|
||||
|
||||
// //测试图片颜色
|
||||
|
||||
// //if (IsColor(pFrameInfo.enPixelType))
|
||||
// //{
|
||||
// // //pFrameInfo.enPixelType = MyCamera.MvGvspPixelType.PixelType_Gvsp_RGB8_Packed;
|
||||
|
||||
// // // 彩色图
|
||||
// // switch (pFrameInfo.enPixelType)
|
||||
// // {
|
||||
// // case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGR8:
|
||||
// // imgSet.HImage = imgSet.HImage.CfaToRgb("bayer_gr", "bilinear");
|
||||
// // imgSet.HImage = imgSet.HImage.ConvertHObjectToHImage();
|
||||
// // break;
|
||||
// // case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerRG8:
|
||||
// // imgSet.HImage = imgSet.HImage.CfaToRgb("bayer_rg", "bilinear");
|
||||
// // imgSet.HImage = imgSet.HImage.ConvertHObjectToHImage();
|
||||
// // break;
|
||||
// // case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGB8:
|
||||
// // imgSet.HImage = imgSet.HImage.CfaToRgb("bayer_gb", "bilinear");
|
||||
// // imgSet.HImage = imgSet.HImage.ConvertHObjectToHImage();
|
||||
// // break;
|
||||
// // case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerBG8:
|
||||
// // imgSet.HImage = imgSet.HImage.CfaToRgb("bayer_bg", "bilinear");
|
||||
// // imgSet.HImage = imgSet.HImage.ConvertHObjectToHImage();
|
||||
// // break;
|
||||
// // }
|
||||
|
||||
// //}
|
||||
|
||||
|
||||
// if (pFrameInfo.enPixelType == MyCamera.MvGvspPixelType.PixelType_Gvsp_RGB8_Packed)
|
||||
// {
|
||||
// // Console.WriteLine("image pixel format is rgb8...");
|
||||
// //pTemp = pData;
|
||||
// //HOperatorSet.GenImageInterleaved(out Hobj, (HTuple)pTemp, (HTuple)"rgb", (HTuple)pFrameInfo.nWidth, (HTuple)pFrameInfo.nHeight, -1, "byte", 0, 0, 0, 0, -1, 0);
|
||||
// //HobjectToRGBHimage(Hobj, ref hImage);
|
||||
// }
|
||||
|
||||
// // Console.WriteLine($">>>> {IIConfig.Name} 相机数据转换完成 ...");
|
||||
|
||||
// //if (!IsMonoData(pFrameInfo.enPixelType))
|
||||
// //{
|
||||
// // pImageBuf = Marshal.AllocHGlobal((int)stFrameInfo.nWidth * stFrameInfo.nHeight * 3);
|
||||
// // HOperatorSet.GenImageInterleaved(out Hobj, (HTuple)pTemp, (HTuple)"rgb", (HTuple)pFrameInfo.nWidth, (HTuple)pFrameInfo.nHeight, -1, "byte", 0, 0, 0, 0, -1, 0);
|
||||
// //}
|
||||
|
||||
|
||||
//#if false
|
||||
// if (pFrameInfo.enPixelType == MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono8)
|
||||
// {
|
||||
// //加入内部队列
|
||||
// InitialImageSet(imgSet);
|
||||
|
||||
// //业务图片处理加入外部队列
|
||||
// var outImgSet = CopyImageSet(imgSet);
|
||||
|
||||
// if (IIConfig.IsDirectHardwareTrigger)
|
||||
// {
|
||||
// //传感器直接触发 收到图片后 传出
|
||||
// OnHImageOutput?.Invoke(DateTime.Now, this, outImgSet);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// _bufferImgSet = outImgSet;
|
||||
// //_bufferImgSetQueue.Enqueue(outImgSet);
|
||||
// _bufferHandle.Set();
|
||||
// }
|
||||
// ClearImageSet(imgSet);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Console.WriteLine($">>>> 像素类型:{pFrameInfo.enPixelType}");
|
||||
// }
|
||||
|
||||
//#else
|
||||
// //加入内部队列
|
||||
// InitialImageSet(imgSet);
|
||||
|
||||
// //业务图片处理加入外部队列
|
||||
// var outImgSet = CopyImageSet(imgSet);
|
||||
|
||||
|
||||
// // LogAsync(DateTime.Now, LogLevel.Information, $"{Name}相机取像, 次数:{SnapshotCount}");
|
||||
|
||||
// // Console.WriteLine($">>>> {IIConfig.Name} 相机回调 OnHImageOutput ...");
|
||||
// if (IIConfig.IsDirectHardwareTrigger)
|
||||
// {
|
||||
// // 传感器直接触发 收到图片后 传出
|
||||
// OnHImageOutput?.Invoke(DateTime.Now, this, outImgSet);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// _bufferImgSet = outImgSet;
|
||||
// // _bufferImgSetQueue.Enqueue(outImgSet);
|
||||
// _bufferHandle.Set();
|
||||
// }
|
||||
// //处理完图片 会清理内部队列的图像
|
||||
// DisplayAndSaveOriginImage(imgSet.Id);
|
||||
// //ClearImageSet(imgSet);
|
||||
//#endif
|
||||
// }
|
||||
//else
|
||||
//{
|
||||
if (_snapFlag)
|
||||
{
|
||||
_snapFlag = false;
|
||||
_frame = new MyCamera.MV_FRAME_OUT
|
||||
{
|
||||
stFrameInfo = pFrameInfo,
|
||||
pBufAddr = pData
|
||||
};
|
||||
_snapHandle.Set();
|
||||
}
|
||||
// }
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//LogAsync(DateTime.Now, LogLevel.Exception, $"{Name}相机取像异常,{ex.GetExceptionMessage()}");
|
||||
}
|
||||
}
|
||||
public void Snapshot()
|
||||
{
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
// ImageSet set = new ImageSet();
|
||||
// set.SnapshotCount = SnapshotCount;
|
||||
// set.SnapshotFileName = SnapshotFileNames;
|
||||
|
||||
//InitialImageSet(set);
|
||||
MyCamera.MV_FRAME_OUT frameInfo = new MyCamera.MV_FRAME_OUT();
|
||||
nRet = MyCamera.MV_OK;
|
||||
if (true)
|
||||
{
|
||||
// ch: 触发命令 || en: Trigger command
|
||||
nRet = device.MV_CC_SetCommandValue_NET("TriggerSoftware");
|
||||
if (MyCamera.MV_OK != nRet)
|
||||
{
|
||||
throw new Exception($"相机拍照触发失败:{nRet}");
|
||||
}
|
||||
|
||||
nRet = device.MV_CC_GetImageBuffer_NET(ref frameInfo, 1000);
|
||||
nRet = device.MV_CC_FreeImageBuffer_NET(ref frameInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
_snapHandle.Reset();
|
||||
_snapFlag = true;
|
||||
_snapHandle.WaitOne();
|
||||
//lock (_imgCallBackLock)
|
||||
{
|
||||
frameInfo.stFrameInfo = _frame.stFrameInfo;
|
||||
frameInfo.pBufAddr = _frame.pBufAddr;
|
||||
}
|
||||
}
|
||||
|
||||
// ch:获取一帧图像 | en:Get one image
|
||||
if (MyCamera.MV_OK == nRet)
|
||||
{
|
||||
if (frameInfo.pBufAddr != IntPtr.Zero)
|
||||
{
|
||||
if (nRet == MyCamera.MV_OK)
|
||||
{
|
||||
var pFrameInfo = frameInfo.stFrameInfo;
|
||||
Mat mat=new Mat(pFrameInfo.nHeight, pFrameInfo.nWidth, MatType.CV_8UC3, frameInfo.pBufAddr);
|
||||
OnHImageOutput?.Invoke(DateTime.Now, mat, SnapshotCount);
|
||||
mat.ImWrite("D://123.jpg");
|
||||
//HImage hImage = new HImage();
|
||||
//HObject Hobj = new HObject();
|
||||
//IntPtr pTemp = IntPtr.Zero;
|
||||
//hImage.GenImage1("byte", pFrameInfo.nWidth, pFrameInfo.nHeight, frameInfo.pBufAddr);
|
||||
|
||||
////hImage.ConvertHImageTo16GrayBitmap();
|
||||
//var imgSet = new ImageSet
|
||||
//{
|
||||
// HImage = hImage,
|
||||
// ImageSaveOption = IConfig.ImageSaveOption.Copy()
|
||||
//};
|
||||
//if (pFrameInfo.enPixelType == MyCamera.MvGvspPixelType.PixelType_Gvsp_RGB8_Packed)
|
||||
//{
|
||||
// // Console.WriteLine("image pixel format is rgb8...");
|
||||
// pTemp = frameInfo.pBufAddr;
|
||||
// HOperatorSet.GenImageInterleaved(out Hobj, (HTuple)pTemp, (HTuple)"rgb", (HTuple)pFrameInfo.nWidth, (HTuple)pFrameInfo.nHeight, -1, "byte", 0, 0, 0, 0, -1, 0);
|
||||
// HobjectToRGBHimage(Hobj, ref hImage);
|
||||
//}
|
||||
|
||||
|
||||
//加入内部队列
|
||||
//InitialImageSet(imgSet);
|
||||
|
||||
////业务图片处理加入外部队列
|
||||
//var outImgSet = CopyImageSet(imgSet);
|
||||
//OnHImageOutput?.Invoke(DateTime.Now, this, outImgSet);
|
||||
//LogAsync(DateTime.Now, LogLevel.Information, $"{Name}相机取像, 次数:{SnapshotCount}");
|
||||
//DisplayAndSaveOriginImage(imgSet.Id);
|
||||
//HikToBitmap(pFrameInfo, frameInfo.pBufAddr);
|
||||
//Generate8GrayImageByPointer((int)nWidth, (int)nHeight, frameInfo.pBufAddr, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"Grap Image Failed:{nRet:x8}");
|
||||
}
|
||||
|
||||
sw.Stop();
|
||||
//LogAsync(DateTime.Now, LogLevel.Information, $"取像耗时:{sw.ElapsedMilliseconds} ms");
|
||||
}
|
||||
}
|
||||
}
|
893
HisenceYoloDetection/HikCameraDriver.cs
Normal file
893
HisenceYoloDetection/HikCameraDriver.cs
Normal file
@ -0,0 +1,893 @@
|
||||
|
||||
using MvCamCtrl.NET;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Net;
|
||||
using OpenCvSharp;
|
||||
using DVPCameraType;
|
||||
using System.Reflection.Metadata;
|
||||
|
||||
|
||||
|
||||
|
||||
//[Device("HikCamera", "海康相机", EnumHelper.DeviceAttributeType.Device)]
|
||||
public class HikCameraDriver
|
||||
{
|
||||
|
||||
#region CameraBase
|
||||
//public IOperationConfig GetOperationConfigFromDevice()
|
||||
// {
|
||||
// HikCameraOperationConfig opConfig = new HikCameraOperationConfig();
|
||||
|
||||
// MyCamera.MVCC_FLOATVALUE stParam = new MyCamera.MVCC_FLOATVALUE();
|
||||
// int nRet = device.MV_CC_GetFloatValue_NET("ExposureTime", ref stParam);
|
||||
// if (MyCamera.MV_OK == nRet)
|
||||
// {
|
||||
// opConfig.Exposure = stParam.fCurValue;
|
||||
// }
|
||||
|
||||
// nRet = device.MV_CC_GetFloatValue_NET("Gain", ref stParam);
|
||||
// if (MyCamera.MV_OK == nRet)
|
||||
// {
|
||||
// opConfig.Gain = stParam.fCurValue;
|
||||
// }
|
||||
|
||||
// return opConfig;
|
||||
// }
|
||||
public bool IfSuccess = false;
|
||||
|
||||
float _lastExposure = 0;
|
||||
float _lastGain = 0;
|
||||
/// <summary>
|
||||
/// 相机拍照计数
|
||||
/// </summary>
|
||||
public volatile int SnapshotCount = 0;
|
||||
//public void UploadOperationConfig(IOperationConfig config)
|
||||
//{
|
||||
// if (CurrentState != EnumHelper.DeviceState.DSOpen)
|
||||
// return;
|
||||
|
||||
// CameraOprerationConfigBase opConfig = config as CameraOprerationConfigBase;
|
||||
|
||||
// int nRet;
|
||||
|
||||
// if (opConfig.Exposure != 0 && opConfig.Exposure != _lastExposure)
|
||||
// {
|
||||
// device.MV_CC_SetEnumValue_NET("ExposureAuto", 0);
|
||||
// nRet = device.MV_CC_SetFloatValue_NET("ExposureTime", opConfig.Exposure);
|
||||
// if (nRet != MyCamera.MV_OK)
|
||||
// {
|
||||
// throw new Exception($"Exposure set failed:{nRet}");
|
||||
// }
|
||||
|
||||
// _lastExposure = opConfig.Exposure;
|
||||
// }
|
||||
|
||||
// if (opConfig.Gain != 0 && opConfig.Gain != _lastGain)
|
||||
// {
|
||||
// device.MV_CC_SetEnumValue_NET("GainAuto", 0);
|
||||
// nRet = device.MV_CC_SetFloatValue_NET("Gain", opConfig.Gain);
|
||||
// if (nRet != MyCamera.MV_OK)
|
||||
// {
|
||||
// throw new Exception($"Gain set failed:{nRet}");
|
||||
// }
|
||||
|
||||
// _lastGain = opConfig.Gain;
|
||||
// }
|
||||
//}
|
||||
public Action<DateTime, Mat, int> OnHImageOutput { get; set; }
|
||||
|
||||
public void Init()
|
||||
{
|
||||
|
||||
//_bufferImgSetQueue = new ConcurrentQueue<ImageSet>();
|
||||
//_bufferImgSet = new ImageSet();
|
||||
//pCallBackFunc = new MyCamera.cbExceptiondelegate(cbExceptiondelegate);
|
||||
#if false
|
||||
#region 根据IP连接相机
|
||||
|
||||
stDevInfo.nTLayerType = MyCamera.MV_GIGE_DEVICE;
|
||||
MyCamera.MV_GIGE_DEVICE_INFO stGigEDev = new MyCamera.MV_GIGE_DEVICE_INFO();
|
||||
//string strCurrentIp = IIConfig.CameraIP;// ch:需要连接的相机ip(根据实际填充)
|
||||
|
||||
//string strNetExport = IIConfig.ComputerIP; // ch:相机对应的网卡ip(根据实际填充)
|
||||
|
||||
string strCurrentIp = "192.168.1.21";// ch:需要连接的相机ip(根据实际填充)
|
||||
|
||||
string strNetExport = "192.168.1.20"; // ch:相机对应的网卡ip(根据实际填充)
|
||||
|
||||
var parts = strCurrentIp.Split('.');
|
||||
int nIp1 = Convert.ToInt32(parts[0]);
|
||||
int nIp2 = Convert.ToInt32(parts[1]);
|
||||
int nIp3 = Convert.ToInt32(parts[2]);
|
||||
int nIp4 = Convert.ToInt32(parts[3]);
|
||||
stGigEDev.nCurrentIp = (uint)((nIp1 << 24) | (nIp2 << 16) | (nIp3 << 8) | nIp4);
|
||||
|
||||
parts = strNetExport.Split('.');
|
||||
nIp1 = Convert.ToInt32(parts[0]);
|
||||
nIp2 = Convert.ToInt32(parts[1]);
|
||||
nIp3 = Convert.ToInt32(parts[2]);
|
||||
nIp4 = Convert.ToInt32(parts[3]);
|
||||
stGigEDev.nNetExport = (uint)((nIp1 << 24) | (nIp2 << 16) | (nIp3 << 8) | nIp4);
|
||||
|
||||
IntPtr stGigeInfoPtr = Marshal.AllocHGlobal(216);
|
||||
Marshal.StructureToPtr(stGigEDev, stGigeInfoPtr, false);
|
||||
stDevInfo.SpecialInfo.stGigEInfo = new Byte[540];
|
||||
Marshal.Copy(stGigeInfoPtr, stDevInfo.SpecialInfo.stGigEInfo, 0, 540);
|
||||
//释放内存空间
|
||||
Marshal.FreeHGlobal(stGigeInfoPtr);
|
||||
|
||||
#endregion
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
protected void Pause()
|
||||
{
|
||||
}
|
||||
|
||||
protected void Resume()
|
||||
{
|
||||
}
|
||||
|
||||
public void Start(string v)
|
||||
{
|
||||
#region 枚举相机后根据IP地址匹配连接相机
|
||||
//将IP地址转换为字节数组
|
||||
uint intAddress = 0;
|
||||
if (/*(IIConfig.HikCameraType == EnumHelper.HikCameraType.Gige) &&*/ (!string.IsNullOrWhiteSpace("192.168.1.21")))
|
||||
{
|
||||
byte[] IPArr = IPAddress.Parse("192.168.1.21").GetAddressBytes();
|
||||
for (int i = 0; i < IPArr.Length; i++)
|
||||
{
|
||||
intAddress += (uint)(IPArr[i] << (IPArr.Length - 1 - i) * 8);
|
||||
}
|
||||
}
|
||||
|
||||
MyCamera.MV_CC_DEVICE_INFO_LIST m_pDeviceList = new MyCamera.MV_CC_DEVICE_INFO_LIST();
|
||||
|
||||
int nRet = MyCamera.MV_CC_EnumDevices_NET(MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE, ref m_pDeviceList);
|
||||
if (0 != nRet)
|
||||
{
|
||||
throw new Exception($"Enumerate devices fail!");
|
||||
}
|
||||
else
|
||||
{
|
||||
//LogAsync(DateTime.Now, $"搜索获取{m_pDeviceList.nDeviceNum.ToInt()}台相机在线", "");
|
||||
}
|
||||
|
||||
bool isCameraFound = false;
|
||||
for (int i = 0; i < m_pDeviceList.nDeviceNum; i++)
|
||||
{
|
||||
MyCamera.MV_CC_DEVICE_INFO device = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(m_pDeviceList.pDeviceInfo[i], typeof(MyCamera.MV_CC_DEVICE_INFO));
|
||||
IntPtr buffer = IntPtr.Zero;
|
||||
|
||||
if (device.nTLayerType == MyCamera.MV_GIGE_DEVICE)
|
||||
{
|
||||
buffer = Marshal.UnsafeAddrOfPinnedArrayElement(device.SpecialInfo.stGigEInfo, 0);
|
||||
MyCamera.MV_GIGE_DEVICE_INFO stGigEDev = (MyCamera.MV_GIGE_DEVICE_INFO)Marshal.PtrToStructure(buffer, typeof(MyCamera.MV_GIGE_DEVICE_INFO));
|
||||
|
||||
if (stGigEDev.nCurrentIp == intAddress)
|
||||
{
|
||||
stDevInfo = device;
|
||||
isCameraFound = true;
|
||||
}
|
||||
}
|
||||
else if (device.nTLayerType == MyCamera.MV_USB_DEVICE)
|
||||
{
|
||||
//buffer = Marshal.UnsafeAddrOfPinnedArrayElement(device.SpecialInfo.stUsb3VInfo, 0);
|
||||
//MyCamera.MV_USB3_DEVICE_INFO usbInfo = (MyCamera.MV_USB3_DEVICE_INFO)Marshal.PtrToStructure(buffer, typeof(MyCamera.MV_USB3_DEVICE_INFO));
|
||||
//if (usbInfo.chSerialNumber == IConfig.SerialNum)
|
||||
//{
|
||||
// stDevInfo = device;
|
||||
// isCameraFound = true;
|
||||
//}
|
||||
}
|
||||
|
||||
//释放内存空间
|
||||
//Marshal.FreeHGlobal(buffer);
|
||||
|
||||
if (isCameraFound)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!isCameraFound)
|
||||
{
|
||||
throw new Exception($"相机未能找到");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
// ch:创建设备 | en: Create device
|
||||
nRet = device.MV_CC_CreateDevice_NET(ref stDevInfo);
|
||||
if (MyCamera.MV_OK != nRet)
|
||||
{
|
||||
throw new Exception($"Create device failed:{nRet:x8}");
|
||||
}
|
||||
|
||||
// ch:打开设备 | en:Open device
|
||||
nRet = device.MV_CC_OpenDevice_NET();
|
||||
if (MyCamera.MV_OK != nRet)
|
||||
{
|
||||
throw new Exception($"Open device failed:{nRet:x8}");
|
||||
}
|
||||
|
||||
|
||||
// ch:探测网络最佳包大小(只对GigE相机有效) | en:Detection network optimal package size(It only works for the GigE camera)
|
||||
if (stDevInfo.nTLayerType == MyCamera.MV_GIGE_DEVICE)
|
||||
{
|
||||
int nPacketSize = device.MV_CC_GetOptimalPacketSize_NET();
|
||||
if (nPacketSize > 0)
|
||||
{
|
||||
nRet = device.MV_CC_SetIntValue_NET("GevSCPSPacketSize", (uint)nPacketSize);
|
||||
if (nRet != MyCamera.MV_OK)
|
||||
{
|
||||
Console.WriteLine("Warning: Set Packet Size failed {0:x8}", nRet);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Warning: Get Packet Size failed {0:x8}", nPacketSize);
|
||||
}
|
||||
}
|
||||
|
||||
// ch:注册异常回调函数 | en:Register Exception Callback
|
||||
nRet = device.MV_CC_RegisterExceptionCallBack_NET(pCallBackFunc, IntPtr.Zero);
|
||||
if (MyCamera.MV_OK != nRet)
|
||||
{
|
||||
throw new Exception($"Register expection callback failed:{nRet}");
|
||||
}
|
||||
GC.KeepAlive(pCallBackFunc);
|
||||
|
||||
// ch:设置采集连续模式 | en:Set Continues Aquisition Mode
|
||||
device.MV_CC_SetEnumValue_NET("AcquisitionMode", 2);// ch:工作在连续模式 | en:Acquisition On Continuous Mode
|
||||
if (false)
|
||||
{
|
||||
device.MV_CC_SetEnumValue_NET("TriggerMode", 0); // ch:连续模式 | en:Continuous
|
||||
|
||||
// ch:注册回调函数 | en:Register image callback
|
||||
ImageCallback = new MyCamera.cbOutputExdelegate(ImageCallbackFunc);
|
||||
nRet = device.MV_CC_RegisterImageCallBackEx_NET(ImageCallback, IntPtr.Zero);
|
||||
if (MyCamera.MV_OK != nRet)
|
||||
{
|
||||
throw new Exception("Register image callback failed!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// ch:设置触发模式为off || en:set trigger mode as off
|
||||
nRet = device.MV_CC_SetEnumValue_NET("TriggerMode", 1);
|
||||
if (MyCamera.MV_OK != nRet)
|
||||
{
|
||||
throw new Exception("Set TriggerMode failed!");
|
||||
}
|
||||
|
||||
if (false)
|
||||
{
|
||||
// ch:触发源选择:0 - Line0; | en:Trigger source select:0 - Line0;
|
||||
// 1 - Line1;
|
||||
// 2 - Line2;
|
||||
// 3 - Line3;
|
||||
// 4 - Counter;
|
||||
// 7 - Software;
|
||||
nRet = device.MV_CC_SetEnumValue_NET("TriggerSource", 0);
|
||||
if (MyCamera.MV_OK != nRet)
|
||||
{
|
||||
throw new Exception("Set Line0 Trigger failed!");
|
||||
}
|
||||
|
||||
// ch:注册回调函数 | en:Register image callback
|
||||
ImageCallback = new MyCamera.cbOutputExdelegate(ImageCallbackFunc);
|
||||
nRet = device.MV_CC_RegisterImageCallBackEx_NET(ImageCallback, IntPtr.Zero);
|
||||
if (MyCamera.MV_OK != nRet)
|
||||
{
|
||||
throw new Exception("Register image callback failed!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nRet = device.MV_CC_SetEnumValue_NET("TriggerSource", 7);
|
||||
if (MyCamera.MV_OK != nRet)
|
||||
{
|
||||
throw new Exception("Set Software Trigger failed!");
|
||||
}
|
||||
}
|
||||
}
|
||||
// ch:开启抓图 || en: start grab image
|
||||
nRet = device.MV_CC_StartGrabbing_NET();
|
||||
if (MyCamera.MV_OK != nRet)
|
||||
{
|
||||
throw new Exception($"Start grabbing failed:{nRet:x8}");
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
IfSuccess = true;
|
||||
}
|
||||
|
||||
//if (IIConfig.DefaultExposure != 0)
|
||||
//{
|
||||
// device.MV_CC_SetEnumValue_NET("ExposureAuto", 0);
|
||||
// nRet = device.MV_CC_SetFloatValue_NET("ExposureTime", IIConfig.DefaultExposure);
|
||||
// if (nRet != MyCamera.MV_OK)
|
||||
// {
|
||||
// throw new Exception($"Exposure set failed:{nRet}");
|
||||
// }
|
||||
//}
|
||||
//if (IIConfig.Gain >= 0)
|
||||
//{
|
||||
// nRet = device.MV_CC_SetFloatValue_NET("Gain", IIConfig.Gain);
|
||||
// if (nRet != MyCamera.MV_OK)
|
||||
// {
|
||||
// throw new Exception($"Gain set failed:{nRet}");
|
||||
// }
|
||||
//}
|
||||
//// 设置 触发延迟
|
||||
//if (IIConfig.TriggerDelay > 0)
|
||||
//{
|
||||
// nRet = device.MV_CC_SetFloatValue_NET("TriggerDelay", IIConfig.TriggerDelay);
|
||||
// if (MyCamera.MV_OK != nRet)
|
||||
// {
|
||||
// throw new Exception("Set TriggerDelay failed!");
|
||||
// }
|
||||
//}
|
||||
//if (IIConfig.LineDebouncerTime > 0)
|
||||
//{
|
||||
// nRet = device.MV_CC_SetIntValue_NET("LineDebouncerTime", (uint)IIConfig.LineDebouncerTime);
|
||||
// if (nRet != MyCamera.MV_OK)
|
||||
// {
|
||||
// throw new Exception($"LineDebouncerTime set failed:{nRet}");
|
||||
// }
|
||||
//}
|
||||
//IIConfig.PropertyChanged -= IIConfig_PropertyChanged;
|
||||
//IIConfig.PropertyChanged += IIConfig_PropertyChanged;
|
||||
|
||||
}
|
||||
|
||||
private void IIConfig_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == "IsHardwareTrigger" && !false)
|
||||
{
|
||||
// ch:停止抓图 | en:Stop grab image
|
||||
nRet = device.MV_CC_StopGrabbing_NET();
|
||||
if (MyCamera.MV_OK != nRet)
|
||||
{
|
||||
throw new Exception($"Stop grabbing failed{nRet:x8}");
|
||||
}
|
||||
|
||||
if (false)
|
||||
{
|
||||
// ch:触发源选择:0 - Line0; | en:Trigger source select:0 - Line0;
|
||||
// 1 - Line1;
|
||||
// 2 - Line2;
|
||||
// 3 - Line3;
|
||||
// 4 - Counter;
|
||||
// 7 - Software;
|
||||
nRet = device.MV_CC_SetEnumValue_NET("TriggerSource", 0);
|
||||
if (MyCamera.MV_OK != nRet)
|
||||
{
|
||||
throw new Exception("Set Line0 Trigger failed!");
|
||||
}
|
||||
|
||||
// ch:注册回调函数 | en:Register image callback
|
||||
ImageCallback = new MyCamera.cbOutputExdelegate(ImageCallbackFunc);
|
||||
nRet = device.MV_CC_RegisterImageCallBackEx_NET(ImageCallback, IntPtr.Zero);
|
||||
if (MyCamera.MV_OK != nRet)
|
||||
{
|
||||
throw new Exception("Register image callback failed!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nRet = device.MV_CC_SetEnumValue_NET("TriggerSource", 7);
|
||||
if (MyCamera.MV_OK != nRet)
|
||||
{
|
||||
throw new Exception("Set Software Trigger failed!");
|
||||
}
|
||||
}
|
||||
|
||||
// ch:开启抓图 || en: start grab image
|
||||
nRet = device.MV_CC_StartGrabbing_NET();
|
||||
if (MyCamera.MV_OK != nRet)
|
||||
{
|
||||
throw new Exception($"Start grabbing failed:{nRet:x8}");
|
||||
}
|
||||
|
||||
//if (IIConfig.DefaultExposure != 0)
|
||||
//{
|
||||
// device.MV_CC_SetEnumValue_NET("ExposureAuto", 0);
|
||||
// nRet = device.MV_CC_SetFloatValue_NET("ExposureTime", IIConfig.DefaultExposure);
|
||||
// if (nRet != MyCamera.MV_OK)
|
||||
// {
|
||||
// throw new Exception($"Exposure set failed:{nRet}");
|
||||
// }
|
||||
//}
|
||||
//if (IIConfig.Gain >= 0)
|
||||
//{
|
||||
// nRet = device.MV_CC_SetFloatValue_NET("Gain", IIConfig.Gain);
|
||||
// if (nRet != MyCamera.MV_OK)
|
||||
// {
|
||||
// throw new Exception($"Gain set failed:{nRet}");
|
||||
// }
|
||||
//}
|
||||
|
||||
//// 设置 触发延迟
|
||||
//if (IIConfig.TriggerDelay > 0)
|
||||
//{
|
||||
// nRet = device.MV_CC_SetFloatValue_NET("TriggerDelay", IIConfig.TriggerDelay);
|
||||
// if (MyCamera.MV_OK != nRet)
|
||||
// {
|
||||
// throw new Exception("Set TriggerDelay failed!");
|
||||
// }
|
||||
//}
|
||||
//if (IIConfig.LineDebouncerTime > 0)
|
||||
//{
|
||||
// nRet = device.MV_CC_SetIntValue_NET("LineDebouncerTime", (uint)IIConfig.LineDebouncerTime);
|
||||
// if (nRet != MyCamera.MV_OK)
|
||||
// {
|
||||
// throw new Exception($"LineDebouncerTime set failed:{nRet}");
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
// IIConfig.PropertyChanged -= IIConfig_PropertyChanged;
|
||||
|
||||
|
||||
// ch:停止抓图 | en:Stop grab image
|
||||
nRet = device.MV_CC_StopGrabbing_NET();
|
||||
if (MyCamera.MV_OK != nRet)
|
||||
{
|
||||
throw new Exception($"Stop grabbing failed{nRet:x8}");
|
||||
}
|
||||
|
||||
// ch:关闭设备 | en:Close device
|
||||
nRet = device.MV_CC_CloseDevice_NET();
|
||||
if (MyCamera.MV_OK != nRet)
|
||||
{
|
||||
throw new Exception($"Close device failed{nRet:x8}");
|
||||
}
|
||||
|
||||
// ch:销毁设备 | en:Destroy device
|
||||
nRet = device.MV_CC_DestroyDevice_NET();
|
||||
if (MyCamera.MV_OK != nRet)
|
||||
{
|
||||
throw new Exception($"Destroy device failed:{nRet:x8}");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region HikCamera
|
||||
public MyCamera.cbOutputExdelegate ImageCallback;
|
||||
MyCamera.MV_FRAME_OUT _frame = new MyCamera.MV_FRAME_OUT();
|
||||
readonly ManualResetEvent _snapHandle = new ManualResetEvent(false);
|
||||
bool _snapFlag = false;
|
||||
|
||||
//ImageSet _bufferImgSet = null;
|
||||
ManualResetEvent _bufferHandle = new ManualResetEvent(false);
|
||||
//ConcurrentQueue<ImageSet> _bufferImgSetQueue = new ConcurrentQueue<ImageSet>();
|
||||
//volatile ImageSet _bufferImgSet = new ImageSet();
|
||||
|
||||
|
||||
void ImageCallbackFunc(IntPtr pData, ref MyCamera.MV_FRAME_OUT_INFO_EX pFrameInfo, IntPtr pUser)
|
||||
{
|
||||
try
|
||||
{
|
||||
// if (false)
|
||||
// {
|
||||
// // SnapshotCount++;
|
||||
// Interlocked.Increment(ref SnapshotCount);
|
||||
|
||||
|
||||
// // Console.WriteLine($">>>> {IIConfig.Name} 相机硬触发...");
|
||||
|
||||
// //LogAsync(DateTime.Now, LogLevel.Information, $"{Name}相机硬触发");
|
||||
// //Stopwatch sw = new Stopwatch();
|
||||
// //sw.Start();
|
||||
|
||||
// int nWidth = pFrameInfo.nWidth;
|
||||
// int nHeight = pFrameInfo.nHeight;
|
||||
|
||||
// //HImage hImage = new HImage();
|
||||
// //HObject Hobj = new HObject();
|
||||
// //IntPtr pTemp = IntPtr.Zero;
|
||||
// //hImage.GenImage1((HTuple)"byte", nWidth, nHeight, pData);
|
||||
|
||||
// //var imgSet = new ImageSet
|
||||
// //{
|
||||
// // HImage = hImage,
|
||||
// // ImageSaveOption = IConfig.ImageSaveOption.Copy()
|
||||
// //};
|
||||
|
||||
|
||||
// //测试图片颜色
|
||||
|
||||
// //if (IsColor(pFrameInfo.enPixelType))
|
||||
// //{
|
||||
// // //pFrameInfo.enPixelType = MyCamera.MvGvspPixelType.PixelType_Gvsp_RGB8_Packed;
|
||||
|
||||
// // // 彩色图
|
||||
// // switch (pFrameInfo.enPixelType)
|
||||
// // {
|
||||
// // case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGR8:
|
||||
// // imgSet.HImage = imgSet.HImage.CfaToRgb("bayer_gr", "bilinear");
|
||||
// // imgSet.HImage = imgSet.HImage.ConvertHObjectToHImage();
|
||||
// // break;
|
||||
// // case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerRG8:
|
||||
// // imgSet.HImage = imgSet.HImage.CfaToRgb("bayer_rg", "bilinear");
|
||||
// // imgSet.HImage = imgSet.HImage.ConvertHObjectToHImage();
|
||||
// // break;
|
||||
// // case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerGB8:
|
||||
// // imgSet.HImage = imgSet.HImage.CfaToRgb("bayer_gb", "bilinear");
|
||||
// // imgSet.HImage = imgSet.HImage.ConvertHObjectToHImage();
|
||||
// // break;
|
||||
// // case MyCamera.MvGvspPixelType.PixelType_Gvsp_BayerBG8:
|
||||
// // imgSet.HImage = imgSet.HImage.CfaToRgb("bayer_bg", "bilinear");
|
||||
// // imgSet.HImage = imgSet.HImage.ConvertHObjectToHImage();
|
||||
// // break;
|
||||
// // }
|
||||
|
||||
// //}
|
||||
|
||||
|
||||
// if (pFrameInfo.enPixelType == MyCamera.MvGvspPixelType.PixelType_Gvsp_RGB8_Packed)
|
||||
// {
|
||||
// // Console.WriteLine("image pixel format is rgb8...");
|
||||
// //pTemp = pData;
|
||||
// //HOperatorSet.GenImageInterleaved(out Hobj, (HTuple)pTemp, (HTuple)"rgb", (HTuple)pFrameInfo.nWidth, (HTuple)pFrameInfo.nHeight, -1, "byte", 0, 0, 0, 0, -1, 0);
|
||||
// //HobjectToRGBHimage(Hobj, ref hImage);
|
||||
// }
|
||||
|
||||
// // Console.WriteLine($">>>> {IIConfig.Name} 相机数据转换完成 ...");
|
||||
|
||||
// //if (!IsMonoData(pFrameInfo.enPixelType))
|
||||
// //{
|
||||
// // pImageBuf = Marshal.AllocHGlobal((int)stFrameInfo.nWidth * stFrameInfo.nHeight * 3);
|
||||
// // HOperatorSet.GenImageInterleaved(out Hobj, (HTuple)pTemp, (HTuple)"rgb", (HTuple)pFrameInfo.nWidth, (HTuple)pFrameInfo.nHeight, -1, "byte", 0, 0, 0, 0, -1, 0);
|
||||
// //}
|
||||
|
||||
|
||||
//#if false
|
||||
// if (pFrameInfo.enPixelType == MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono8)
|
||||
// {
|
||||
// //加入内部队列
|
||||
// InitialImageSet(imgSet);
|
||||
|
||||
// //业务图片处理加入外部队列
|
||||
// var outImgSet = CopyImageSet(imgSet);
|
||||
|
||||
// if (IIConfig.IsDirectHardwareTrigger)
|
||||
// {
|
||||
// //传感器直接触发 收到图片后 传出
|
||||
// OnHImageOutput?.Invoke(DateTime.Now, this, outImgSet);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// _bufferImgSet = outImgSet;
|
||||
// //_bufferImgSetQueue.Enqueue(outImgSet);
|
||||
// _bufferHandle.Set();
|
||||
// }
|
||||
// ClearImageSet(imgSet);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Console.WriteLine($">>>> 像素类型:{pFrameInfo.enPixelType}");
|
||||
// }
|
||||
|
||||
//#else
|
||||
// //加入内部队列
|
||||
// InitialImageSet(imgSet);
|
||||
|
||||
// //业务图片处理加入外部队列
|
||||
// var outImgSet = CopyImageSet(imgSet);
|
||||
|
||||
|
||||
// // LogAsync(DateTime.Now, LogLevel.Information, $"{Name}相机取像, 次数:{SnapshotCount}");
|
||||
|
||||
// // Console.WriteLine($">>>> {IIConfig.Name} 相机回调 OnHImageOutput ...");
|
||||
// if (IIConfig.IsDirectHardwareTrigger)
|
||||
// {
|
||||
// // 传感器直接触发 收到图片后 传出
|
||||
// OnHImageOutput?.Invoke(DateTime.Now, this, outImgSet);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// _bufferImgSet = outImgSet;
|
||||
// // _bufferImgSetQueue.Enqueue(outImgSet);
|
||||
// _bufferHandle.Set();
|
||||
// }
|
||||
// //处理完图片 会清理内部队列的图像
|
||||
// DisplayAndSaveOriginImage(imgSet.Id);
|
||||
// //ClearImageSet(imgSet);
|
||||
//#endif
|
||||
// }
|
||||
//else
|
||||
//{
|
||||
if (_snapFlag)
|
||||
{
|
||||
_snapFlag = false;
|
||||
_frame = new MyCamera.MV_FRAME_OUT
|
||||
{
|
||||
stFrameInfo = pFrameInfo,
|
||||
pBufAddr = pData
|
||||
};
|
||||
_snapHandle.Set();
|
||||
}
|
||||
// }
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//LogAsync(DateTime.Now, LogLevel.Exception, $"{Name}相机取像异常,{ex.GetExceptionMessage()}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//bool IsColor(MvGvspPixelType enType)
|
||||
//{
|
||||
// switch (enType)
|
||||
// {
|
||||
// case MvGvspPixelType.PixelType_Gvsp_BGR8_Packed:
|
||||
// case MvGvspPixelType.PixelType_Gvsp_YUV422_Packed:
|
||||
// case MvGvspPixelType.PixelType_Gvsp_YUV422_YUYV_Packed:
|
||||
// case MvGvspPixelType.PixelType_Gvsp_BayerGR8:
|
||||
// case MvGvspPixelType.PixelType_Gvsp_BayerRG8:
|
||||
// case MvGvspPixelType.PixelType_Gvsp_BayerGB8:
|
||||
// case MvGvspPixelType.PixelType_Gvsp_BayerBG8:
|
||||
// case MvGvspPixelType.PixelType_Gvsp_BayerGB10:
|
||||
// case MvGvspPixelType.PixelType_Gvsp_BayerGB10_Packed:
|
||||
// case MvGvspPixelType.PixelType_Gvsp_BayerBG10:
|
||||
// case MvGvspPixelType.PixelType_Gvsp_BayerBG10_Packed:
|
||||
// case MvGvspPixelType.PixelType_Gvsp_BayerRG10:
|
||||
// case MvGvspPixelType.PixelType_Gvsp_BayerRG10_Packed:
|
||||
// case MvGvspPixelType.PixelType_Gvsp_BayerGR10:
|
||||
// case MvGvspPixelType.PixelType_Gvsp_BayerGR10_Packed:
|
||||
// case MvGvspPixelType.PixelType_Gvsp_BayerGB12:
|
||||
// case MvGvspPixelType.PixelType_Gvsp_BayerGB12_Packed:
|
||||
// case MvGvspPixelType.PixelType_Gvsp_BayerBG12:
|
||||
// case MvGvspPixelType.PixelType_Gvsp_BayerBG12_Packed:
|
||||
// case MvGvspPixelType.PixelType_Gvsp_BayerRG12:
|
||||
// case MvGvspPixelType.PixelType_Gvsp_BayerRG12_Packed:
|
||||
// case MvGvspPixelType.PixelType_Gvsp_BayerGR12:
|
||||
// case MvGvspPixelType.PixelType_Gvsp_BayerGR12_Packed:
|
||||
// return true;
|
||||
// default:
|
||||
// return false;
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
private bool IsMonoData(MyCamera.MvGvspPixelType enGvspPixelType)
|
||||
{
|
||||
switch (enGvspPixelType)
|
||||
{
|
||||
case MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono8:
|
||||
case MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono10:
|
||||
case MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono10_Packed:
|
||||
case MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono12:
|
||||
case MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono12_Packed:
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void RefreshImageBufferHandle()
|
||||
{
|
||||
//_bufferImgSet?.Dispose();
|
||||
//_bufferImgSet = null;
|
||||
|
||||
_bufferHandle.Reset();
|
||||
}
|
||||
|
||||
object _bufferLock = new object();
|
||||
|
||||
|
||||
//public void CameraOpModeChanged(EnumHelper.CameraOpMode opMode)
|
||||
//{
|
||||
// if (opMode == EnumHelper.CameraOpMode.ContinuousMode)
|
||||
// {
|
||||
// device.MV_CC_SetEnumValue_NET("TriggerMode", 0);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// device.MV_CC_SetEnumValue_NET("TriggerMode", 1);
|
||||
// }
|
||||
//}
|
||||
public void Snapshot(int pageBum, string napshotFileName)
|
||||
{
|
||||
//SnapshotCount = pageBum;
|
||||
//SnapshotFileNames = napshotFileName;
|
||||
|
||||
Snapshot();
|
||||
}
|
||||
public void Snapshot()
|
||||
{
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
// ImageSet set = new ImageSet();
|
||||
// set.SnapshotCount = SnapshotCount;
|
||||
// set.SnapshotFileName = SnapshotFileNames;
|
||||
|
||||
//InitialImageSet(set);
|
||||
MyCamera.MV_FRAME_OUT frameInfo = new MyCamera.MV_FRAME_OUT();
|
||||
nRet = MyCamera.MV_OK;
|
||||
if (true)
|
||||
{
|
||||
// ch: 触发命令 || en: Trigger command
|
||||
nRet = device.MV_CC_SetCommandValue_NET("TriggerSoftware");
|
||||
if (MyCamera.MV_OK != nRet)
|
||||
{
|
||||
throw new Exception($"相机拍照触发失败:{nRet}");
|
||||
}
|
||||
|
||||
nRet = device.MV_CC_GetImageBuffer_NET(ref frameInfo, 1000);
|
||||
nRet = device.MV_CC_FreeImageBuffer_NET(ref frameInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
_snapHandle.Reset();
|
||||
_snapFlag = true;
|
||||
_snapHandle.WaitOne();
|
||||
//lock (_imgCallBackLock)
|
||||
{
|
||||
frameInfo.stFrameInfo = _frame.stFrameInfo;
|
||||
frameInfo.pBufAddr = _frame.pBufAddr;
|
||||
}
|
||||
}
|
||||
|
||||
// ch:获取一帧图像 | en:Get one image
|
||||
if (MyCamera.MV_OK == nRet)
|
||||
{
|
||||
if (frameInfo.pBufAddr != IntPtr.Zero)
|
||||
{
|
||||
if (nRet == MyCamera.MV_OK)
|
||||
{
|
||||
var pFrameInfo = frameInfo.stFrameInfo;
|
||||
|
||||
Mat _mat = new Mat(pFrameInfo.nWidth, pFrameInfo.nHeight, MatType.CV_8UC3, frameInfo.pBufAddr);
|
||||
OnHImageOutput?.Invoke(DateTime.Now, _mat, SnapshotCount);
|
||||
// mat.ImWrite("D://123mat.jpg");
|
||||
//HImage hImage = new HImage();
|
||||
//HObject Hobj = new HObject();
|
||||
//IntPtr pTemp = IntPtr.Zero;
|
||||
//hImage.GenImage1("byte", pFrameInfo.nWidth, pFrameInfo.nHeight, frameInfo.pBufAddr);
|
||||
|
||||
////hImage.ConvertHImageTo16GrayBitmap();
|
||||
//var imgSet = new ImageSet
|
||||
//{
|
||||
// HImage = hImage,
|
||||
// ImageSaveOption = IConfig.ImageSaveOption.Copy()
|
||||
//};
|
||||
//if (pFrameInfo.enPixelType == MyCamera.MvGvspPixelType.PixelType_Gvsp_RGB8_Packed)
|
||||
//{
|
||||
// // Console.WriteLine("image pixel format is rgb8...");
|
||||
// pTemp = frameInfo.pBufAddr;
|
||||
// HOperatorSet.GenImageInterleaved(out Hobj, (HTuple)pTemp, (HTuple)"rgb", (HTuple)pFrameInfo.nWidth, (HTuple)pFrameInfo.nHeight, -1, "byte", 0, 0, 0, 0, -1, 0);
|
||||
// HobjectToRGBHimage(Hobj, ref hImage);
|
||||
//}
|
||||
|
||||
|
||||
//加入内部队列
|
||||
//InitialImageSet(imgSet);
|
||||
|
||||
////业务图片处理加入外部队列
|
||||
//var outImgSet = CopyImageSet(imgSet);
|
||||
//OnHImageOutput?.Invoke(DateTime.Now, this, outImgSet);
|
||||
//LogAsync(DateTime.Now, LogLevel.Information, $"{Name}相机取像, 次数:{SnapshotCount}");
|
||||
//DisplayAndSaveOriginImage(imgSet.Id);
|
||||
//HikToBitmap(pFrameInfo, frameInfo.pBufAddr);
|
||||
//Generate8GrayImageByPointer((int)nWidth, (int)nHeight, frameInfo.pBufAddr, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"Grap Image Failed:{nRet:x8}");
|
||||
}
|
||||
|
||||
sw.Stop();
|
||||
//LogAsync(DateTime.Now, LogLevel.Information, $"取像耗时:{sw.ElapsedMilliseconds} ms");
|
||||
}
|
||||
|
||||
|
||||
|
||||
readonly MyCamera device = new MyCamera();
|
||||
MyCamera.MV_CC_DEVICE_INFO stDevInfo = new MyCamera.MV_CC_DEVICE_INFO();
|
||||
int nRet = MyCamera.MV_OK;
|
||||
MyCamera.cbExceptiondelegate pCallBackFunc;
|
||||
|
||||
/// <summary>
|
||||
/// 获取曝光
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
//public double dvpGetExposure()
|
||||
//{
|
||||
// dvpStatus status;
|
||||
// double exposure = 0;
|
||||
// float gain = 0;
|
||||
// if (IsValidHandle(m_handle))
|
||||
// {
|
||||
// // 读取曝光
|
||||
// status = DVPCamera.dvpGetExposure(m_handle, ref exposure);
|
||||
// if (status == dvpStatus.DVP_STATUS_OK)
|
||||
// {
|
||||
// //opConfig.Exposure = (float)exposure;
|
||||
// return exposure;
|
||||
// }
|
||||
// }
|
||||
// return exposure;
|
||||
//}
|
||||
///// <summary>
|
||||
///// 获取增益
|
||||
///// </summary>
|
||||
///// <returns></returns>
|
||||
//public float dvpGetAnalogGain()
|
||||
//{
|
||||
// dvpStatus status;
|
||||
// double exposure = 0;
|
||||
// float gain = 0;
|
||||
// if (IsValidHandle(m_handle))
|
||||
// {
|
||||
// // 读取曝光
|
||||
// status = DVPCamera.dvpGetAnalogGain(m_handle, ref gain);
|
||||
// if (status == dvpStatus.DVP_STATUS_OK)
|
||||
// {
|
||||
// //opConfig.Exposure = (float)exposure;
|
||||
// return gain;
|
||||
// }
|
||||
// }
|
||||
// return gain;
|
||||
//}
|
||||
|
||||
// ch:回调函数 | en:Callback function
|
||||
//private void cbExceptiondelegate(uint nMsgType, IntPtr pUser)
|
||||
//{
|
||||
// if (nMsgType == MyCamera.MV_EXCEPTION_DEV_DISCONNECT)
|
||||
// {
|
||||
// if (CurrentState != EnumHelper.DeviceState.DSClose)
|
||||
// {
|
||||
// int reTryTimes = 3;
|
||||
// do
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// Task.Delay(1000).Wait();
|
||||
// Stop();
|
||||
|
||||
// Start();
|
||||
// reTryTimes = -1;
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// reTryTimes--;
|
||||
|
||||
// if (reTryTimes > 0)
|
||||
// {
|
||||
// LogAsync(DateTime.Now, LogLevel.Information, $"{this.Name}重新连接异常,{ex.GetExceptionMessage()}");
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// throw ex;
|
||||
// }
|
||||
// }
|
||||
// } while (reTryTimes > 0);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
#endregion
|
||||
}
|
||||
|
@ -8,12 +8,17 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Platforms>AnyCPU;X64</Platforms>
|
||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||
<ApplicationIcon>bin\X64\Debug\net7.0-windows\Logo.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="MelsecPLCTCPDriver.cs~RFacf25a.TMP" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="bin\X64\Debug\net7.0-windows\Logo.ico" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
@ -24,6 +29,10 @@
|
||||
<PackageReference Include="System.Data.SQLite" Version="1.0.118" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\XKRS.UI\XKRS.UI.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="DVPCameraCS64">
|
||||
<HintPath>..\libs\DVPCameraCS_Net6.0\x64\DVPCameraCS64.dll</HintPath>
|
||||
@ -31,6 +40,9 @@
|
||||
<Reference Include="HslCommunication">
|
||||
<HintPath>..\libs\HslCommunication.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MvCameraControl.Net">
|
||||
<HintPath>..\libs\HikCamera\MvCameraControl.Net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="PaddleOCRSharp">
|
||||
<HintPath>bin\X64\Debug\net7.0-windows\PaddleOCRSharp.dll</HintPath>
|
||||
</Reference>
|
||||
@ -44,8 +56,4 @@
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
297
HisenceYoloDetection/MainForm.Designer.cs
generated
297
HisenceYoloDetection/MainForm.Designer.cs
generated
@ -29,6 +29,14 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
components = new System.ComponentModel.Container();
|
||||
OpenCvSharp.Mat mat1 = new OpenCvSharp.Mat();
|
||||
OpenCvSharp.Mat mat2 = new OpenCvSharp.Mat();
|
||||
OpenCvSharp.Mat mat3 = new OpenCvSharp.Mat();
|
||||
OpenCvSharp.Mat mat4 = new OpenCvSharp.Mat();
|
||||
OpenCvSharp.Mat mat5 = new OpenCvSharp.Mat();
|
||||
OpenCvSharp.Mat mat6 = new OpenCvSharp.Mat();
|
||||
OpenCvSharp.Mat mat7 = new OpenCvSharp.Mat();
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
|
||||
tabPage2 = new TabPage();
|
||||
panel1 = new Panel();
|
||||
groupBox5 = new GroupBox();
|
||||
@ -90,6 +98,8 @@
|
||||
showPLC = new TextBox();
|
||||
readPLc = new TextBox();
|
||||
tabPage1 = new TabPage();
|
||||
CamShow2 = new XKRS.UI.Canvas();
|
||||
CamShow1 = new XKRS.UI.Canvas();
|
||||
groupBox3 = new GroupBox();
|
||||
SnapshotCam2 = new Button();
|
||||
button3 = new Button();
|
||||
@ -101,7 +111,6 @@
|
||||
tbExposure2 = new TextBox();
|
||||
label7 = new Label();
|
||||
label8 = new Label();
|
||||
pictureBox2 = new PictureBox();
|
||||
groupBox1 = new GroupBox();
|
||||
SnapshotCam1 = new Button();
|
||||
button2 = new Button();
|
||||
@ -113,11 +122,11 @@
|
||||
tbExposure = new TextBox();
|
||||
label2 = new Label();
|
||||
label4 = new Label();
|
||||
pictureBox1 = new PictureBox();
|
||||
tabControl1 = new TabControl();
|
||||
tabPage5 = new TabPage();
|
||||
panel4 = new Panel();
|
||||
panel5 = new Panel();
|
||||
DefetShow5 = new XKRS.UI.Canvas();
|
||||
panel8 = new Panel();
|
||||
RefeshData = new Button();
|
||||
实时显示 = new Label();
|
||||
@ -135,8 +144,11 @@
|
||||
InitMachine = new Button();
|
||||
panel6 = new Panel();
|
||||
groupBox2 = new GroupBox();
|
||||
ResultMat2Show = new PictureBox();
|
||||
DefetShow4 = new XKRS.UI.Canvas();
|
||||
DefetShow3 = new XKRS.UI.Canvas();
|
||||
DefetShow2 = new XKRS.UI.Canvas();
|
||||
originMat2Show = new PictureBox();
|
||||
DefetShow1 = new XKRS.UI.Canvas();
|
||||
ResultMatShow2 = new PictureBox();
|
||||
originMatShow2 = new PictureBox();
|
||||
originMatShow = new PictureBox();
|
||||
@ -146,7 +158,6 @@
|
||||
WhiteBanCbx = new CheckBox();
|
||||
label33 = new Label();
|
||||
label28 = new Label();
|
||||
button1 = new Button();
|
||||
openModelBtn = new Button();
|
||||
modelChangeCbx = new TextBox();
|
||||
label34 = new Label();
|
||||
@ -186,7 +197,6 @@
|
||||
timer6 = new System.Windows.Forms.Timer(components);
|
||||
richTextBox1 = new RichTextBox();
|
||||
contextMenuStrip1 = new ContextMenuStrip(components);
|
||||
dataGridView1 = new DataGridView();
|
||||
backgroundWorker1 = new System.ComponentModel.BackgroundWorker();
|
||||
tabPage2.SuspendLayout();
|
||||
panel1.SuspendLayout();
|
||||
@ -195,9 +205,7 @@
|
||||
ModeleShow.SuspendLayout();
|
||||
tabPage1.SuspendLayout();
|
||||
groupBox3.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox2).BeginInit();
|
||||
groupBox1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit();
|
||||
tabControl1.SuspendLayout();
|
||||
tabPage5.SuspendLayout();
|
||||
panel4.SuspendLayout();
|
||||
@ -206,7 +214,6 @@
|
||||
((System.ComponentModel.ISupportInitialize)OKOrNGShow).BeginInit();
|
||||
panel6.SuspendLayout();
|
||||
groupBox2.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)ResultMat2Show).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)originMat2Show).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)ResultMatShow2).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)originMatShow2).BeginInit();
|
||||
@ -215,7 +222,6 @@
|
||||
tabPage3.SuspendLayout();
|
||||
panel2.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)InsertDataDgv).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// tabPage2
|
||||
@ -224,7 +230,7 @@
|
||||
tabPage2.Location = new Point(4, 26);
|
||||
tabPage2.Name = "tabPage2";
|
||||
tabPage2.Padding = new Padding(3);
|
||||
tabPage2.Size = new Size(1276, 499);
|
||||
tabPage2.Size = new Size(1319, 765);
|
||||
tabPage2.TabIndex = 1;
|
||||
tabPage2.Text = "PLC";
|
||||
tabPage2.UseVisualStyleBackColor = true;
|
||||
@ -815,18 +821,60 @@
|
||||
//
|
||||
// tabPage1
|
||||
//
|
||||
tabPage1.Controls.Add(CamShow2);
|
||||
tabPage1.Controls.Add(CamShow1);
|
||||
tabPage1.Controls.Add(groupBox3);
|
||||
tabPage1.Controls.Add(pictureBox2);
|
||||
tabPage1.Controls.Add(groupBox1);
|
||||
tabPage1.Controls.Add(pictureBox1);
|
||||
tabPage1.Location = new Point(4, 26);
|
||||
tabPage1.Name = "tabPage1";
|
||||
tabPage1.Padding = new Padding(3);
|
||||
tabPage1.Size = new Size(1276, 499);
|
||||
tabPage1.Size = new Size(1319, 765);
|
||||
tabPage1.TabIndex = 0;
|
||||
tabPage1.Text = "相机";
|
||||
tabPage1.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// CamShow2
|
||||
//
|
||||
CamShow2.AllowSelectDefect = true;
|
||||
CamShow2.BrushColor = null;
|
||||
CamShow2.ImagePath = "";
|
||||
mat1.IsEnabledDispose = true;
|
||||
CamShow2.ImaMAt = mat1;
|
||||
CamShow2.ImgData = null;
|
||||
CamShow2.Location = new Point(578, 6);
|
||||
CamShow2.MoveStep = 5F;
|
||||
CamShow2.Name = "CamShow2";
|
||||
CamShow2.Route = 0D;
|
||||
CamShow2.Scale = 1D;
|
||||
CamShow2.Size = new Size(690, 310);
|
||||
CamShow2.TabIndex = 21;
|
||||
CamShow2.WholeScale = 0F;
|
||||
CamShow2.XMove = 0F;
|
||||
CamShow2.XScale = 0F;
|
||||
CamShow2.YMove = 0F;
|
||||
CamShow2.YScale = 0F;
|
||||
//
|
||||
// CamShow1
|
||||
//
|
||||
CamShow1.AllowSelectDefect = true;
|
||||
CamShow1.BrushColor = null;
|
||||
CamShow1.ImagePath = "";
|
||||
mat2.IsEnabledDispose = true;
|
||||
CamShow1.ImaMAt = mat2;
|
||||
CamShow1.ImgData = null;
|
||||
CamShow1.Location = new Point(14, 6);
|
||||
CamShow1.MoveStep = 5F;
|
||||
CamShow1.Name = "CamShow1";
|
||||
CamShow1.Route = 0D;
|
||||
CamShow1.Scale = 1D;
|
||||
CamShow1.Size = new Size(546, 293);
|
||||
CamShow1.TabIndex = 20;
|
||||
CamShow1.WholeScale = 0F;
|
||||
CamShow1.XMove = 0F;
|
||||
CamShow1.XScale = 0F;
|
||||
CamShow1.YMove = 0F;
|
||||
CamShow1.YScale = 0F;
|
||||
//
|
||||
// groupBox3
|
||||
//
|
||||
groupBox3.Controls.Add(SnapshotCam2);
|
||||
@ -936,15 +984,6 @@
|
||||
label8.TabIndex = 0;
|
||||
label8.Text = "曝光";
|
||||
//
|
||||
// pictureBox2
|
||||
//
|
||||
pictureBox2.Location = new Point(566, 6);
|
||||
pictureBox2.Name = "pictureBox2";
|
||||
pictureBox2.Size = new Size(464, 293);
|
||||
pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;
|
||||
pictureBox2.TabIndex = 18;
|
||||
pictureBox2.TabStop = false;
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
groupBox1.Controls.Add(SnapshotCam1);
|
||||
@ -993,6 +1032,7 @@
|
||||
bnSetParam.TabIndex = 7;
|
||||
bnSetParam.Text = "设置参数";
|
||||
bnSetParam.UseVisualStyleBackColor = true;
|
||||
bnSetParam.Click += bnSetParam_Click;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
@ -1055,15 +1095,6 @@
|
||||
label4.TabIndex = 0;
|
||||
label4.Text = "曝光";
|
||||
//
|
||||
// pictureBox1
|
||||
//
|
||||
pictureBox1.Location = new Point(8, 6);
|
||||
pictureBox1.Name = "pictureBox1";
|
||||
pictureBox1.Size = new Size(535, 293);
|
||||
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
|
||||
pictureBox1.TabIndex = 0;
|
||||
pictureBox1.TabStop = false;
|
||||
//
|
||||
// tabControl1
|
||||
//
|
||||
tabControl1.Controls.Add(tabPage1);
|
||||
@ -1074,7 +1105,7 @@
|
||||
tabControl1.Location = new Point(0, 0);
|
||||
tabControl1.Name = "tabControl1";
|
||||
tabControl1.SelectedIndex = 0;
|
||||
tabControl1.Size = new Size(1284, 529);
|
||||
tabControl1.Size = new Size(1327, 795);
|
||||
tabControl1.TabIndex = 0;
|
||||
//
|
||||
// tabPage5
|
||||
@ -1082,7 +1113,7 @@
|
||||
tabPage5.Controls.Add(panel4);
|
||||
tabPage5.Location = new Point(4, 26);
|
||||
tabPage5.Name = "tabPage5";
|
||||
tabPage5.Size = new Size(1276, 499);
|
||||
tabPage5.Size = new Size(1319, 765);
|
||||
tabPage5.TabIndex = 3;
|
||||
tabPage5.Text = "流程";
|
||||
tabPage5.UseVisualStyleBackColor = true;
|
||||
@ -1093,19 +1124,41 @@
|
||||
panel4.Dock = DockStyle.Fill;
|
||||
panel4.Location = new Point(0, 0);
|
||||
panel4.Name = "panel4";
|
||||
panel4.Size = new Size(1276, 499);
|
||||
panel4.Size = new Size(1319, 765);
|
||||
panel4.TabIndex = 0;
|
||||
//
|
||||
// panel5
|
||||
//
|
||||
panel5.Controls.Add(DefetShow5);
|
||||
panel5.Controls.Add(panel8);
|
||||
panel5.Controls.Add(panel6);
|
||||
panel5.Dock = DockStyle.Top;
|
||||
panel5.Location = new Point(0, 0);
|
||||
panel5.Name = "panel5";
|
||||
panel5.Size = new Size(1276, 577);
|
||||
panel5.Size = new Size(1319, 762);
|
||||
panel5.TabIndex = 0;
|
||||
//
|
||||
// DefetShow5
|
||||
//
|
||||
DefetShow5.AllowSelectDefect = true;
|
||||
DefetShow5.BrushColor = null;
|
||||
DefetShow5.ImagePath = "";
|
||||
mat3.IsEnabledDispose = true;
|
||||
DefetShow5.ImaMAt = mat3;
|
||||
DefetShow5.ImgData = null;
|
||||
DefetShow5.Location = new Point(853, 464);
|
||||
DefetShow5.MoveStep = 5F;
|
||||
DefetShow5.Name = "DefetShow5";
|
||||
DefetShow5.Route = 0D;
|
||||
DefetShow5.Scale = 1D;
|
||||
DefetShow5.Size = new Size(254, 196);
|
||||
DefetShow5.TabIndex = 10;
|
||||
DefetShow5.WholeScale = 0F;
|
||||
DefetShow5.XMove = 0F;
|
||||
DefetShow5.XScale = 0F;
|
||||
DefetShow5.YMove = 0F;
|
||||
DefetShow5.YScale = 0F;
|
||||
//
|
||||
// panel8
|
||||
//
|
||||
panel8.Controls.Add(RefeshData);
|
||||
@ -1124,13 +1177,13 @@
|
||||
panel8.Controls.Add(InitMachine);
|
||||
panel8.Location = new Point(853, 0);
|
||||
panel8.Name = "panel8";
|
||||
panel8.Size = new Size(440, 496);
|
||||
panel8.Size = new Size(440, 458);
|
||||
panel8.TabIndex = 2;
|
||||
panel8.Paint += panel8_Paint;
|
||||
//
|
||||
// RefeshData
|
||||
//
|
||||
RefeshData.Location = new Point(38, 442);
|
||||
RefeshData.Location = new Point(24, 340);
|
||||
RefeshData.Name = "RefeshData";
|
||||
RefeshData.Size = new Size(94, 43);
|
||||
RefeshData.TabIndex = 13;
|
||||
@ -1261,46 +1314,125 @@
|
||||
panel6.Controls.Add(groupBox2);
|
||||
panel6.Location = new Point(0, 0);
|
||||
panel6.Name = "panel6";
|
||||
panel6.Size = new Size(847, 531);
|
||||
panel6.Size = new Size(847, 759);
|
||||
panel6.TabIndex = 1;
|
||||
//
|
||||
// groupBox2
|
||||
//
|
||||
groupBox2.AutoSize = true;
|
||||
groupBox2.Controls.Add(ResultMat2Show);
|
||||
groupBox2.Controls.Add(DefetShow4);
|
||||
groupBox2.Controls.Add(DefetShow3);
|
||||
groupBox2.Controls.Add(DefetShow2);
|
||||
groupBox2.Controls.Add(originMat2Show);
|
||||
groupBox2.Controls.Add(DefetShow1);
|
||||
groupBox2.Controls.Add(ResultMatShow2);
|
||||
groupBox2.Controls.Add(originMatShow2);
|
||||
groupBox2.Controls.Add(originMatShow);
|
||||
groupBox2.Controls.Add(ResultMatShow);
|
||||
groupBox2.Location = new Point(8, 4);
|
||||
groupBox2.Name = "groupBox2";
|
||||
groupBox2.Size = new Size(839, 493);
|
||||
groupBox2.Size = new Size(885, 768);
|
||||
groupBox2.TabIndex = 0;
|
||||
groupBox2.TabStop = false;
|
||||
groupBox2.Text = "图片";
|
||||
groupBox2.Enter += groupBox2_Enter;
|
||||
//
|
||||
// ResultMat2Show
|
||||
// DefetShow4
|
||||
//
|
||||
ResultMat2Show.Location = new Point(574, 245);
|
||||
ResultMat2Show.Name = "ResultMat2Show";
|
||||
ResultMat2Show.Size = new Size(259, 213);
|
||||
ResultMat2Show.SizeMode = PictureBoxSizeMode.StretchImage;
|
||||
ResultMat2Show.TabIndex = 7;
|
||||
ResultMat2Show.TabStop = false;
|
||||
DefetShow4.AllowSelectDefect = true;
|
||||
DefetShow4.BrushColor = null;
|
||||
DefetShow4.ImagePath = "";
|
||||
mat4.IsEnabledDispose = true;
|
||||
DefetShow4.ImaMAt = mat4;
|
||||
DefetShow4.ImgData = null;
|
||||
DefetShow4.Location = new Point(574, 460);
|
||||
DefetShow4.MoveStep = 5F;
|
||||
DefetShow4.Name = "DefetShow4";
|
||||
DefetShow4.Route = 0D;
|
||||
DefetShow4.Scale = 1D;
|
||||
DefetShow4.Size = new Size(265, 196);
|
||||
DefetShow4.TabIndex = 11;
|
||||
DefetShow4.WholeScale = 0F;
|
||||
DefetShow4.XMove = 0F;
|
||||
DefetShow4.XScale = 0F;
|
||||
DefetShow4.YMove = 0F;
|
||||
DefetShow4.YScale = 0F;
|
||||
//
|
||||
// DefetShow3
|
||||
//
|
||||
DefetShow3.AllowSelectDefect = true;
|
||||
DefetShow3.BrushColor = null;
|
||||
DefetShow3.ImagePath = "";
|
||||
mat5.IsEnabledDispose = true;
|
||||
DefetShow3.ImaMAt = mat5;
|
||||
DefetShow3.ImgData = null;
|
||||
DefetShow3.Location = new Point(303, 460);
|
||||
DefetShow3.MoveStep = 5F;
|
||||
DefetShow3.Name = "DefetShow3";
|
||||
DefetShow3.Route = 0D;
|
||||
DefetShow3.Scale = 1D;
|
||||
DefetShow3.Size = new Size(265, 196);
|
||||
DefetShow3.TabIndex = 10;
|
||||
DefetShow3.WholeScale = 0F;
|
||||
DefetShow3.XMove = 0F;
|
||||
DefetShow3.XScale = 0F;
|
||||
DefetShow3.YMove = 0F;
|
||||
DefetShow3.YScale = 0F;
|
||||
//
|
||||
// DefetShow2
|
||||
//
|
||||
DefetShow2.AllowSelectDefect = true;
|
||||
DefetShow2.BrushColor = null;
|
||||
DefetShow2.ImagePath = "";
|
||||
mat6.IsEnabledDispose = true;
|
||||
DefetShow2.ImaMAt = mat6;
|
||||
DefetShow2.ImgData = null;
|
||||
DefetShow2.Location = new Point(6, 460);
|
||||
DefetShow2.MoveStep = 5F;
|
||||
DefetShow2.Name = "DefetShow2";
|
||||
DefetShow2.Route = 0D;
|
||||
DefetShow2.Scale = 1D;
|
||||
DefetShow2.Size = new Size(285, 196);
|
||||
DefetShow2.TabIndex = 9;
|
||||
DefetShow2.WholeScale = 0F;
|
||||
DefetShow2.XMove = 0F;
|
||||
DefetShow2.XScale = 0F;
|
||||
DefetShow2.YMove = 0F;
|
||||
DefetShow2.YScale = 0F;
|
||||
//
|
||||
// originMat2Show
|
||||
//
|
||||
originMat2Show.Location = new Point(574, 22);
|
||||
originMat2Show.Location = new Point(574, 21);
|
||||
originMat2Show.Name = "originMat2Show";
|
||||
originMat2Show.Size = new Size(259, 213);
|
||||
originMat2Show.Size = new Size(271, 213);
|
||||
originMat2Show.SizeMode = PictureBoxSizeMode.StretchImage;
|
||||
originMat2Show.TabIndex = 6;
|
||||
originMat2Show.TabIndex = 8;
|
||||
originMat2Show.TabStop = false;
|
||||
//
|
||||
// DefetShow1
|
||||
//
|
||||
DefetShow1.AllowSelectDefect = true;
|
||||
DefetShow1.BrushColor = null;
|
||||
DefetShow1.ImagePath = "";
|
||||
mat7.IsEnabledDispose = true;
|
||||
DefetShow1.ImaMAt = mat7;
|
||||
DefetShow1.ImgData = null;
|
||||
DefetShow1.Location = new Point(574, 245);
|
||||
DefetShow1.MoveStep = 5F;
|
||||
DefetShow1.Name = "DefetShow1";
|
||||
DefetShow1.Route = 0D;
|
||||
DefetShow1.Scale = 1D;
|
||||
DefetShow1.Size = new Size(262, 209);
|
||||
DefetShow1.TabIndex = 7;
|
||||
DefetShow1.WholeScale = 0F;
|
||||
DefetShow1.XMove = 0F;
|
||||
DefetShow1.XScale = 0F;
|
||||
DefetShow1.YMove = 0F;
|
||||
DefetShow1.YScale = 0F;
|
||||
//
|
||||
// ResultMatShow2
|
||||
//
|
||||
ResultMatShow2.Location = new Point(297, 246);
|
||||
ResultMatShow2.Location = new Point(297, 241);
|
||||
ResultMatShow2.Name = "ResultMatShow2";
|
||||
ResultMatShow2.Size = new Size(271, 213);
|
||||
ResultMatShow2.SizeMode = PictureBoxSizeMode.StretchImage;
|
||||
@ -1309,7 +1441,7 @@
|
||||
//
|
||||
// originMatShow2
|
||||
//
|
||||
originMatShow2.Location = new Point(6, 250);
|
||||
originMatShow2.Location = new Point(6, 241);
|
||||
originMatShow2.Name = "originMatShow2";
|
||||
originMatShow2.Size = new Size(285, 213);
|
||||
originMatShow2.SizeMode = PictureBoxSizeMode.StretchImage;
|
||||
@ -1339,7 +1471,7 @@
|
||||
tabPage3.Controls.Add(panel2);
|
||||
tabPage3.Location = new Point(4, 26);
|
||||
tabPage3.Name = "tabPage3";
|
||||
tabPage3.Size = new Size(1276, 499);
|
||||
tabPage3.Size = new Size(1319, 765);
|
||||
tabPage3.TabIndex = 4;
|
||||
tabPage3.Text = "录入新型号";
|
||||
tabPage3.UseVisualStyleBackColor = true;
|
||||
@ -1349,7 +1481,6 @@
|
||||
panel2.Controls.Add(WhiteBanCbx);
|
||||
panel2.Controls.Add(label33);
|
||||
panel2.Controls.Add(label28);
|
||||
panel2.Controls.Add(button1);
|
||||
panel2.Controls.Add(openModelBtn);
|
||||
panel2.Controls.Add(modelChangeCbx);
|
||||
panel2.Controls.Add(label34);
|
||||
@ -1402,7 +1533,7 @@
|
||||
// label33
|
||||
//
|
||||
label33.AutoSize = true;
|
||||
label33.Location = new Point(373, 245);
|
||||
label33.Location = new Point(366, 246);
|
||||
label33.Name = "label33";
|
||||
label33.Size = new Size(140, 17);
|
||||
label33.TabIndex = 39;
|
||||
@ -1417,15 +1548,6 @@
|
||||
label28.TabIndex = 14;
|
||||
label28.Text = "第一次拍照Z轴";
|
||||
//
|
||||
// button1
|
||||
//
|
||||
button1.Location = new Point(896, 110);
|
||||
button1.Name = "button1";
|
||||
button1.Size = new Size(93, 23);
|
||||
button1.TabIndex = 38;
|
||||
button1.Text = "识别到log";
|
||||
button1.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// openModelBtn
|
||||
//
|
||||
openModelBtn.Location = new Point(1042, 15);
|
||||
@ -1455,7 +1577,7 @@
|
||||
//
|
||||
// button4
|
||||
//
|
||||
button4.Location = new Point(691, 110);
|
||||
button4.Location = new Point(697, 110);
|
||||
button4.Name = "button4";
|
||||
button4.Size = new Size(75, 23);
|
||||
button4.TabIndex = 32;
|
||||
@ -1465,7 +1587,7 @@
|
||||
//
|
||||
// OpenTwoDirBtn
|
||||
//
|
||||
OpenTwoDirBtn.Location = new Point(691, 199);
|
||||
OpenTwoDirBtn.Location = new Point(697, 202);
|
||||
OpenTwoDirBtn.Name = "OpenTwoDirBtn";
|
||||
OpenTwoDirBtn.Size = new Size(75, 23);
|
||||
OpenTwoDirBtn.TabIndex = 31;
|
||||
@ -1475,7 +1597,7 @@
|
||||
//
|
||||
// OpenDirBtn
|
||||
//
|
||||
OpenDirBtn.Location = new Point(691, 151);
|
||||
OpenDirBtn.Location = new Point(697, 154);
|
||||
OpenDirBtn.Name = "OpenDirBtn";
|
||||
OpenDirBtn.Size = new Size(75, 23);
|
||||
OpenDirBtn.TabIndex = 30;
|
||||
@ -1538,7 +1660,7 @@
|
||||
// label24
|
||||
//
|
||||
label24.AutoSize = true;
|
||||
label24.Location = new Point(397, 116);
|
||||
label24.Location = new Point(366, 116);
|
||||
label24.Name = "label24";
|
||||
label24.Size = new Size(56, 17);
|
||||
label24.TabIndex = 23;
|
||||
@ -1575,7 +1697,7 @@
|
||||
//
|
||||
moveTwoYbox.Location = new Point(472, 12);
|
||||
moveTwoYbox.Name = "moveTwoYbox";
|
||||
moveTwoYbox.Size = new Size(213, 23);
|
||||
moveTwoYbox.Size = new Size(219, 23);
|
||||
moveTwoYbox.TabIndex = 19;
|
||||
moveTwoYbox.Text = "0";
|
||||
//
|
||||
@ -1590,9 +1712,9 @@
|
||||
//
|
||||
// moveTwoXbox
|
||||
//
|
||||
moveTwoXbox.Location = new Point(122, 242);
|
||||
moveTwoXbox.Location = new Point(111, 243);
|
||||
moveTwoXbox.Name = "moveTwoXbox";
|
||||
moveTwoXbox.Size = new Size(213, 23);
|
||||
moveTwoXbox.Size = new Size(224, 23);
|
||||
moveTwoXbox.TabIndex = 17;
|
||||
moveTwoXbox.Text = "54964";
|
||||
//
|
||||
@ -1705,7 +1827,7 @@
|
||||
richTextBox1.Dock = DockStyle.Bottom;
|
||||
richTextBox1.Location = new Point(0, 801);
|
||||
richTextBox1.Name = "richTextBox1";
|
||||
richTextBox1.Size = new Size(1284, 176);
|
||||
richTextBox1.Size = new Size(1327, 176);
|
||||
richTextBox1.TabIndex = 1;
|
||||
richTextBox1.Text = "";
|
||||
//
|
||||
@ -1714,24 +1836,14 @@
|
||||
contextMenuStrip1.Name = "contextMenuStrip1";
|
||||
contextMenuStrip1.Size = new Size(61, 4);
|
||||
//
|
||||
// dataGridView1
|
||||
//
|
||||
dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView1.Dock = DockStyle.Fill;
|
||||
dataGridView1.Location = new Point(0, 529);
|
||||
dataGridView1.Name = "dataGridView1";
|
||||
dataGridView1.RowTemplate.Height = 25;
|
||||
dataGridView1.Size = new Size(1284, 272);
|
||||
dataGridView1.TabIndex = 3;
|
||||
//
|
||||
// MainForm
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 17F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1284, 977);
|
||||
Controls.Add(dataGridView1);
|
||||
ClientSize = new Size(1327, 977);
|
||||
Controls.Add(richTextBox1);
|
||||
Controls.Add(tabControl1);
|
||||
Icon = (Icon)resources.GetObject("$this.Icon");
|
||||
Name = "MainForm";
|
||||
Text = "海信视觉防差错";
|
||||
Load += MainForm_Load;
|
||||
@ -1746,10 +1858,8 @@
|
||||
tabPage1.ResumeLayout(false);
|
||||
groupBox3.ResumeLayout(false);
|
||||
groupBox3.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox2).EndInit();
|
||||
groupBox1.ResumeLayout(false);
|
||||
groupBox1.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit();
|
||||
tabControl1.ResumeLayout(false);
|
||||
tabPage5.ResumeLayout(false);
|
||||
panel4.ResumeLayout(false);
|
||||
@ -1760,7 +1870,6 @@
|
||||
panel6.ResumeLayout(false);
|
||||
panel6.PerformLayout();
|
||||
groupBox2.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)ResultMat2Show).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)originMat2Show).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)ResultMatShow2).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)originMatShow2).EndInit();
|
||||
@ -1770,7 +1879,6 @@
|
||||
panel2.ResumeLayout(false);
|
||||
panel2.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)InsertDataDgv).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
@ -1779,7 +1887,6 @@
|
||||
private TabPage tabPage1;
|
||||
private Label label1;
|
||||
private Button Cam1OpenBtn;
|
||||
private PictureBox pictureBox1;
|
||||
private TabControl tabControl1;
|
||||
private TabPage tabPage5;
|
||||
private Panel panel4;
|
||||
@ -1797,7 +1904,6 @@
|
||||
private TextBox tbExposure;
|
||||
private Label label2;
|
||||
private Label label4;
|
||||
private PictureBox pictureBox2;
|
||||
private Button button2;
|
||||
private Button SnapshotCam1;
|
||||
private Button InitMachine;
|
||||
@ -1851,7 +1957,6 @@
|
||||
private Label label15;
|
||||
private Button StartDecBtn;
|
||||
private ContextMenuStrip contextMenuStrip1;
|
||||
private DataGridView dataGridView1;
|
||||
private Button InsertSqlBtn;
|
||||
private PictureBox ResultMatShow2;
|
||||
private PictureBox originMatShow2;
|
||||
@ -1896,8 +2001,6 @@
|
||||
private GroupBox groupBox5;
|
||||
private TextBox DistanceShow;
|
||||
private Label label21;
|
||||
private PictureBox originMat2Show;
|
||||
private PictureBox ResultMat2Show;
|
||||
private TabPage tabPage3;
|
||||
private Panel panel2;
|
||||
private Button button4;
|
||||
@ -1935,5 +2038,13 @@
|
||||
private Button button1;
|
||||
private Label label33;
|
||||
private CheckBox WhiteBanCbx;
|
||||
private XKRS.UI.Canvas DefetShow1;
|
||||
private XKRS.UI.Canvas CamShow1;
|
||||
private XKRS.UI.Canvas CamShow2;
|
||||
private XKRS.UI.Canvas DefetShow5;
|
||||
private XKRS.UI.Canvas DefetShow4;
|
||||
private XKRS.UI.Canvas DefetShow3;
|
||||
private XKRS.UI.Canvas DefetShow2;
|
||||
private PictureBox originMat2Show;
|
||||
}
|
||||
}
|
||||
|
@ -34,12 +34,16 @@ namespace HisenceYoloDetection
|
||||
}
|
||||
MGSCameraDriver Cam1 = new MGSCameraDriver();
|
||||
MGSCameraDriver Cam2 = new MGSCameraDriver();
|
||||
|
||||
// HikCameraDriver Cam1 = new HikCameraDriver();
|
||||
//HikCameraDriver Cam2 = new HikCameraDriver();
|
||||
|
||||
SQLiteHelper sqlhelper = new SQLiteHelper();
|
||||
TCPClienDriver Scanner = new TCPClienDriver();
|
||||
MelsecPLCTCPDriver melsecPLCTCPDriver = new MelsecPLCTCPDriver();
|
||||
SimboObjectDetection simboObjectDetection = new SimboObjectDetection();
|
||||
SimboObjectDetection simboObjectDetButton = new SimboObjectDetection();
|
||||
// CheckDiffSciHelper checkDiffSciHelper = new CheckDiffSciHelper();
|
||||
// CheckDiffSciHelper checkDiffSciHelper = new CheckDiffSciHelper();
|
||||
// ManagerModelHelper managerModelHelper = new ManagerModelHelper();
|
||||
|
||||
PaddleOcrModel paddleOcrModel = new PaddleOcrModel();
|
||||
@ -182,6 +186,9 @@ namespace HisenceYoloDetection
|
||||
string vModelChangePath = "D:\\Hisence\\config\\chinese.json";
|
||||
string LablePathstr = "D:\\Hisence\\ClassName.txt";//标签路径
|
||||
string LablePathButtonstr = "D:\\Hisence\\ClassNameButton.txt";//标签路径
|
||||
//Mat cameraMat = Cv2.ImRead(vCam1TwoPath);
|
||||
// canvas1.ImagePath = vCam1TwoPath;
|
||||
// DefetShow.ImaMAt = cameraMat;
|
||||
if (File.Exists(LablePathButtonstr) && File.Exists(vBarPath) && File.Exists(vCam1OnePath) && File.Exists(vCam1TwoPath) && File.Exists(vModelChangePath))
|
||||
{
|
||||
|
||||
@ -378,8 +385,8 @@ namespace HisenceYoloDetection
|
||||
}
|
||||
private void bnGetParam_Click(object sender, EventArgs e)
|
||||
{
|
||||
tbExposure.Text = Cam1.dvpGetExposure().ToString();
|
||||
tbGain.Text = Cam1.dvpGetAnalogGain().ToString();
|
||||
// tbExposure.Text = Cam1.dvpGetExposure().ToString();
|
||||
// tbGain.Text = Cam1.dvpGetAnalogGain().ToString();
|
||||
|
||||
}
|
||||
|
||||
@ -454,7 +461,7 @@ namespace HisenceYoloDetection
|
||||
//初始化相机
|
||||
|
||||
DataSet dataSet = SQLiteHelper.Query("select * from XK_HisenceDet");
|
||||
dataGridView1.DataSource = dataSet.Tables[0];
|
||||
//dataGridView1.DataSource = dataSet.Tables[0];
|
||||
|
||||
Cam1.Start("Cam1");
|
||||
if (Cam1.IfSuccess)
|
||||
@ -486,10 +493,10 @@ namespace HisenceYoloDetection
|
||||
melsecPLCTCPDriver.WriteInt("524", 0);//定位松开
|
||||
melsecPLCTCPDriver.WriteInt("406", 60000); //写入手动速度
|
||||
melsecPLCTCPDriver.WriteInt("416", 8000);
|
||||
melsecPLCTCPDriver.WriteInt("426", 8000);
|
||||
melsecPLCTCPDriver.WriteInt("426", 10000);
|
||||
melsecPLCTCPDriver.WriteInt("404", 100000); //写入定位速度
|
||||
melsecPLCTCPDriver.WriteInt("414", 8000);
|
||||
melsecPLCTCPDriver.WriteInt("424", 8000);
|
||||
melsecPLCTCPDriver.WriteInt("424", 10000);
|
||||
|
||||
|
||||
melsecPLCTCPDriver.WriteInt("500", 0);
|
||||
@ -902,6 +909,8 @@ namespace HisenceYoloDetection
|
||||
|
||||
});
|
||||
}
|
||||
int YPos = 6715;
|
||||
int ZPos = 18857;
|
||||
/// <summary>
|
||||
/// 监听洗衣机544是否触发后面对射传感器 相机
|
||||
/// </summary>
|
||||
@ -953,7 +962,7 @@ namespace HisenceYoloDetection
|
||||
|
||||
myLog("第一次采集图像", DateTime.Now);
|
||||
//移动模组 读三次测距的地址 看是否往前移动
|
||||
MoveToP(8974, 0, 0);
|
||||
MoveToP(5815, YPos, ZPos);
|
||||
// Thread.Sleep(2000);//删
|
||||
|
||||
|
||||
@ -973,10 +982,10 @@ namespace HisenceYoloDetection
|
||||
double dismove = disreal - 876;
|
||||
if (dismove > 0 && dismove < 4000)
|
||||
{
|
||||
MoveToP(8974, 0, (int)(dismove));
|
||||
MoveToP(5815, YPos, ZPos + (int)(dismove));
|
||||
}
|
||||
Thread.Sleep(2000);//删
|
||||
Thread.Sleep(500);
|
||||
//Thread.Sleep(2000);//删
|
||||
// Thread.Sleep(500);
|
||||
Cam1.SnapshotCount = 0;
|
||||
Cam1.Snapshot();
|
||||
IfCam2Triger = true;
|
||||
@ -989,9 +998,9 @@ namespace HisenceYoloDetection
|
||||
//}
|
||||
//currentXP = 54964;
|
||||
//Thread.Sleep(2000);//删
|
||||
MoveToP(54964, 0, (int)(dismove));
|
||||
MoveToP(51043, YPos, ZPos + (int)(dismove));
|
||||
Cam1.Snapshot();
|
||||
MoveToP(8974, 0, 0);
|
||||
MoveToP(5815, YPos, ZPos);
|
||||
//if (xKNow != null)
|
||||
//{
|
||||
// MoveToP(xKNow.MoveX, xKNow.MoveY, xKNow.MoveZ);
|
||||
@ -1084,7 +1093,7 @@ namespace HisenceYoloDetection
|
||||
}
|
||||
|
||||
|
||||
pictureBox1.Image = cameraMat.ToBitmap();
|
||||
CamShow1.ImaMAt = cameraMat;
|
||||
cameraMat.ImWrite(fitImageFolder + dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString() + "1.jpg");
|
||||
|
||||
}
|
||||
@ -1106,14 +1115,15 @@ namespace HisenceYoloDetection
|
||||
// Mat mat = Cv2.ImRead("F:\\海信洗衣机\\cam1\\2024517161641.jpg");
|
||||
Cam2ImgShowBar = cameraMat;
|
||||
IfCam2Triger = true;
|
||||
originMat2Show.Image = cameraMat.ToBitmap();
|
||||
originMat2Show.BackgroundImage = cameraMat.ToBitmap();
|
||||
//originMat2Show.Image = cameraMat.ToBitmap();
|
||||
//pictureBox1.Image = cameraMat.ToBitmap();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
pictureBox2.Image = cameraMat.ToBitmap();
|
||||
CamShow2.ImaMAt = cameraMat;
|
||||
cameraMat.ImWrite(fitImageFolder + dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString() + "1.jpg");
|
||||
|
||||
}
|
||||
@ -1139,18 +1149,33 @@ namespace HisenceYoloDetection
|
||||
//OCR识别
|
||||
MLRequest req = new MLRequest();
|
||||
req.currentMat = Cam2ImgShowBar;
|
||||
// req.currentMat = Cv2.ImRead("D:\\Hisence\\类型\\Lp\\202453015229201.jpg");
|
||||
// req.currentMat = Cv2.ImRead("D:\\Hisence\\类型\\Lp\\202453015229201.jpg");
|
||||
MLResult mL = paddleOcrModelCountry.RunInferenceFixed(req);
|
||||
//相机识别的字符串
|
||||
string IOcrBAr = "";
|
||||
for (int v = 0; v < Enumerable.Count<DetectionResultDetail>(mL.ResultDetails); v++)
|
||||
{
|
||||
string iv = mL.ResultDetails[v].LabelDisplay;
|
||||
string result = Regex.Replace(iv, "[ \\[ \\] \\^ \\-_*×――(^)$%~!@#$…&%¥—+=<>《》!!???::?`·、。,;,.;/\"‘’“”-]", "");
|
||||
if (mL.ResultDetails.Count() > 0)
|
||||
{
|
||||
if (mL.ResultDetails.Count() > 0)
|
||||
{
|
||||
string iv = mL.ResultDetails[0].LabelDisplay;
|
||||
string result = Regex.Replace(iv, "[ \\[ \\] \\^ \\-_*×――(^)$%~!@#$…&%¥—+=<>《》!!???::?`·、。,;,.;/\"‘’“”-]", "");
|
||||
|
||||
IOcrBAr = result;
|
||||
}
|
||||
}
|
||||
|
||||
IOcrBAr += result;
|
||||
}
|
||||
//IOcrBAr = "LR1006G4SILVERWJ060480U0SW901N120105";
|
||||
DateTime dt = DateTime.Now;
|
||||
using (StreamWriter sw = new StreamWriter("D://Hisence//logsBar.log", true))
|
||||
{
|
||||
string filename = dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString();
|
||||
sw.WriteLine(filename + "\n");
|
||||
sw.WriteLine(IOcrBAr + "\n");
|
||||
sw.Flush();
|
||||
}
|
||||
IOcrBAr = "BatchW81XBModelWNHA62SASUASNVWJ060501V0WW81XB120024";
|
||||
//根据条码数据库比对
|
||||
xKNow = GetModeFromBar(IOcrBAr);//从数据库中查询到这个条码的四轴的值
|
||||
List<XK_HisenceWord> xkWordList = ManagerModelHelper.GetModeWordFromBar(IOcrBAr);
|
||||
@ -1165,7 +1190,7 @@ namespace HisenceYoloDetection
|
||||
myLog("未匹配成功" + IfChangeLanguage, DateTime.Now);
|
||||
break;
|
||||
}
|
||||
if ( xKNow.Detect != "")
|
||||
if (xKNow.Detect != "")
|
||||
{
|
||||
//此时运行的洗衣机是和之前一个语言模型
|
||||
if (IfChangeLanguage == IOcrBAr)
|
||||
@ -1213,15 +1238,15 @@ namespace HisenceYoloDetection
|
||||
MLResult mL = simboObjectDetection.RunInferenceFixed(req);
|
||||
MLResult mLButton = simboObjectDetButton.RunInferenceFixed(req);
|
||||
|
||||
DateTime dt = DateTime.Now;
|
||||
DateTime dt = DateTime.Now;
|
||||
//将所有的块裁剪 识别字符对比字符串
|
||||
List<string> strMatListOne = new List<string>();
|
||||
List<string> strMatFuzzyListOne = new List<string>();
|
||||
Mat mResultCut = req.currentMat.Clone();
|
||||
Mat mCut = new Mat();
|
||||
ManagerModelHelper.InsertSqlRunDataButton(false,ref mCut, ref mResultCut, mL, mLButton, ref xK_MatchDet, /*ref strMatListOne, ref strMatFuzzyListOne, */ref paddleOcrModel);
|
||||
ManagerModelHelper.InsertSqlRunDataButton(false, ref mCut, ref mResultCut, mL, mLButton, ref xK_MatchDet, ref strMatListOne, ref strMatFuzzyListOne, ref paddleOcrModel);
|
||||
|
||||
if(mL.ResultMap!=null)
|
||||
if (mL.ResultMap != null)
|
||||
{
|
||||
mL.ResultMap.Save("D://cam1//" + dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString() + "1result.jpg");
|
||||
ResultMatShow.Image = mL.ResultMap;
|
||||
@ -1289,16 +1314,25 @@ namespace HisenceYoloDetection
|
||||
OKDsums++;
|
||||
myLog("匹配成功", DateTime.Now);
|
||||
//界面显示
|
||||
InsertXK_HisenceWordMatchData(xK_MatchDet, true);
|
||||
OKOrNGShow.Image = OKbitmap;
|
||||
// InsertXK_HisenceWordMatchData(xK_MatchDet, true);
|
||||
this.Invoke(new Action(() =>
|
||||
{
|
||||
OKOrNGShow.Image = OKbitmap;
|
||||
}));
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
NGDsums++;
|
||||
myLog("匹配失败", DateTime.Now);
|
||||
//界面显示
|
||||
InsertXK_HisenceWordMatchData(xK_MatchDet, false);
|
||||
OKOrNGShow.Image = NGbitmap;
|
||||
// InsertXK_HisenceWordMatchData(xK_MatchDet, false);
|
||||
this.Invoke(new Action(() =>
|
||||
{
|
||||
OKOrNGShow.Image = NGbitmap;
|
||||
}));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1563,7 +1597,7 @@ namespace HisenceYoloDetection
|
||||
private void RefeshData_Click(object sender, EventArgs e)
|
||||
{
|
||||
DataSet dataSet = SQLiteHelper.Query("select * from XK_HisenceDet");
|
||||
dataGridView1.DataSource = dataSet.Tables[0];
|
||||
//dataGridView1.DataSource = dataSet.Tables[0];
|
||||
}
|
||||
|
||||
private void panel8_Paint(object sender, PaintEventArgs e)
|
||||
@ -1906,7 +1940,7 @@ namespace HisenceYoloDetection
|
||||
int HmovetwoX = (int)Convert.ToInt64(movetwoX);
|
||||
int HmovetwoY = (int)Convert.ToInt64(movetwoY);
|
||||
int HmovetwoZ = (int)Convert.ToInt64(movetwoZ);
|
||||
InsertXK_Hisence(whiteBan,HmoveX, HmoveY, HmoveZ, HmovetwoX, HmovetwoY, HmovetwoZ);
|
||||
InsertXK_Hisence(whiteBan, HmoveX, HmoveY, HmoveZ, HmovetwoX, HmovetwoY, HmovetwoZ);
|
||||
|
||||
|
||||
}
|
||||
@ -1921,7 +1955,7 @@ namespace HisenceYoloDetection
|
||||
MessageBox.Show(es.Message);
|
||||
}
|
||||
}
|
||||
public void InsertXK_Hisence(bool ifwhiteBan,int MoveX, int MoveY, int MoveZ, int MoveTwoX, int MoveTwoY, int MoveTwoZ)
|
||||
public void InsertXK_Hisence(bool ifwhiteBan, int MoveX, int MoveY, int MoveZ, int MoveTwoX, int MoveTwoY, int MoveTwoZ)
|
||||
{
|
||||
PaddleOcrModel IpaddleOcrModel = new PaddleOcrModel();
|
||||
IpaddleOcrModel.Load(ModelChangePath, "CPU");
|
||||
@ -1983,7 +2017,7 @@ namespace HisenceYoloDetection
|
||||
List<string> strMatFuzzyListOne = new List<string>();
|
||||
Mat mResultCut = CamOneI.currentMat.Clone();
|
||||
Mat mCut = new Mat();
|
||||
ManagerModelHelper.InsertSqlRunDataButton(true,ref mCut, ref mResultCut, mL3, mLButton,ref xkWord, /*ref strMatListOne, ref strMatFuzzyListOne,*/ ref paddleOcrModel);
|
||||
ManagerModelHelper.InsertSqlRunDataButton(true, ref mCut, ref mResultCut, mL3, mLButton, ref xkWord, ref strMatListOne, ref strMatFuzzyListOne, ref paddleOcrModel);
|
||||
|
||||
|
||||
|
||||
@ -2011,7 +2045,7 @@ namespace HisenceYoloDetection
|
||||
|
||||
|
||||
|
||||
InsertXKHisenceWordData( xkWord);//往关键字表中插入一条数据
|
||||
InsertXKHisenceWordData(xkWord);//往关键字表中插入一条数据
|
||||
//文本区域
|
||||
List<string> bingji = strMatListOne.Union(strMatListTwo).ToList();//并(全)集
|
||||
List<string> Fuzzybingji = strMatFuzzyListOne.Union(strMatFuzzyListTwo).ToList();//并(全)集
|
||||
@ -2149,7 +2183,7 @@ namespace HisenceYoloDetection
|
||||
MessageBox.Show("关键字XK_HisenceWord插入一条数据");
|
||||
}
|
||||
}
|
||||
public void InsertXK_HisenceWordMatchData(XK_HisenceWord xkWord,bool ifMatch)
|
||||
public void InsertXK_HisenceWordMatchData(XK_HisenceWord xkWord, bool ifMatch)
|
||||
{
|
||||
StringBuilder strSql = new StringBuilder();
|
||||
strSql.Append("insert into XK_HisenceWordMatch(");
|
||||
@ -2373,13 +2407,23 @@ namespace HisenceYoloDetection
|
||||
|
||||
private void bnGetParam2_Click_1(object sender, EventArgs e)
|
||||
{
|
||||
tbExposure2.Text = Cam2.dvpGetExposure().ToString();
|
||||
tbGain2.Text = Cam2.dvpGetAnalogGain().ToString();
|
||||
// tbExposure2.Text = Cam2.dvpGetExposure().ToString();
|
||||
//tbGain2.Text = Cam2.dvpGetAnalogGain().ToString();
|
||||
}
|
||||
|
||||
private void panel2_Paint(object sender, PaintEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void bnSetParam_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void groupBox2_Enter(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -35,7 +35,7 @@ namespace HisenceYoloDetection
|
||||
/// <param name="strMatList">返回的定位框的结果</param>
|
||||
/// <param name="strMatRefList"></param>
|
||||
/// <param name="IOcrModel"></param>
|
||||
public static void InsertSqlRunDataButton(bool saveimage,ref Mat CutMat, ref Mat currentMatC, MLResult cam1TwoML, MLResult cam1Button, ref XK_HisenceWord xK_HisenceWord, /*ref List<string> strMatList, ref List<string> strMatRefList, */ref PaddleOcrModel IOcrModel)
|
||||
public static void InsertSqlRunDataButton(bool saveimage,ref Mat CutMat, ref Mat currentMatC, MLResult cam1TwoML, MLResult cam1Button, ref XK_HisenceWord xK_HisenceWord, ref List<string> strMatList, ref List<string> strMatRefList, ref PaddleOcrModel IOcrModel)
|
||||
{
|
||||
#if true
|
||||
//try
|
||||
@ -64,7 +64,7 @@ namespace HisenceYoloDetection
|
||||
|
||||
string blockIndex = cam1TwoML.ResultDetails[i].LabelDisplay;
|
||||
Rect area2 = new Rect();
|
||||
if (blockIndex == "2")//根据旋钮扩大范围
|
||||
if (blockIndex == "2"|| blockIndex == "7")//根据旋钮扩大范围
|
||||
{
|
||||
areaBlack.X -= rectsx;
|
||||
areaBlack.Y -= rectsy;
|
||||
@ -394,9 +394,26 @@ namespace HisenceYoloDetection
|
||||
//第二快 卷积匹配
|
||||
string PathSql = XKSQL.TwoblockPath;
|
||||
//
|
||||
|
||||
Rect rectsql = CheckDiffSciHelper.strChangeRect(TwoRectstr);
|
||||
Rect rectDet = CheckDiffSciHelper.strChangeRect(XKDet.TwoRect);
|
||||
bool twoif2 = CheckDiffSciHelper.CheckDiffSci(PathSql, detMat, rectsql, rectDet,(bool)XKSQL.TwoIFWhile, "D://");
|
||||
bool twoif2 = CheckDiffSciHelper.CheckDiffSci(PathSql, detMat, rectsql, rectDet,(bool)XKSQL.TwoIFWhile, "D://Test");
|
||||
DateTime dt = DateTime.Now;
|
||||
using (StreamWriter sw = new StreamWriter("D://Hisence//logsMatch.log", true))
|
||||
{
|
||||
string filename = dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString();
|
||||
sw.WriteLine(filename + "\n");
|
||||
sw.WriteLine(oneBlockWordSql + " " + oneBlockWordDet + "\n");
|
||||
sw.WriteLine(twoBlockWordSql + " " + twoBlockWordDet + "\n");
|
||||
sw.WriteLine(threeBlockWordSql + " " + threeBlockWordDet + "\n");
|
||||
sw.WriteLine(fourBlockWordSql + " " + fourBlockWordDet + "\n");
|
||||
sw.WriteLine(fiveBlockWordSql + " " + fiveBlockWordDet + "\n");
|
||||
sw.WriteLine(sixBlockWordSql + " " + sixBlockWordDet + "\n");
|
||||
sw.WriteLine(sevenBlockWordSql + " " + sevenBlockWordDet + "\n");
|
||||
sw.WriteLine(eightBlockWordSql + " " + eightBlockWordDet + "\n");
|
||||
sw.WriteLine( " 卷积匹配 " + twoif2 + "\n");
|
||||
sw.Flush();
|
||||
}
|
||||
//第三块区域一直都是false
|
||||
if (OneIF && TwoIF && ThreeIF && FourIF && FiveIF && SixIF && SenvenIF && EightIF&& twoif2)
|
||||
{
|
||||
@ -419,35 +436,48 @@ namespace HisenceYoloDetection
|
||||
}
|
||||
public static bool isMatchStr(string SqlText, string DetText)
|
||||
{
|
||||
if (SqlText.Contains("##") && DetText.Contains("##"))
|
||||
{
|
||||
// 计算Levenshtein距离
|
||||
int distance = LevenshteinDistance(SqlText, DetText);
|
||||
|
||||
// 计算相似度(相似度等于1减去标准化的Levenshtein距离)
|
||||
double similarity = 1 - ((double)distance / Math.Max(SqlText.Length, DetText.Length));
|
||||
bool areEqual = false;
|
||||
if (similarity<0.5)
|
||||
{
|
||||
areEqual = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
areEqual = true;
|
||||
}
|
||||
//string[] sArraysql = Regex.Split(SqlText, "##", RegexOptions.IgnoreCase);
|
||||
//string[] sArraydet = Regex.Split(DetText, "##", RegexOptions.IgnoreCase);
|
||||
//bool areEqual = sArraysql.OrderBy(x => x).SequenceEqual(sArraydet.OrderBy(x => x));
|
||||
return areEqual;
|
||||
|
||||
}
|
||||
else if ((SqlText == "" || SqlText == null) && (DetText == "" || DetText == null))
|
||||
if ((SqlText == "" || SqlText == null) && (DetText == "" || DetText == null))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
if(SqlText!=null&& DetText!=null)
|
||||
{
|
||||
if (SqlText.Contains("##") && DetText.Contains("##"))
|
||||
{
|
||||
// 计算Levenshtein距离
|
||||
int distance = LevenshteinDistance(SqlText, DetText);
|
||||
|
||||
// 计算相似度(相似度等于1减去标准化的Levenshtein距离)
|
||||
double similarity = 1 - ((double)distance / Math.Max(SqlText.Length, DetText.Length));
|
||||
bool areEqual = false;
|
||||
if (similarity < 0.5)
|
||||
{
|
||||
areEqual = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
areEqual = true;
|
||||
}
|
||||
//string[] sArraysql = Regex.Split(SqlText, "##", RegexOptions.IgnoreCase);
|
||||
//string[] sArraydet = Regex.Split(DetText, "##", RegexOptions.IgnoreCase);
|
||||
//bool areEqual = sArraysql.OrderBy(x => x).SequenceEqual(sArraydet.OrderBy(x => x));
|
||||
return areEqual;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
// 计算Levenshtein距离
|
||||
|
@ -267,8 +267,8 @@ namespace XKRS.Device.SimboVision.SimboHelper
|
||||
finally
|
||||
{
|
||||
|
||||
originMat?.Dispose();
|
||||
originMat = null;
|
||||
// originMat?.Dispose();
|
||||
// originMat = null;
|
||||
|
||||
|
||||
// GC.Collect();
|
||||
|
BIN
HisenceYoloDetection/yyb.douyin.ico
Normal file
BIN
HisenceYoloDetection/yyb.douyin.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.8 KiB |
52
XKRS.UI/Canvas.Designer.cs
generated
Normal file
52
XKRS.UI/Canvas.Designer.cs
generated
Normal file
@ -0,0 +1,52 @@
|
||||
namespace XKRS.UI
|
||||
{
|
||||
partial class Canvas
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Component Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// Canvas
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.Name = "Canvas";
|
||||
this.Size = new System.Drawing.Size(190, 148);
|
||||
this.SizeChanged += new System.EventHandler(this.Canvas_SizeChanged);
|
||||
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Canvas_KeyDown);
|
||||
this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.Canvas_KeyUp);
|
||||
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Canvas_MouseDown);
|
||||
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Canvas_MouseMove);
|
||||
this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Canvas_MouseUp);
|
||||
this.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.Canvas_MouseWheel);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
1238
XKRS.UI/Canvas.cs
Normal file
1238
XKRS.UI/Canvas.cs
Normal file
File diff suppressed because it is too large
Load Diff
60
XKRS.UI/Canvas.resx
Normal file
60
XKRS.UI/Canvas.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
32
XKRS.UI/ClickArea.cs
Normal file
32
XKRS.UI/ClickArea.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace XKRS.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// 点击的区域
|
||||
/// </summary>
|
||||
internal enum ClickArea
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 未知区域
|
||||
/// </summary>
|
||||
AREA_UNKNOW,
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 图片区域
|
||||
/// </summary>
|
||||
AREA_IMG,
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 缺陷元素区域
|
||||
/// </summary>
|
||||
AREA_DEFECT,
|
||||
}
|
||||
}
|
434
XKRS.UI/Defect.cs
Normal file
434
XKRS.UI/Defect.cs
Normal file
@ -0,0 +1,434 @@
|
||||
using Microsoft.VisualBasic.ApplicationServices;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using XKRS.UI.Helper;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace XKRS.UI
|
||||
{
|
||||
public class Defect
|
||||
{
|
||||
public string File { get; private set; }
|
||||
public bool Selected { get; private set; }
|
||||
private Rectangle _rectangle { get; }
|
||||
public GraphicsPath Path { get; set; }
|
||||
public Bitmap OriBitMap { get; set; }
|
||||
public PointF _defectCenterPoint { get; }
|
||||
|
||||
private float _wholeDScale = 1f;
|
||||
|
||||
private float _xDScale = 1f;
|
||||
|
||||
private float _yDScale = 1f;
|
||||
|
||||
private float[] _lastSetScale = new float[3] { 1f, 1f, 1f };
|
||||
|
||||
private double _dRoute;
|
||||
|
||||
private double _totalDRoute;
|
||||
|
||||
private PointF _initialPosition;
|
||||
|
||||
private PointF _lastSetPosition;
|
||||
|
||||
private float _xDMove;
|
||||
|
||||
private float _yDMove;
|
||||
|
||||
private Brush[] _brushDColors = new Brush[5]
|
||||
{ Brushes.Red, Brushes.Yellow, Brushes.Blue, Brushes.Green, Brushes.Black };
|
||||
|
||||
private int _selectedColorIndex = 0;
|
||||
|
||||
private Matrix _matrix;
|
||||
|
||||
private PointF _upperLeftPoint;
|
||||
|
||||
/// <summary>
|
||||
/// 每个缺陷自身上一次赋值的缩放值
|
||||
/// </summary>
|
||||
public float[] LastSetScale
|
||||
{
|
||||
get
|
||||
{
|
||||
return _lastSetScale;
|
||||
}
|
||||
set
|
||||
{
|
||||
_lastSetScale = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 每个缺陷自身的整体缩放比例
|
||||
/// </summary>
|
||||
public float WholeDScale
|
||||
{
|
||||
get
|
||||
{
|
||||
return _wholeDScale;
|
||||
}
|
||||
set
|
||||
{
|
||||
_wholeDScale = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 每个缺陷自身的横向缩放
|
||||
/// </summary>
|
||||
public float XDScale
|
||||
{
|
||||
get
|
||||
{
|
||||
return _xDScale;
|
||||
}
|
||||
set
|
||||
{
|
||||
_xDScale = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 每个缺陷自身的竖向缩放
|
||||
/// </summary>
|
||||
public float YDScale
|
||||
{
|
||||
get
|
||||
{
|
||||
return _yDScale;
|
||||
}
|
||||
set
|
||||
{
|
||||
_yDScale = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 每个缺陷自身旋转过程中的角度
|
||||
/// </summary>
|
||||
public double DRoute
|
||||
{
|
||||
get
|
||||
{
|
||||
return Math.Ceiling(_dRoute % 360);
|
||||
}
|
||||
set
|
||||
{
|
||||
_dRoute = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 每个缺陷自身旋转的总角度
|
||||
/// </summary>
|
||||
public double TotalDRoute
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_totalDRoute % 360 > 0)
|
||||
{
|
||||
return _totalDRoute % 360;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (_totalDRoute + 360) % 360;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
_totalDRoute = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 每个缺陷自身开始加载时中心点在控件坐标系中的坐标
|
||||
/// </summary
|
||||
public PointF InitialPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
return _initialPosition;
|
||||
}
|
||||
set
|
||||
{
|
||||
_initialPosition = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 上一次赋值的位移终点
|
||||
/// </summary>
|
||||
public PointF LastSetPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
return _lastSetPosition;
|
||||
}
|
||||
set
|
||||
{
|
||||
_lastSetPosition = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 每个缺陷自身在控件坐标系X轴方向上的位移
|
||||
/// </summary>
|
||||
public float XDMove
|
||||
{
|
||||
get
|
||||
{
|
||||
return (int)_xDMove;
|
||||
}
|
||||
set
|
||||
{
|
||||
_xDMove = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 每个缺陷自身在空间坐标系Y轴方向上的位移
|
||||
/// </summary>
|
||||
public float YDMove
|
||||
{
|
||||
get
|
||||
{
|
||||
return (int)_yDMove;
|
||||
}
|
||||
set
|
||||
{
|
||||
_yDMove = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 每个缺陷自身的边框颜色
|
||||
/// </summary>
|
||||
public Brush[] BrushDColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return _brushDColors;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 每个缺陷自身在调整颜色控件中选择的边框颜色序列
|
||||
/// </summary>
|
||||
public int SelectedColorIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
return _selectedColorIndex;
|
||||
}
|
||||
set
|
||||
{
|
||||
_selectedColorIndex = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 每个缺陷自身的矩阵,该矩阵需要左乘背景图的矩阵才是最终看到的显示效果
|
||||
/// </summary>
|
||||
public Matrix PrivateMatrix
|
||||
{
|
||||
get
|
||||
{
|
||||
return _matrix;
|
||||
}
|
||||
private set
|
||||
{
|
||||
_matrix = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 每个缺陷自身的左上角顶点坐标
|
||||
/// </summary>
|
||||
public PointF UpperLeftPoint
|
||||
{
|
||||
get
|
||||
{
|
||||
return _upperLeftPoint;
|
||||
}
|
||||
private set
|
||||
{
|
||||
_upperLeftPoint = value;
|
||||
}
|
||||
}
|
||||
|
||||
public Defect(string file) : this(file, new Matrix())
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public Defect(string file, Matrix m)
|
||||
{
|
||||
File = file;
|
||||
|
||||
using (Stream s = System.IO.File.Open(file, FileMode.Open))
|
||||
{
|
||||
OriBitMap = (Bitmap)Image.FromStream(s);
|
||||
}
|
||||
|
||||
PrivateMatrix = m;
|
||||
|
||||
UpperLeftPoint = new PointF(0, 0);
|
||||
_defectCenterPoint = new PointF(UpperLeftPoint.X + OriBitMap.Width / 2, UpperLeftPoint.Y + OriBitMap.Height / 2);
|
||||
_rectangle = new Rectangle((int)UpperLeftPoint.X, (int)UpperLeftPoint.Y, OriBitMap.Width, OriBitMap.Height);
|
||||
Path = new GraphicsPath();
|
||||
Path.AddRectangle(_rectangle);
|
||||
Path.CloseAllFigures();
|
||||
}
|
||||
|
||||
public Defect(string file, PointF[] points, Matrix m)
|
||||
{
|
||||
File = file;
|
||||
|
||||
using (Stream s = System.IO.File.Open(file, FileMode.Open))
|
||||
{
|
||||
Bitmap midBitmap = (Bitmap)Image.FromStream(s);
|
||||
Path = new GraphicsPath();
|
||||
Path.AddPolygon(points);
|
||||
Path.CloseAllFigures();
|
||||
OriBitMap = BitmapCrop(midBitmap, Path);
|
||||
}
|
||||
PrivateMatrix = m;
|
||||
|
||||
RectangleF rec = Path.GetBounds();
|
||||
UpperLeftPoint = new PointF(rec.X, rec.Y);
|
||||
_defectCenterPoint = new PointF(UpperLeftPoint.X + OriBitMap.Width / 2, UpperLeftPoint.Y + OriBitMap.Height / 2);
|
||||
_rectangle = new Rectangle((int)rec.X, (int)rec.Y, OriBitMap.Width, OriBitMap.Height);
|
||||
PrivateMatrix.Translate(-rec.X, -rec.Y);
|
||||
}
|
||||
|
||||
public Defect(Rectangle rectangle, Matrix m)
|
||||
{
|
||||
|
||||
Path = new GraphicsPath();
|
||||
Path.AddRectangle(rectangle);
|
||||
Path.CloseAllFigures();
|
||||
OriBitMap = BitmapCropRect(Path);
|
||||
PrivateMatrix = m;
|
||||
|
||||
RectangleF rec = Path.GetBounds();
|
||||
UpperLeftPoint = new PointF(rec.X, rec.Y);
|
||||
_defectCenterPoint = new PointF(UpperLeftPoint.X + OriBitMap.Width / 2, UpperLeftPoint.Y + OriBitMap.Height / 2);
|
||||
_rectangle = new Rectangle((int)rec.X, (int)rec.Y, OriBitMap.Width, OriBitMap.Height);
|
||||
PrivateMatrix.Translate(-rec.X, -rec.Y);
|
||||
}
|
||||
public Bitmap BitmapCropRect( GraphicsPath path)
|
||||
{
|
||||
RectangleF rec = path.GetBounds();
|
||||
int left = (int)rec.Left;
|
||||
int top = (int)rec.Top;
|
||||
int width = (int)rec.Width;
|
||||
int height = (int)rec.Height;
|
||||
Bitmap imgCropped = new Bitmap(width, height);
|
||||
//Bitmap img = (Bitmap)bitmap.Clone();
|
||||
Region r = new Region(path);
|
||||
for (int i = left; i < left + width; i++)
|
||||
{
|
||||
for (int j = top; j < top + height; j++)
|
||||
{
|
||||
if (!r.IsVisible(i, j))
|
||||
{
|
||||
imgCropped.SetPixel(i - left, j - top, Color.FromArgb(0, 255, 255, 255));
|
||||
}
|
||||
else
|
||||
{
|
||||
imgCropped.SetPixel(i - left, j - top, Color.FromArgb(0, 0, 255, 255));
|
||||
}
|
||||
}
|
||||
}
|
||||
return imgCropped;
|
||||
}
|
||||
public Bitmap BitmapCrop(Bitmap bitmap, GraphicsPath path)
|
||||
{
|
||||
RectangleF rec = path.GetBounds();
|
||||
int left = (int)rec.Left;
|
||||
int top = (int)rec.Top;
|
||||
int width = (int)rec.Width;
|
||||
int height = (int)rec.Height;
|
||||
Bitmap imgCropped = new Bitmap(width, height);
|
||||
Bitmap img = (Bitmap)bitmap.Clone();
|
||||
Region r = new Region(path);
|
||||
for (int i = left; i < left + width; i++)
|
||||
{
|
||||
for (int j = top; j < top + height; j++)
|
||||
{
|
||||
if (!r.IsVisible(i, j))
|
||||
{
|
||||
imgCropped.SetPixel(i - left, j - top, Color.FromArgb(0, 255, 255, 255));
|
||||
}
|
||||
else
|
||||
{
|
||||
imgCropped.SetPixel(i - left, j - top, img.GetPixel(i, j));
|
||||
}
|
||||
}
|
||||
}
|
||||
return imgCropped;
|
||||
}
|
||||
|
||||
public void DrawPath(Graphics graphics)
|
||||
{
|
||||
graphics.DrawPath(new Pen(BrushDColor[SelectedColorIndex], 1f), Path);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void Select()
|
||||
{
|
||||
Selected = true;
|
||||
}
|
||||
|
||||
|
||||
public void UnSelect()
|
||||
{
|
||||
Selected = false;
|
||||
}
|
||||
|
||||
|
||||
public bool ContainPoint(Point p)
|
||||
{
|
||||
return _rectangle.Contains(p);
|
||||
}
|
||||
|
||||
|
||||
//Prepend参数指先操作,Append参数指后操作
|
||||
public void Move(float x, float y, MatrixOrder order = MatrixOrder.Prepend)
|
||||
{
|
||||
switch (order)
|
||||
{
|
||||
default:
|
||||
case MatrixOrder.Prepend:
|
||||
//设定平移矩阵,order默认为predend,平移矩阵左乘_matrix
|
||||
_matrix.Translate(x, y);
|
||||
break;
|
||||
case MatrixOrder.Append:
|
||||
_matrix.Translate(x, y, MatrixOrder.Append);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void Scale(float scaleX, float scaleY)
|
||||
{
|
||||
_matrix.Scale(scaleX, scaleY);
|
||||
}
|
||||
public void Rotate(float angle)
|
||||
{
|
||||
_matrix.Rotate(angle);
|
||||
}
|
||||
public void RotateAt(float angle, PointF point)
|
||||
{
|
||||
_matrix.RotateAt(angle, point);
|
||||
}
|
||||
}
|
||||
}
|
56
XKRS.UI/Helper/PointHelper.cs
Normal file
56
XKRS.UI/Helper/PointHelper.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace XKRS.UI.Helper
|
||||
{
|
||||
internal static class PointHelper
|
||||
{
|
||||
public static Point ToPoint(this PointF pf)
|
||||
{
|
||||
return new Point((int)pf.X, (int)pf.Y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将相对于控件的坐标转换为相对于图像的坐标
|
||||
/// </summary>
|
||||
/// <param name="p">控件中指定点的点位坐标,坐标原点为控件左上角</param>
|
||||
/// <returns>该点以图像坐标系为基准的坐标值,坐标原点为图像左上角</returns>
|
||||
public static PointF ToImageCoordinate(this Point p, Matrix m)
|
||||
{
|
||||
PointF pf = new PointF(p.X, p.Y);
|
||||
return ToImageCoordinate(pf, m);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将相对于控件的坐标转换为相对于图像的坐标
|
||||
/// </summary>
|
||||
/// <param name="p">控件中指定点的点位坐标,坐标原点为控件左上角</param>
|
||||
/// <returns>该点以图像坐标系为基准的坐标值,坐标原点为图像左上角</returns>
|
||||
public static PointF ToImageCoordinate(this PointF p, Matrix m)
|
||||
{
|
||||
PointF[] ps = new PointF[] { p };
|
||||
Matrix invertMatrix = m.Clone();
|
||||
//想要从旧空间到新空间的逆变换,所以我们需要对这个矩阵求逆
|
||||
invertMatrix.Invert();
|
||||
invertMatrix.TransformPoints(ps);
|
||||
return ps[0];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将相对于图像的坐标转换为相对于控件坐标系
|
||||
/// </summary>
|
||||
/// <param name="p">图像中指定点的点位坐标,坐标原点为图像左上角</param>
|
||||
/// <returns>该点以空间坐标系为基准的坐标值,坐标原点为空间坐左上角</returns>
|
||||
public static PointF ToControlCoordinate(this PointF p, Matrix m)
|
||||
{
|
||||
PointF[] ps = new PointF[] { p };
|
||||
m.TransformPoints(ps);
|
||||
return ps[0];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
12
XKRS.UI/Helper/RectangleHelper.cs
Normal file
12
XKRS.UI/Helper/RectangleHelper.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace XKRS.UI.Helper
|
||||
{
|
||||
internal static class RectangleHelper
|
||||
{
|
||||
}
|
||||
}
|
15
XKRS.UI/ILoadToCanvas.cs
Normal file
15
XKRS.UI/ILoadToCanvas.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace XKRS.UI
|
||||
{
|
||||
public interface ILoadToCanvas
|
||||
{
|
||||
|
||||
void OnLoadToCanvas(Canvas canvas);
|
||||
|
||||
}
|
||||
}
|
47
XKRS.UI/Polygon.cs
Normal file
47
XKRS.UI/Polygon.cs
Normal file
@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace XKRS.UI
|
||||
{
|
||||
public class Polygon
|
||||
{
|
||||
// public ShapesContent[]? shapes { get; set; }
|
||||
|
||||
public Color FillColor { get; set; }
|
||||
public Color LineColor { get; set; }
|
||||
|
||||
private List<PointF> Points = new List<PointF>();
|
||||
|
||||
public Polygon()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Polygon(Color fillColor, Color lineColor, List<PointF> points)
|
||||
{
|
||||
FillColor = fillColor;
|
||||
LineColor = lineColor;
|
||||
Points = points;
|
||||
}
|
||||
|
||||
public void SetPoints(List<PointF> pointsList)
|
||||
{
|
||||
this.Points = pointsList;
|
||||
}
|
||||
public void AddPoint(PointF p)
|
||||
{
|
||||
Points.Add(p);
|
||||
}
|
||||
public void RemovePoint(int index)
|
||||
{
|
||||
Points.RemoveAt(index);
|
||||
}
|
||||
public List<PointF> GetPoints()
|
||||
{
|
||||
return Points;
|
||||
}
|
||||
}
|
||||
}
|
18
XKRS.UI/XKRS.UI.csproj
Normal file
18
XKRS.UI/XKRS.UI.csproj
Normal file
@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<BaseOutputPath>.\bin\X64\Debug</BaseOutputPath>
|
||||
<OutputType>Library</OutputType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="OpenCvSharp4" Version="4.5.3.20210817" />
|
||||
<PackageReference Include="OpenCvSharp4.runtime.win" Version="4.5.3.20210817" />
|
||||
<PackageReference Include="SunnyUI" Version="3.2.3.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
BIN
libs/XKRS.UI.dll
Normal file
BIN
libs/XKRS.UI.dll
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user