免费国产网站_秋霞午夜一区二区三区视频_99热在线看_日韩精品久久一区二区_午夜看一级毛片_天天鲁在视频在线观看

  • 您的位置:首頁 > 新聞動態 > 技術文章

    realsense顯示限定范圍內的圖像物體

    2019/11/11??????點擊:

    REALSENSE不同于普通RGB相機的是,普通相機只可以獲得圖像的RGB顏色信息,REALSENSE可以獲得像素的深度信息。RGB相機只能通過幀間差分、特定顏色提取、基于混合高斯模型去除背景等方法,做到前景背景分離,而通過REALSENSE可以根據像素的深度信息我們可以很方便實現畫面摳圖,即設置一定的深度范圍, 只顯示在此深度范圍內的像素,那我們就可以通過Z方向的距離來剔除背景了。以下是實現摳圖功能的代碼:

    // License: Apache 2.0. See LICENSE file in root directory.
    // Copyright(c) 2017 Intel Corporation. All Rights Reserved.
     
    #include 
    #include "../example.hpp"
    #include 
    #include "imgui_impl_glfw.h"
     
    #include#include#include#include#includevoid render_slider(rect location, float& clipping_dist);
    void remove_background(rs2::video_frame& other, const rs2::depth_frame& depth_frame, float depth_scale, float clipping_dist);
    float get_depth_scale(rs2::device dev);
    rs2_stream find_stream_to_align(const std::vector& streams);
    bool profile_changed(const std::vector& current, const std::vector& prev);
     
    int main(int argc, char * argv[]) try
    {
        // Create and initialize GUI related objects
        window app(1280, 720, "CPP - Align Example"); // Simple window handling
        ImGui_ImplGlfw_Init(app, false);      // ImGui library intializition
        rs2::colorizer c;                          // Helper to colorize depth images
        texture renderer;                     // Helper for renderig images
     
        // Create a pipeline to easily configure and start the camera
        rs2::pipeline pipe;
        //Calling pipeline's start() without any additional parameters will start the first device
        // with its default streams.
        //The start function returns the pipeline profile which the pipeline used to start the device
        rs2::pipeline_profile profile = pipe.start();
     
        // Each depth camera might have different units for depth pixels, so we get it here
        // Using the pipeline's profile, we can retrieve the device that the pipeline uses
        float depth_scale = get_depth_scale(profile.get_device());
     
        //Pipeline could choose a device that does not have a color stream
        //If there is no color stream, choose to align depth to another stream
        rs2_stream align_to = find_stream_to_align(profile.get_streams());
     
        // Create a rs2::align object.
        // rs2::align allows us to perform alignment of depth frames to others frames
        //The "align_to" is the stream type to which we plan to align depth frames.
        rs2::align align(align_to);
     
        // Define a variable for controlling the distance to clip
        float depth_clipping_distance = 1.f;
     
        while (app) // Application still alive?
        {
            // Using the align object, we block the application until a frameset is available
            rs2::frameset frameset = pipe.wait_for_frames();
     
            // rs2::pipeline::wait_for_frames() can replace the device it uses in case of device error or disconnection.
            // Since rs2::align is aligning depth to some other stream, we need to make sure that the stream was not changed
            //  after the call to wait_for_frames();
            if (profile_changed(pipe.get_active_profile().get_streams(), profile.get_streams()))
            {
                //If the profile was changed, update the align object, and also get the new device's depth scale
                profile = pipe.get_active_profile();
                align_to = find_stream_to_align(profile.get_streams());
                align = rs2::align(align_to);
                depth_scale = get_depth_scale(profile.get_device());
            }
     
            //Get processed aligned frame
            auto processed = align.process(frameset);
     
            // Trying to get both other and aligned depth frames
            rs2::video_frame other_frame = processed.first(align_to);
            rs2::depth_frame aligned_depth_frame = processed.get_depth_frame();
     
            //If one of them is unavailable, continue iteration
            if (!aligned_depth_frame || !other_frame)
            {
                continue;
            }
            // Passing both frames to remove_background so it will "strip" the background
            // NOTE: in this example, we alter the buffer of the other frame, instead of copying it and altering the copy
            //       This behavior is not recommended in real application since the other frame could be used elsewhere
            remove_background(other_frame, aligned_depth_frame, depth_scale, depth_clipping_distance);
     
            // Taking dimensions of the window for rendering purposes
            float w = static_cast(app.width());
            float h = static_cast(app.height());
     
            // At this point, "other_frame" is an altered frame, stripped form its background
            // Calculating the position to place the frame in the window
            rect altered_other_frame_rect{ 0, 0, w, h };
            altered_other_frame_rect = altered_other_frame_rect.adjust_ratio({ static_cast(other_frame.get_width()),static_cast(other_frame.get_height()) });
     
            // Render aligned image
            renderer.render(other_frame, altered_other_frame_rect);
     
            // The example also renders the depth frame, as a picture-in-picture
            // Calculating the position to place the depth frame in the window
            rect pip_stream{ 0, 0, w / 5, h / 5 };
            pip_stream = pip_stream.adjust_ratio({ static_cast(aligned_depth_frame.get_width()),static_cast(aligned_depth_frame.get_height()) });
            pip_stream.x = altered_other_frame_rect.x + altered_other_frame_rect.w - pip_stream.w - (std::max(w, h) / 25);
            pip_stream.y = altered_other_frame_rect.y + altered_other_frame_rect.h - pip_stream.h - (std::max(w, h) / 25);
     
            // Render depth (as picture in pipcture)
            renderer.upload(c.process(aligned_depth_frame));
            renderer.show(pip_stream);
     
            // Using ImGui library to provide a slide controller to select the depth clipping distance
            ImGui_ImplGlfw_NewFrame(1);
            render_slider({ 5.f, 0, w, h }, depth_clipping_distance);
            ImGui::Render();
     
        }
        return EXIT_SUCCESS;
    }
    catch (const rs2::error & e)
    {
        std::cerr << "RealSense error calling " << e.get_failed_function() << "(" << e.get_failed_args() << "):\n    " << e.what() << std::endl;
        return EXIT_FAILURE;
    }
    catch (const std::exception & e)
    {
        std::cerr << e.what() << std::endl;
        return EXIT_FAILURE;
    }
     
    float get_depth_scale(rs2::device dev)
    {
        // Go over the device's sensors
        for (rs2::sensor& sensor : dev.query_sensors())
        {
            // Check if the sensor if a depth sensor
            if (rs2::depth_sensor dpt = sensor.as())
            {
                return dpt.get_depth_scale();
            }
        }
        throw std::runtime_error("Device does not have a depth sensor");
    }
     
    void render_slider(rect location, float& clipping_dist)
    {
        // Some trickery to display the control nicely
        static const int flags = ImGuiWindowFlags_NoCollapse
            | ImGuiWindowFlags_NoScrollbar
            | ImGuiWindowFlags_NoSavedSettings
            | ImGuiWindowFlags_NoTitleBar
            | ImGuiWindowFlags_NoResize
            | ImGuiWindowFlags_NoMove;
        const int pixels_to_buttom_of_stream_text = 25;
        const float slider_window_width = 30;
     
        ImGui::SetNextWindowPos({ location.x, location.y + pixels_to_buttom_of_stream_text });
        ImGui::SetNextWindowSize({ slider_window_width + 20, location.h - (pixels_to_buttom_of_stream_text * 2) });
     
        //Render the vertical slider
        ImGui::Begin("slider", nullptr, flags);
        ImGui::PushStyleColor(ImGuiCol_FrameBg, ImColor(215.f / 255, 215.0f / 255, 215.0f / 255));
        ImGui::PushStyleColor(ImGuiCol_SliderGrab, ImColor(215.f / 255, 215.0f / 255, 215.0f / 255));
        ImGui::PushStyleColor(ImGuiCol_SliderGrabActive, ImColor(215.f / 255, 215.0f / 255, 215.0f / 255));
        auto slider_size = ImVec2(slider_window_width / 2, location.h - (pixels_to_buttom_of_stream_text * 2) - 20);
        ImGui::VSliderFloat("", slider_size, &clipping_dist, 0.0f, 6.0f, "", 1.0f, true);
        if (ImGui::IsItemHovered())
            ImGui::SetTooltip("Depth Clipping Distance: %.3f", clipping_dist);
        ImGui::PopStyleColor(3);
     
        //Display bars next to slider
        float bars_dist = (slider_size.y / 6.0f);
        for (int i = 0; i <= 6; i++)
        {
            ImGui::SetCursorPos({ slider_size.x, i * bars_dist });
            std::string bar_text = "- " + std::to_string(6-i) + "m";
            ImGui::Text("%s", bar_text.c_str());
        }
        ImGui::End();
    }
     
    void remove_background(rs2::video_frame& other_frame, const rs2::depth_frame& depth_frame, float depth_scale, float clipping_dist)
    {
        const uint16_t* p_depth_frame = reinterpret_cast(depth_frame.get_data());
        uint8_t* p_other_frame = reinterpret_cast(const_cast(other_frame.get_data()));
     
        int width = other_frame.get_width();
        int height = other_frame.get_height();
        int other_bpp = other_frame.get_bytes_per_pixel();
     
        #pragma omp parallel for schedule(dynamic) //Using OpenMP to try to parallelise the loop
        for (int y = 0; y < height; y++)
        {
            auto depth_pixel_index = y * width;
            for (int x = 0; x < width; x++, ++depth_pixel_index)
            {
                // Get the depth value of the current pixel
                auto pixels_distance = depth_scale * p_depth_frame[depth_pixel_index];
     
                // Check if the depth value is invalid (<=0) or greater than the threashold
                if (pixels_distance <= 0.f || pixels_distance > clipping_dist)
                {
                    // Calculate the offset in other frame's buffer to current pixel
                    auto offset = depth_pixel_index * other_bpp;
     
                    // Set pixel to "background" color (0x999999)
                    std::memset(&p_other_frame[offset], 0x99, other_bpp);
                }
            }
        }
    }
     
    rs2_stream find_stream_to_align(const std::vector& streams)
    {
        //Given a vector of streams, we try to find a depth stream and another stream to align depth with.
        //We prioritize color streams to make the view look better.
        //If color is not available, we take another stream that (other than depth)
        rs2_stream align_to = RS2_STREAM_ANY;
        bool depth_stream_found = false;
        bool color_stream_found = false;
        for (rs2::stream_profile sp : streams)
        {
            rs2_stream profile_stream = sp.stream_type();
            if (profile_stream != RS2_STREAM_DEPTH)
            {
                if (!color_stream_found)         //Prefer color
                    align_to = profile_stream;
     
                if (profile_stream == RS2_STREAM_COLOR)
                {
                    color_stream_found = true;
                }
            }
            else
            {
                depth_stream_found = true;
            }
        }
     
        if(!depth_stream_found)
            throw std::runtime_error("No Depth stream available");
     
        if (align_to == RS2_STREAM_ANY)
            throw std::runtime_error("No stream found to align with Depth");
     
        return align_to;
    }
     
    bool profile_changed(const std::vector& current, const std::vector& prev)
    {
        for (auto&& sp : prev)
        {
            //If previous profile is in current (maybe just added another)
            auto itr = std::find_if(std::begin(current), std::end(current), [&sp](const rs2::stream_profile& current_sp) { return sp.unique_id() == current_sp.unique_id(); });
            if (itr == std::end(current)) //If it previous stream wasn't found in current
            {
                return true;
            }
        }
        return false;
    } 
    主站蜘蛛池模板: 性欧美13处14处破在线观看_黄色a一片_91在线看片_五月婷之久久综合丝袜美腿_欧美日本一二三区_中国VIDEOSEX高潮 | 天堂资源中文最新版在线一区_国产极品美女高潮无套_国产馆av大片免费_亚洲精品久久久久久久观小说_国产激情视频图片qvod_美女黄页网站免费进入 | 亚洲优女在线_日本黄色动漫视频_精品1区2区3区4区产品乱码9_日本在线不卡免费_午夜在线网站_四虎av影院 | 日本熟妇色videosex_国产成人精品久久二区二区91_国产成人av在线播放不卡_91精品国产高清久久久久久91裸体_欧美一区二区在线不卡_欧美天堂精品久久久久久久噜噜噜 | 美女扒开内裤无遮挡18禁_视频一区视频二区中文_免费精品国产人妻国语_久久天天综合网_日本一级淫片a免费播放_99亚洲乱人伦aⅴ精品 | 视频在线观看视频_欧美一区二区免费观在线_日本一级作爱片_国产精品va尤物在观看2021_校花高潮抽搐冒白浆视频_波多一区 | 免费无码黄动漫在线观看尤物_亚洲综合不卡_777久久久免费精品国产_欧洲免费在线视频_国产亚洲精品v_日本免费影院 | 成人免费看AA片_欧美日韩激情_69热视频在线观看免费自拍_日韩精品网站在线观看_2022中文字字幕久亚洲_欧美熟妇性xxx交潮喷 | 免费看黄色国产_大地资源网高清在线观看免费新浪_江苏富婆按摩高潮对白_亚洲日本中文字幕在线_日韩在线不卡一区_欧美国产日韩另类 | 亚洲最大成人免费网站_日本不卡二三区_午夜理论片YY6080影院_欧美激情网站_无码流畅无码福利午夜_老太脱裤子让老头玩xxxxx | 国产高清亚洲日韩一区_韩日激情_国产成人无码AV片在线观看不卡_午夜国产一级_成人综合区_a黄色片在线观看 | 国产成人精品优优AV_久久成人国产精品免费_有剧情的av_日日摸日日碰夜夜爽视频_久久精品2019中文字幕_2021av天堂网手机版 | 99草草国产熟女视频在线_国产精品久久高潮无码视频_国产中文在线观看_韩国二区三区_毛片在线播放视频_免费成人在线网站 | 欧美高清网站_亚洲第一不卡_国产成人在线观看免费网站_国产av一区最新精品_日本www视频在线观看_免费观看久久 | onlyfans是个什么平台_国产区香蕉精品系列在线观看不卡_亚洲国产另类久久久精品黑人_艹逼逼小说_亚洲欧美日韩国产一区二区_国产亚洲一区二区不卡 | 免费无码av一区_97超碰免费人妻中文_在线观看91精品国产网站_波多野结衣AV在线无码中文观看_a级黑粗大硬长爽猛出猛进_亚洲日韩欧美在线一区二区 | 欧美69xxxxx_欧美人与动牲交ZOOZ男人_国产精品久久久久潘金莲_亚洲天堂男_精品成人在线视频_蜜桃传媒一区二区亚洲av | 老司机福利av_国产精品一级片在线观看_A级国产乱理论片在线观_美女叼嘿视频_性较小国产交xxxxx视频_香蕉久久夜色精品 | 国产极品在线播放_av视屏在线播放_免费看成人A片无码视频尤物_俄罗斯胖老太牲交_亚洲AV无码成人网站久久精品大_91亚洲国产成人精品一区二三 | 视频一区中文_欧美黑人一区二区三区免费A片_国精品无码一区二区三区左线_国产尤物av_黄色免费小视频_天天操天天骑 | 97好色_玖草在线观看_国产a久久精品一区二区三区_国产精选自拍_国产三级精品视频_亚洲色图在线看 | 成人一级片视频_91精品在线看_av无码国产在线观看岛国_麻豆精品网站_日本精品少妇一区二区三区_人人爽久久久噜噜噜婷婷 | 巨胸不知火舞露双奶头无遮挡_91pro在线_久久这里只有精品国产_国产精品视频啪啪_91精品对白一区国产伦_美日韩精品 | 国产在线观看精品_麻豆快播_天天舔日日干_超碰成人人人做人人爽_中文字幕网在线_91精品大全 | www.com成人_黄色四虎影院_精彩视频一区二区_天天干天天草_国产成人精品久久_国产天堂精品 | 国产成人在线视频观看_亚洲成av人影院在线观看_sm另类首页制服av_www.爱久久_日韩精品无码专区免费视频_japanese成熟丰满熟妇 | 最近中文字幕高清mv在线视频_亚洲阿v天堂无码z2018_伊人天天久大香线蕉AV色_国产乡下妇女做爰视频_亚洲一级片网站_国产精一品亚洲二区在线播放 | 精久久久久_国产高清在线观看视频_日韩美女一级片_日韩欧美激情兽交_成人免费午夜无码视频_精品在线视频亚洲小说 | 高潮videossex潮喷另类_中文字幕无码热在线视频_国产大屁股喷水视频在线观看_国产专区免费_A级无遮挡超级高清一在线观看_精品国产AV久久久久无码 | 好吊视频一区二区三区_亚洲中文字幕久久精品无码2021_亚洲一区www_日韩欧美在线免费观看_49vv婷婷网_超碰一区二区三区 | 少妇高潮喷水久久久久久久久久_奇米涩涩涩_欧美激情性xxxxx_bt天堂新版中文在线地址_嫩草影院永久在线_久9热这里只有精品视频 | 2020VA最新国产在线_免费精品国偷自产在线2020_国产18禁黄网站禁片免费观看_99久草_国产精品va无码免费麻豆_A片在线观看免费视频网站 | 一区二区精品久久久_亚洲蜜臀av乱码久久精品蜜桃_在线观看日韩欧美_少妇愉情理伦片_午夜DJ在线观看免费视频_久久亚洲线观看视频 亚洲网站免费观看_亚洲在线视频播放_美国xxxx视频_成人av网址在线_麻豆传媒在线观看_免费无码又爽又刺激A片软件 | 天天操夜夜操国产精品_国产特级毛片AAAAAA高清_久久久久久久久久一本门道91_欧美片第一页_免费99精品国产人妻自在线_亚洲国产日韩一区三区 | 国产在线黄色_日本一级床片_91在线永久_成人h动漫亚洲一区二区_97国产精品亚洲精品_日本www一道久久久免费 | 久久精品日韩精品_中文无码亚洲精品制服丝袜_国产成人高清精品_樱桃视频大全免费高清版_无码AV天天AV天天爽_国产内射性高潮对白 久久成人高清_人人射视频_性av一区_欧洲人免费视频网站在线_欧美亚洲精品一区二区_亚洲欧美视频图片 | 午夜男人网_国产乱码精品一区二区三区亚洲人_久久视频在线播放_超碰人人射_久久一av_人鲁交YAZHONGHUCXX | 国产精品99久久久久久大便_国产成人免费ā片在线观看_亚洲大片一区_乌克兰丰满女人a级毛片右手影院_九九色在线_欲妇荡岳丰满少妇岳 | 亚洲精品乱码久久久久久蜜桃麻豆_成人黄色网_国产日韩欧美综合一区二区三区_99热在线观看精品_亚洲综合首页_国产成人免费无码AV在线播放 | 69av色_日本超碰一区二区_国产精品人妻在线观看_亚洲中日韩欧美高清在线_久久亚洲一区二区三区舞蹈_久久一日本道色综合久久大香 无码人妻精品一区二区三区蜜桃_青青av在线_俺也去色官网_最近2019中文字幕大全视频10_91精品国产91久久久久福利_国产亚州精品女人久久久久久 | 人人做人人澡人人爽欧美_电击奶头の尿失禁调教_乱成熟女人在线视频_亚色中文网_h国产在线_亚洲老妈激情一区二区三区 |