You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
148 lines
4.7 KiB
148 lines
4.7 KiB
#include "ALL_Detect.hpp"
|
|
#include "CheckErrorCode.hpp"
|
|
#include "CheckUtil.hpp"
|
|
using namespace cv;
|
|
using namespace std;
|
|
// 检测模型 单个小图 输入模型图片尺寸
|
|
#define SRC_CUT_IMAGE_WIDTH 512
|
|
#define SRC_CUT_IMAGE_HEIGHT 512
|
|
std::shared_ptr<ImgCheckBase> ImgCheckBase::GetInstance()
|
|
{
|
|
return std::shared_ptr<ImgCheckBase>(new ALL_Detect());
|
|
}
|
|
|
|
ALL_Detect::ALL_Detect()
|
|
{
|
|
}
|
|
|
|
ALL_Detect::~ALL_Detect()
|
|
{
|
|
printf("----------------~ALL_Detect \n");
|
|
}
|
|
|
|
int ALL_Detect::RunStart(void *pconfig1)
|
|
{
|
|
// 初始化
|
|
m_cam_param.copy(*(Cam_Param *)pconfig1);
|
|
RunInfoST runconfig;
|
|
runconfig.flag0 = m_cam_param.cam_position;
|
|
if (m_cam_param.check_param_path.empty() || m_cam_param.AIModel_param_path.empty())
|
|
{
|
|
printf("check_param_path or AIModel_param_path is empty\n");
|
|
return -1;
|
|
}
|
|
if (m_cam_param.AIModel_param_path.back() != '/')
|
|
m_cam_param.AIModel_param_path += '/';
|
|
if (m_cam_param.check_param_path.back() != '/')
|
|
m_cam_param.check_param_path += '/';
|
|
|
|
switch (m_cam_param.cam_position)
|
|
{
|
|
case CAMERA_TOP_1:
|
|
{
|
|
if (!m_checkBase)
|
|
m_checkBase = std::make_shared<Top_Detect>();
|
|
runconfig.str_AIModelJson = m_cam_param.AIModel_param_path + "AIModel_Top.json";
|
|
runconfig.str_RunJson = m_cam_param.check_param_path + "param_Top-1.json";
|
|
break;
|
|
}
|
|
case CAMERA_TOP_2:
|
|
{
|
|
if (!m_checkBase)
|
|
m_checkBase = std::make_shared<Top_Detect>();
|
|
runconfig.str_AIModelJson = m_cam_param.AIModel_param_path + "AIModel_Top.json";
|
|
runconfig.str_RunJson = m_cam_param.check_param_path + "param_Top-2.json";
|
|
break;
|
|
}
|
|
case CAMERA_SIDE_1:
|
|
{
|
|
if (!m_checkBase)
|
|
m_checkBase = std::make_shared<Side_Detect>();
|
|
runconfig.str_AIModelJson = m_cam_param.AIModel_param_path + "AIModel_Side.json";
|
|
runconfig.str_RunJson = m_cam_param.check_param_path + "param_Side-1.json";
|
|
break;
|
|
}
|
|
case CAMERA_SIDE_2:
|
|
{
|
|
if (!m_checkBase)
|
|
m_checkBase = std::make_shared<Side_Detect>();
|
|
runconfig.str_AIModelJson = m_cam_param.AIModel_param_path + "AIModel_Side.json";
|
|
runconfig.str_RunJson = m_cam_param.check_param_path + "param_Side-2.json";
|
|
break;
|
|
}
|
|
case CAMERA_DOWN_1:
|
|
{
|
|
if (!m_checkBase)
|
|
m_checkBase = std::make_shared<Down_Detect>();
|
|
if (!m_down_angle_detect)
|
|
m_down_angle_detect = std::make_shared<Down_Angle_Detect>();
|
|
runconfig.str_AIModelJson = m_cam_param.AIModel_param_path + "AIModel_Down.json";
|
|
runconfig.str_RunJson = m_cam_param.check_param_path + "param_Down.json";
|
|
auto ret = this->m_down_angle_detect->RunStart((void *)&runconfig);
|
|
if (ret != 0)
|
|
{
|
|
std::cout << "Down_Angle_Detect RunStart failed, ret=" << ret << std::endl;
|
|
return ret;
|
|
}
|
|
break;
|
|
}
|
|
case CAMERA_Feeding:
|
|
case CAMERA_Blanking:
|
|
{
|
|
if (!m_checkBase)
|
|
m_checkBase = std::make_shared<Chip_Detect>();
|
|
runconfig.str_AIModelJson = m_cam_param.AIModel_param_path + "AIModel_Chip.json";
|
|
// runconfig.str_RunJson = m_cam_param.check_param_path + "param_Chip.json";
|
|
break;
|
|
}
|
|
default:
|
|
break;
|
|
}
|
|
return this->m_checkBase->RunStart((void *)&runconfig);
|
|
}
|
|
|
|
int ALL_Detect::CheckImg(std::shared_ptr<shareImage> p, std::shared_ptr<CheckResult> &pResult)
|
|
{
|
|
if (m_cam_param.cam_position != p->cam_position)
|
|
{
|
|
std::cout << "ERROR: ALL_Detect cam_position not match, expect: " << m_cam_param.cam_position
|
|
<< ", but got: " << p->cam_position << std::endl;
|
|
return -1;
|
|
}
|
|
|
|
if (p->cam_position == CAMERA_DOWN_1)
|
|
{
|
|
if (p->detect_type != DETECT_TYPE_QX && p->detect_type != DETECT_TYPE_ANGLE)
|
|
{
|
|
std::cout << "ERROR: Down Detect only support DETECT_TYPE_QX and DETECT_TYPE_ANGLE" << std::endl;
|
|
return -2;
|
|
}
|
|
}
|
|
else if (p->cam_position == CAMERA_Feeding || p->cam_position == CAMERA_Blanking)
|
|
{
|
|
if (p->detect_type != DETECT_TYPE_CHIP)
|
|
{
|
|
std::cout << "ERROR: Chip_Detect only support DETECT_TYPE_CHIP" << std::endl;
|
|
return -2;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (p->detect_type != DETECT_TYPE_QX)
|
|
{
|
|
std::cout << "ERROR: Top/Side Detect only support DETECT_TYPE_QX" << std::endl;
|
|
return -2;
|
|
}
|
|
}
|
|
|
|
if (p->detect_type == DETECT_TYPE_ANGLE)
|
|
return this->m_down_angle_detect->CheckImg(p, pResult);
|
|
else
|
|
return this->m_checkBase->CheckImg(p, pResult);
|
|
}
|
|
|
|
int ALL_Detect::UpdateConfig(void *pconfig, int nConfigType)
|
|
{
|
|
return this->m_checkBase->UpdateConfig(pconfig, nConfigType);
|
|
}
|