Practice3DVision / SLMaster

SLMaster is a relatively complete open-source Structured Light 3D camera software. You can use it to complete a series of operations including calibration, stripe encoding, 3D reconstruction, and point cloud post-processing. Welcome Star⭐ And Fork🍴.
https://github.com/Practice3DVision/SLMaster/wiki
GNU Affero General Public License v3.0
225 stars 50 forks source link

关于实时扫描重建的一些问题请教 #33

Open shanwenbin opened 4 months ago

shanwenbin commented 4 months ago

关于实时扫描重建的一些问题请教

博主您好!在测试完单目及双目的标定及单次重建流程后,我们选择尝试高速的实时重建(单目结构光方式),但都失败了。在这个过程中有以下疑问,想要向您请教:

我们的环境为:

d9edd1d444b3c9ff88e885f8c247dbe

`bool MonocularCamera::continuesCapture(SafeQueue &frameDataQueue) {

if (!isCaptureStop_.load(std::memory_order_acquire)) {
    return true;
}

if (imgCreateThread_.joinable()) {
    imgCreateThread_.join();
}

if (frameDataCreateThread_.joinable()) {
    frameDataCreateThread_.join();
}

isCaptureStop_.store(false, std::memory_order_release);

imgCreateThread_ = std::thread([&] {
    const device::CameraFactory::CameraManufactor manufator =
        stringProperties_["2D Camera Manufactor"] == "Huaray"
            ? device::CameraFactory::Huaray
            : device::CameraFactory::Halcon;
    auto pLeftCamera = cameraFactory_.getCamera(
        stringProperties_["Left Camera Name"], manufator);

    device::Camera *pColorCamera = nullptr;
    if (stringProperties_["Color Camera Name"] != "") {
        pColorCamera = cameraFactory_.getCamera(
            stringProperties_["Color Camera Name"], manufator);
    }

    const int imgSizeWaitFor = numbericalProperties_["Total Fringes"];

    while (!isCaptureStop_.load(std::memory_order_acquire)) {
        if (pLeftCamera->getImgs().size() >= imgSizeWaitFor &&
            (pColorCamera ? pColorCamera->getImgs().size() >= imgSizeWaitFor
                          : true)) {
            std::vector<std::vector<cv::Mat>> imgs(pColorCamera ? 2 : 1);
            int index = 0;
            while (index != imgSizeWaitFor) {
                imgs[0].emplace_back(pLeftCamera->popImg());
                if (pColorCamera) {
                    imgs[1].emplace_back(pColorCamera->popImg());
                }
                ++index;

                //add by Jia
                std::cout << "imgCreateThread : pLeftCamera->getImgs().size() = " << pLeftCamera->getImgs().size() << std::endl;
            }

            std::cout << "imgCreateThread : Before : imgsCreated_.size() = " << imgsCreated_.size() << std::endl;

            if (imgsCreated_.size() > 2) {
                continue;
            }

            imgsCreated_.push(imgs);

            std::cout << "imgCreateThread : After : imgsCreated_.size() = " << imgsCreated_.size() << std::endl;
        }
    }
});

frameDataCreateThread_ = std::thread([&] {
    while (!isCaptureStop_.load(std::memory_order_acquire)) {
        if (imgsCreated_.empty()) {
            std::this_thread::sleep_for(std::chrono::milliseconds(5));
            continue;
        }

        std::cout << "frameDataCreateThread : Before : imgsCreated_.size() = " << imgsCreated_.size() << std::endl;

        std::vector<std::vector<cv::Mat>> imgs;
        imgsCreated_.move_pop(imgs);

        std::cout << "frameDataCreateThread : After : imgsCreated_.size() = " << imgsCreated_.size() << std::endl;
        std::cout << "frameDataCreateThread : After : imgs.size() = " << imgs.size() << std::endl;

        if (stringProperties_["Color Camera Name"] != "") {
            for (int i = 0; i < imgs.size(); ++i) {
                cv::cvtColor(imgs[i], imgs[i], cv::COLOR_BayerBG2BGR);
            }
        }

        FrameData curFrameData;
        decode(imgs, curFrameData);
        //frameDataQueue.push(curFrameData);
    }
});

projectorFactory_.getProjector(stringProperties_["DLP Evm"])->project(true);
return true;

}`

期待您的回复,感谢!!!!!

shanwenbin commented 4 months ago

博主您好!经过几天的探究,我们对实时重建出现的问题有了一些新的发现,但目前没有找到最合适的解决办法,现向您请教!

  1. 将几个线程隔离开进行测试,发现问题出现在frameDataCreateThread_线程。

  2. 进而对该线程进行排查,将FrameData curFrameData设置为全局变量,发现软件崩溃退出的问题得到了解决。但是该种方式失去了数据保护的优势。是否有其他的一些方式可以采用?

  3. 对FrameData结构体进行了查看,发现每次调用该结构体都会分配新的地址,但在线程调用后却没有释放,不知道此处是否存在一些问题?

shanwenbin commented 4 months ago

image