穴位有无优化返回值类型

master
lhiven 1 year ago
parent de8a4053fb
commit 929798570e

@ -15,6 +15,12 @@ using System.Windows.Forms;
namespace Rs.MotionPlat.Flow.Camera
{
public class SlotProductHasOrNotResult
{
public bool HasProduct { get; set; } = false;
public HObject SearchRegion { get; set; }
public HObject SourceImage { get; set; }
}
/// <summary>
/// 视觉管理类
/// </summary>
@ -34,80 +40,47 @@ namespace Rs.MotionPlat.Flow.Camera
/// StockTray盘是否有料
/// 0 无料 1 有料 负数 错误返回错误码
/// </summary>
public static int StockTrayHasProduct(Action<HObject> checkFinishedEvent)
public static SlotProductHasOrNotResult StockTrayHasProduct()
{
SlotProductHasOrNotResult result = new SlotProductHasOrNotResult();
string cameraName = "upCamera";
string LightName = "";
//1、拍照
string m_savePath = Path.Combine("Recipe", GlobalVar.CurRecipe, "周转盘产品有无");
//IniHelper iniHelper = new IniHelper(Path.Combine(m_savePath,"default.ini"));
//string AngleStart = iniHelper.ReadValue("ModelParam", "AngleStart", "-10");
//string AngleExtent = iniHelper.ReadValue("ModelParam", "AngleExtent", "10");
//string Score = iniHelper.ReadValue("ModelParam", "Score", "0.5");
//string text = Path.Combine(m_savePath, "model.shm");
//HOperatorSet.ReadShapeModel(text, out var modelID);
string m_savePath = Path.Combine("Recipe", GlobalVar.CurRecipe, "料仓料盘产品有无");
HOperatorSet.ReadRegion(out HObject searchRegion, Path.Combine(m_savePath , "搜索区域.reg"));
if(searchRegion.IsInitialized())
{
result.SearchRegion = searchRegion;
ImageProcess.ClearManualTrigger();
HikCamera.Instance.SetTrigger(cameraName, ETriggerMode.Manual);
HikCamera.Instance.SetExposure(cameraName, GlobalVar.UpCameraExposureTime);
HikCamera.Instance.SetGain(cameraName, GlobalVar.UpCameraGain);
AxisControl.LoadX.ComparePulse(2, false);
//LightName = SysConfigParam.GetValue<string>(cameraName + "LightName");
//if (!string.IsNullOrEmpty(LightName))
//{
// if (!string.IsNullOrEmpty(cameraName))
// {
// IoManager.Instance.WriteOut(LightName, 0);
// Thread.Sleep(50);
// IoManager.Instance.WriteOut(LightName, 1);
// Thread.Sleep(100);
// HikCamera.Instance.Grab(cameraName);
// }
// else
// {
// Msg.ShowError("请先先择相机");
// }
//}
//else
//{
// Msg.ShowError("未设置相机对应的光源,请到变量中配置!");
//}
//AxisControl.LoadY.ComparePulse(0x01);
//Thread.Sleep(50);
//2、等待相机返回结果
bool cameraOk = ImageProcess.manualTriggerEvent.WaitOne(3000);
if (cameraOk)
{
HObject hImage = new HObject();
IoManager.Instance.WriteOut(LightName, 0);
HObject image = ImageProcess.GetManualImage();
HOperatorSet.WriteImage(image, "bmp", 0, "d://images//111");
if (cameraName == SysConfigParam.GetValue<string>("UpCameraName"))
{
HOperatorSet.RotateImage(image, out hImage, SysConfigParam.GetValue<double>("UpCameraRotate"), "constant");
}
HOperatorSet.WriteImage(hImage, "bmp", 0, "d://images//111");
checkFinishedEvent?.Invoke(hImage);
if (searchRegion.IsInitialized())
{
result.SourceImage = hImage;
HOperatorSet.ReduceDomain(hImage, searchRegion, out HObject searchImg);
HOperatorSet.Threshold(searchImg, out HObject whiteRegion, new HTuple(GlobalVar.StockTrayHaveOrNotGrayMin), new HTuple(GlobalVar.StockTrayHaveOrNotGrayMax));
HOperatorSet.AreaCenter(whiteRegion, out HTuple area, out HTuple row, out HTuple column);
if (area.D > GlobalVar.StockTrayHaveOrNotGrayArea)
return 1;
//HOperatorSet.WriteImage(searchImg, "bmp", 0, "d://images//111");
//HOperatorSet.GetShapeModelContours(out HObject modelContours, modelID, 1);
//HOperatorSet.FindShapeModel(searchImg, modelID, AngleTool.Deg2Rad(double.Parse(AngleStart)), AngleTool.Deg2Rad(Math.Abs((double.Parse(AngleExtent) - double.Parse(AngleStart)))), new HTuple(double.Parse(Score)), 1, 0.5, "least_squares", 0, 0.9, out HTuple row, out HTuple column, out HTuple angle, out HTuple score);
//if(score.Length>0)
//{
// return 1;
//}
{
result.HasProduct = true;
}
else
{
result.HasProduct = false;
}
}
}
//3、返回结果
return 0;
return result;
}
/// <summary>
@ -115,83 +88,50 @@ namespace Rs.MotionPlat.Flow.Camera
/// 0 无料 1 有料 负数 错误返回错误码
/// </summary>
/// <returns></returns>
public static int TurnoverTrayHasProduct(Action<HObject> checkFinishedEvent)
public static SlotProductHasOrNotResult TurnoverTrayHasProduct(Action<HObject> checkFinishedEvent)
{
SlotProductHasOrNotResult result = new SlotProductHasOrNotResult();
string cameraName = "upCamera";
string LightName = "";
//1、拍照
ImageProcess.ClearManualTrigger();
string m_savePath = Path.Combine("Recipe", GlobalVar.CurRecipe, "周转盘产品定位");
IniHelper iniHelper = new IniHelper(Path.Combine(m_savePath, "default.ini"));
string AngleStart = iniHelper.ReadValue("ModelParam", "AngleStart", "-10");
string AngleExtent = iniHelper.ReadValue("ModelParam", "AngleExtent", "10");
string Score = iniHelper.ReadValue("ModelParam", "Score", "0.5");
string text = Path.Combine(m_savePath, "model.shm");
HOperatorSet.ReadShapeModel(text, out var modelID);
HOperatorSet.ReadRegion(out HObject searchRegion, Path.Combine(m_savePath, "search.reg"));
string m_savePath = Path.Combine("Recipe", GlobalVar.CurRecipe, "周转盘产品有无");
HOperatorSet.ReadRegion(out HObject searchRegion, Path.Combine(m_savePath, "搜索区域.reg"));
result.SearchRegion = searchRegion;
ImageProcess.ClearManualTrigger();
HikCamera.Instance.SetTrigger(cameraName, ETriggerMode.Manual);
HikCamera.Instance.SetExposure(cameraName, GlobalVar.UpCameraExposureTime);
HikCamera.Instance.SetGain(cameraName, GlobalVar.UpCameraGain);
AxisControl.LoadX.ComparePulse(2, false);
//LightName = SysConfigParam.GetValue<string>(cameraName + "LightName");
//if (!string.IsNullOrEmpty(LightName))
//{
// if (!string.IsNullOrEmpty(cameraName))
// {
// IoManager.Instance.WriteOut(LightName, 0);
// Thread.Sleep(50);
// IoManager.Instance.WriteOut(LightName, 1);
// Thread.Sleep(100);
// HikCamera.Instance.Grab(cameraName);
// }
// else
// {
// Msg.ShowError("请先先择相机");
// }
//}
//else
//{
// Msg.ShowError("未设置相机对应的光源,请到变量中配置!");
//}
//AxisControl.LoadY.ComparePulse(0x01);
//Thread.Sleep(50);
//2、等待相机返回结果
bool cameraOk = ImageProcess.manualTriggerEvent.WaitOne(3000);
if (cameraOk)
{
HObject hImage = new HObject();
//IoManager.Instance.WriteOut(LightName, 0);
HObject image = ImageProcess.GetManualImage();
if (cameraName == SysConfigParam.GetValue<string>("UpCameraName"))
{
HOperatorSet.RotateImage(image, out hImage, SysConfigParam.GetValue<double>("UpCameraRotate"), "constant");
}
checkFinishedEvent?.Invoke(hImage);
result.SourceImage = hImage;
if (searchRegion.IsInitialized())
{
HOperatorSet.WriteImage(hImage, "bmp", 0, "d://images/22222");
HOperatorSet.ReduceDomain(hImage, searchRegion, out HObject searchImg);
HOperatorSet.Threshold(searchImg, out HObject whiteRegion, new HTuple(GlobalVar.TurnoverTrayHaveOrNotGrayMin), new HTuple(GlobalVar.TurnoverTrayHaveOrNotGrayMax));
//checkFinishedEvent?.Invoke(hImage);
HOperatorSet.AreaCenter(whiteRegion, out HTuple area, out HTuple row1, out HTuple column1);
if(area.D>GlobalVar.TurnoverTrayHaveOrNotGrayArea)
{
return 1;
result.HasProduct = true;
}
else
{
result.HasProduct = false;
}
//HOperatorSet.GetShapeModelContours(out HObject modelContours, modelID, 1);
//HOperatorSet.FindShapeModel(searchImg, modelID, AngleTool.Deg2Rad(double.Parse(AngleStart)), AngleTool.Deg2Rad(Math.Abs((double.Parse(AngleExtent) - double.Parse(AngleStart)))), new HTuple(double.Parse(Score)), 1, 0.5, "least_squares", 0, 0.9, out HTuple row, out HTuple column, out HTuple angle, out HTuple score);
//if (score.Length > 0)
//{
// return 1;
//}
}
}
//3、返回结果
return 0;
return result;
}
/// <summary>
@ -227,18 +167,20 @@ namespace Rs.MotionPlat.Flow.Camera
vr.OffsetY = -1 * (row.D - upCameraScanBarCodeModel.ModelMatchResult[0].D) * GlobalVar.UpCameraMmPerPixel;
vr.OffsetR = AngleTool.Rad2Deg((angle.D - upCameraScanBarCodeModel.ModelMatchResult[2].D));
vr.SourceImage = image;
if (Math.Abs(vr.OffsetX) < GlobalVar.TurnoverTrayLocateXRange
&& Math.Abs(vr.OffsetY) < GlobalVar.TurnoverTrayLocateYRange
&& Math.Abs(vr.OffsetR) < GlobalVar.TurnoverTrayLocateRRange)
{
vr.SearchModelOK = true;
//if (Math.Abs(vr.OffsetX) < GlobalVar.TurnoverTrayLocateXRange
// && Math.Abs(vr.OffsetY) < GlobalVar.TurnoverTrayLocateYRange
// && Math.Abs(vr.OffsetR) < GlobalVar.TurnoverTrayLocateRRange)
//{
// vr.SearchModelOK = true;
//}
}
else
{
vr.SearchModelOK = false;
}
}
}
else
{
vr.SearchModelOK = true;

Loading…
Cancel
Save