128 lines
2.7 KiB
C++
128 lines
2.7 KiB
C++
|
#include "opcv/CvImageShowModel.h"
|
|||
|
|
|||
|
CvImageShowModel::CvImageShowModel()
|
|||
|
{
|
|||
|
//moveToThread(this);
|
|||
|
|
|||
|
mCvImageView = new CvImageViewWidget();
|
|||
|
mCvImageView->installEventFilter(this);
|
|||
|
mCvImageView->resize(200, 200);
|
|||
|
mCvImageData = std::make_shared<CvImageData>();
|
|||
|
//m_hRegion = std::make_shared<HRegionData>();
|
|||
|
}
|
|||
|
|
|||
|
void CvImageShowModel::inputConnectionDeleted(QtNodes::Connection const&)
|
|||
|
{
|
|||
|
mCvImageView->showImage(cv::Mat());
|
|||
|
|
|||
|
mCvImageData = std::make_shared<CvImageData>();
|
|||
|
|
|||
|
PortIndex const outPortIndex = 0;
|
|||
|
modelValidationState = NodeValidationState::Warning;
|
|||
|
modelValidationError = QStringLiteral("ͼƬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
|
|||
|
Q_EMIT dataUpdated(outPortIndex);
|
|||
|
}
|
|||
|
|
|||
|
bool CvImageShowModel::RunTask()
|
|||
|
{
|
|||
|
PortIndex const outPortIndex = 0;
|
|||
|
try
|
|||
|
{
|
|||
|
//qDebug() << "22show";
|
|||
|
//QThread::sleep(3);
|
|||
|
|
|||
|
mCvImageView->showImage(*mCvImageData->CvImage());
|
|||
|
modelValidationState = NodeValidationState::Valid;
|
|||
|
modelValidationError = QString();
|
|||
|
}
|
|||
|
catch (...)
|
|||
|
{
|
|||
|
modelValidationState = NodeValidationState::Warning;
|
|||
|
modelValidationError = QStringLiteral("ȱʧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>!");
|
|||
|
}
|
|||
|
|
|||
|
Q_EMIT dataUpdated(outPortIndex);
|
|||
|
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
bool CvImageShowModel::eventFilter(QObject* watched, QEvent* event)
|
|||
|
{
|
|||
|
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
unsigned int CvImageShowModel::nPorts(PortType portType) const
|
|||
|
{
|
|||
|
unsigned int result = 1;
|
|||
|
|
|||
|
switch (portType)
|
|||
|
{
|
|||
|
case PortType::In:
|
|||
|
result = 1;
|
|||
|
break;
|
|||
|
|
|||
|
case PortType::Out:
|
|||
|
result = 1;
|
|||
|
|
|||
|
default:
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
return result;
|
|||
|
}
|
|||
|
|
|||
|
NodeDataType CvImageShowModel::dataType(PortType portType, PortIndex portIndex) const
|
|||
|
{
|
|||
|
switch (portIndex)
|
|||
|
{
|
|||
|
case 0:
|
|||
|
return CvImageData().type();
|
|||
|
break;
|
|||
|
case 1:
|
|||
|
return CvImageData().type();
|
|||
|
break;
|
|||
|
}
|
|||
|
return CvImageData().type();
|
|||
|
}
|
|||
|
|
|||
|
void CvImageShowModel::setInData(std::shared_ptr<NodeData> data, int portIndex)
|
|||
|
{
|
|||
|
if (data == nullptr)
|
|||
|
return;
|
|||
|
if (data->type() == mCvImageData->type())
|
|||
|
{
|
|||
|
auto dataPtr = std::dynamic_pointer_cast<CvImageData>(data);
|
|||
|
if (dataPtr->CvImage()->empty())
|
|||
|
return;
|
|||
|
mCvImageData->setCvImage(*dataPtr->CvImage());
|
|||
|
}
|
|||
|
//else if (data->type() == m_hRegion->type())
|
|||
|
//{
|
|||
|
// auto dataPtr = std::dynamic_pointer_cast<HRegionData>(data);
|
|||
|
// if (!dataPtr->hRegion()->IsInitialized())
|
|||
|
// return;
|
|||
|
// m_hRegion->setHRegion(*dataPtr->hRegion());
|
|||
|
// m_hRegion->setSize(dataPtr->getSize());
|
|||
|
// HImage tmpImg = m_hRegion->hRegion()->RegionToBin(255, 0,
|
|||
|
// m_hRegion->getSize().width(), m_hRegion->getSize().height());
|
|||
|
// m_hImage->setHImage(tmpImg);
|
|||
|
//}
|
|||
|
RunTask();
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
std::shared_ptr<NodeData> CvImageShowModel::outData(PortIndex index)
|
|||
|
{
|
|||
|
switch (index)
|
|||
|
{
|
|||
|
case 0:
|
|||
|
return std::dynamic_pointer_cast<CvImageData>(mCvImageData);
|
|||
|
break;
|
|||
|
case 1:
|
|||
|
return std::dynamic_pointer_cast<CvImageData>(mCvImageData);
|
|||
|
break;
|
|||
|
}
|
|||
|
return std::dynamic_pointer_cast<CvImageData>(mCvImageData);
|
|||
|
}
|