Hello, I have a serious issue when I use a following function "test_show()" as DLL C++. Could you help me? A simple and DLL source is below.
#include "opencv2/opencv.hpp"
#include "depthai/depthai.hpp"
dai::Pipeline pipeline;
dai::Device device;
std::shared_ptrdai::node::ColorCamera colorCam;
std::shared_ptrdai::node::XLinkOut xlinkOut;
std::shared_ptrdai::DataOutputQueue preview
void __declspec(dllexport) test_show() {
colorCam = pipeline.create<dai::node::ColorCamera>();
xlinkOut = pipeline.create<dai::node::XLinkOut>();
xlinkOut->setStreamName("preview");
colorCam->setInterleaved(true);
colorCam->preview.link(xlinkOut->input);
device.startPipeline(pipeline);
preview = device.getOutputQueue("preview");
for (int i = 0; i < 400; ++i){
auto inRgb = preview->get<dai::ImgFrame>();
cv::imshow("rgb", inRgb->getCvFrame())
}
cv::destroyAllWindows();
device.close();
}
Above simple source defines device, pipeline .. as global variables. When I build this dll and calls test_show() from other C++ source, The DepthAI camera doesn't work at all. The same applies when declaring a global pointer for a variable and instantiating it inside a function. On the other hands, if there is no global variables (device, pipeline … are defined within test_show()), the software works well.
My development environment is as follows.
windows visual studio 2022,depthai-core-2.21.2 opencv_world460
When I call this dll function, the source is simple.
void __declspec(dllimport) test_show();
int main(){ test_show(); }
I hope your quick response for us and our customer.
Best Regards,