免费国产网站_秋霞午夜一区二区三区视频_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;
    } 
    主站蜘蛛池模板: 色125综合网_少妇高潮爽到娇喘抽搐_黄色福利在线观看_午夜在线影院_性欧美熟妇freetube_手机在线视频一区 | 内射夜晚在线观看_一区二区三区四区国产精品_国产精品99久久久久久天美传媒_日韩中字幕_免费看小12萝裸体视频国产_久久重口味 | 国产精品日产无码av永久不卡_暖暖视频免费高清日本_国产一级特黄AAAA级婬片_日韩成人AV在线一区二区三区_岛国免费网站_日本免费福利视频 | 高清av免费观看_日韩精品视频一区二区三区_国产高潮刺激叫喊视频_免费看A片久久久久久久久久_老年人品久久久无码中文字幕_777米奇色狠狠888俺也去 | 成年人免费在线观看_精品午夜一区二区三区在线观看_成年人免费片_久久久久黄色片_精品国产第一国产综合精品_日本肉体做爰猛烈高潮全免费 | 一级做a毛片免费视频_爽一爽av_韩国一级视频_免费精品国产_国产卡一卡二卡三高清_FREEXX性黑人大战欧美 | 国产精品国产三级国产aⅴ无密码_69xxx免费视频_亚洲黄色成人_男插女青青影院_国产91嫩草_日本福利一区二区三区 | 一级做a毛片免费视频_爽一爽av_韩国一级视频_免费精品国产_国产卡一卡二卡三高清_FREEXX性黑人大战欧美 | 欧美午夜精选久久久A_亚洲一区中文_91.看片_97dyy影院理论片_欧美在线综合_午夜精品久久久久久久99热黄桃 | 偷偷操视频_久草成人网_九九热超碰_99精品在线观看视频_人妻精品久久无码专区精东影业_91同城在线观看 | 亚洲无卡视频_又硬又粗又长又爽免费看_九草在线_91精品国产色综合久久不卡98口_av亚洲一区二区三区_亚洲国产经典视频 | 99热日韩_日本乱人伦在线观看_复仇者联盟4免费版高清在线观看_av免费看在线_国产精品99久久久成人小说_老司机aⅴ在线精品导航 | 久久久久亚洲AV综合仓井空_国产精品污WWW在线观看_成年人一级片_国产精品嫩草影院奶水_巨大黑人极品videos精品_中文字幕永久免费视频 | 蜜桃视频免费在线观看_精品久久久久久免费人妻_西出玉门在线观看_国产a一片_免费观看Aⅴ成人片_久久人体rtys | 国产片在线天堂av_国产精品专区一区_黄色片特级_亚洲第一页在线_日韩欧美一级大片_人妻激倩偷乱视频一区二区三区 | 久久久永久免费视频_欧美一区二区美女_亚洲区欧洲区_澳门黄网_天堂AV无码AV日韩AV_欧美羞羞视频 | 老妇女人一级毛片_黄色av免费看_日韩jizz_一级性大片_欧美人一级淫片a免费播放_欧美日韩一区二区三区在线观看 | 欧美亚洲日本国产_亚洲天堂2017无码_黄毛片在线观看_成人免费视频久久_天码欧美日本一道免费_成人久久亚洲 | 97se亚洲综合自在线尤物_国产极品粉嫩正在播放软件特点_日本国产在线视频_国产一级一区二区_免费成人av_在线a亚洲v天堂网2019无码 | 亚洲精品av天天看1080p_免费不卡在线观看av_国产精品久久久久久久女厕留拍_岛国精品一区_国产在线播精品第三_亚洲中文全新无码亚洲人一成 | 午夜二区_欧美成人a∨高清免费观看_国语自产免费精品视频在_人摸人人人澡人人超碰97_超碰免费在线公开_a级毛片视频免费观看 | 精品久久久久久成人av_91色免费视频_浮生影院在线观看完整_国产亚洲AV综合人人澡精品_少妇高潮喷潮久久久影院_日韩色影 | 爱逼爱操_亚洲三级黄色_99久久欧美日韩国产二区_农村一级片_女人私视频免费观看_色欧美视频 | 久青草资源视频在线无码_麻豆精品一区_就爱av_性欧美1819sex性高清_国语对白做受69按摩_外出3在线观看 在线四区_自拍偷拍臀av_日韩高清免费看_欧美精品VIDEOFREE1080P_97久久综合一区二区三区_亚洲日韩欧美一区二区三区在线 | 99re视频在线_粗长巨龙挤进新婚少妇未删版_末发育娇小性色xxxx_久久综久久_igao视频网站_久久国产综合精品 | 亚洲免费视频成人_小荡货你夹的老师好紧_真实国产普通话对白乱子子伦视频_牛和人交VIDE欧美XX00186_四虎国产免费_国产成人午夜 | 亚洲视频综合网_中文字幕一线产区和二线_免费涩涩视频_亚洲不卡_精品国产亚洲av麻豆狂野_中文字幕日韩三级 | 丰满少妇女裸体bbw_亚洲精品制服校园无码_亚洲午夜综合网_日韩成人av一区二区_成人一级黄色_久久免费视频99 | 三级黄色录像视频_yourporn国产在线观看_亚洲国产午夜_色yeye网站_久久国产香蕉_人人操,天天干 | 一区二区三区视频在线播放_五月婷婷久久综合_久久色成人在线_AV激情亚洲男人的天堂国语_草草CCYY免费看片线路_皇上从小侵犯双性太子NP高H | 免费观看麻豆_国产在线精品成人一区二区三区_婷婷五月综合人人网_成人毛片无码一区二区三区_91原创精品_青青草免费网站 | 国产片在线天堂av_国产精品专区一区_黄色片特级_亚洲第一页在线_日韩欧美一级大片_人妻激倩偷乱视频一区二区三区 | 在线观看视频免费区_黑人又大又粗又长进去很舒服_免费无码久久成人网站_黄色成人在线网站_国产精品爆乳在线播放第一人称_尤物99国产成人精品视频 | 亚洲免费网站观看视频_MM131亚洲国产美女久久_九色麻豆_了解最新久久精品免费一区二区视_亚洲综合在线网_999精品网 91精品视频在线播放_久久久激情视频_国产精品一区二区av在线观看_国产精品高潮久久久久久_久久99国产精品久久99大师_国产精品一级视频 | 9久热久爱免费精品视频在线_中日韩免费毛片_91小视频在线播放_国产精品一v二v在线观看_911国产影院在线观看_日本精品中文字幕在线播放 | 无码久久精品国产亚洲AV影片_欧美一级淫片丝袜脚交_午夜三级毛片_亚洲av久久无码精品影视_国产精品嫩草影院久久_久久综合久色欧美综合狠狠 | 少妇人妻无码AV片在线蜜芽_人妻丰满熟妇AV无码处处不卡_成年男女免费视频网站很黄的_99久久免费精品_无码人妻一区二区三区兔费_一本色道久久综合无码人妻 无遮挡A级毛片免费看_国产精品综合久久_不卡中文字幕_国产又粗又猛又爽又黄A片小说_国产黄色免费大片_日韩精人妻无码一区二区三区 | 2020国自产拍精品露脸快速_亚洲日韩国产欧美一区二区三区_99精品久久久久久久_久久春色_亚洲精品一二区_国产成人精品免高潮在线观看 | 一级视频网_92少妇精品免费视频_精彩久久_四虎影院中文字幕_久久久久成人免费视频_美女网站久久 | 中文有码人妻字幕在线_97在线免费看视频_美女视频一区二区三区_成年女人毛片免费中文_91色哟哟_中日韩一区 | 成人一级片视频_91精品在线看_av无码国产在线观看岛国_麻豆精品网站_日本精品少妇一区二区三区_人人爽久久久噜噜噜婷婷 |