先看源代码
1、main.cpp源码如下:
void test_opencv()
{
GPipelinePtr pipeline = GPipelineFactory::create();
CStatus status;
GElementPtr a = nullptr;
GElementPtr b = nullptr;
status += pipeline->registerGElement<CNodeReadImage>(&a, {}, "readNodeA");
// status += pipeline->registerGElement<CNodeReadImage>(&b, {a}, "readNodeB");
if (!status.isOK())
{
return;
}
status += pipeline->init();
status += pipeline->run();
status += pipeline->destroy();
GPipelineFactory::remove(pipeline);
}
int main(int argc, char *argv[])
{
test_opencv();
return 0;
}
2、nodereadimage.cpp源文件如下
CStatus CNodeReadImage::init()
{
CGraph::CGRAPH_ECHO("[%s], enter init function", this->getName().c_str());
return CStatus();
}
CStatus CNodeReadImage::run()
{
CStatus status;
CGraph::CGRAPH_ECHO("[%s], enter run function", this->getName().c_str());
// CGRAPH_SLEEP_SECOND(1)
return status;
}
CStatus CNodeReadImage::destroy()
{
CGraph::CGRAPH_ECHO("[%s], enter destroy function", this->getName().c_str());
return CStatus();
}
CStatus CNodeReadImage::beforeRun()
{
CGraph::CGRAPH_ECHO("[%s], enter beforeRun function", this->getName().c_str());
return CStatus();
}
CStatus CNodeReadImage::afterRun()
{
CGraph::CGRAPH_ECHO("[%s], enter afterRun function", this->getName().c_str());
return CStatus();
}
再看编译之后的运行结果:
[CGraph] [Mon Feb 20 19:06:06 2023] [readNodeA], enter beforeRun function
[CGraph] [Mon Feb 20 19:06:06 2023] [readNodeA], enter afterRun function
[CGraph] [Mon Feb 20 19:06:06 2023] [readNodeA], enter init function
[CGraph] [Mon Feb 20 19:06:06 2023] [readNodeA], enter beforeRun function
[CGraph] [Mon Feb 20 19:06:06 2023] [readNodeA], enter run function
[CGraph] [Mon Feb 20 19:06:06 2023] [readNodeA], enter afterRun function
[CGraph] [Mon Feb 20 19:06:06 2023] ..\cvGraphDemo\graph\GraphCtrl\GraphPipeline\GPipeline.cpp | CGraph::GPipeline::run | line = [75], errorCode = [-1], errorInfo = [pipeline done status check failed...].
[CGraph] [Mon Feb 20 19:06:06 2023] [readNodeA], enter destroy function
我的疑问如下:
1、node节点在init之前,怎么先执行了beforeRun和afterRun?
2、为什么会报错?errorCode = [-1], errorInfo = [pipeline done status check failed...]
哪里有问题?