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
226 stars 50 forks source link

怎么进行双目实时重建 #17

Open zhaoBeauty opened 6 months ago

zhaoBeauty commented 6 months ago

Desktop (please complete the following information):

博主代码里怎么进行双目实时重建?就是二值离焦后再用互补格雷码相位展开在匹配重建。 投影仪那里怎么操作?

Practice3DVision commented 6 months ago

没太明白意思,就正常的解相、匹配就行了。都是用CUDA加速会更快点,但用互补格雷码方案,会由于图像数目过多导致帧率比较低。投影仪简单离焦就行了。可以自行查阅部分源码

bool BinocularCamera::continuesCapture(SafeQueue<FrameData> &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);
        auto pRightCamera = cameraFactory_.getCamera(
            stringProperties_["Right 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 &&
                pRightCamera->getImgs().size() >= imgSizeWaitFor &&
                (pColorCamera ? pColorCamera->getImgs().size() >= imgSizeWaitFor
                              : true)) {
                std::vector<std::vector<cv::Mat>> imgs(pColorCamera ? 3 : 2);
                int index = 0;
                while (index != imgSizeWaitFor) {
                    imgs[0].emplace_back(pLeftCamera->popImg());
                    imgs[1].emplace_back(pRightCamera->popImg());
                    if (pColorCamera) {
                        imgs[2].emplace_back(pColorCamera->popImg());
                    }
                    ++index;
                }

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

                imgsCreated_.push(imgs);
            }
        }
    });

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

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

            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;
}
zhaoBeauty commented 6 months ago

好的,谢谢您!