免费国产网站_秋霞午夜一区二区三区视频_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;
    } 
    主站蜘蛛池模板: 国产精品亚洲一区二区在线观看_免费久久精品国产片_亚洲色图第四色_在线观看中文字幕不卡有码_无码人妻久久一区二区三区免费丨_99久久精品毛片免费播放 | 韩国午夜理伦三级在线观看_欧美人与牲口杂交在线播放免费_国产一级aaa毛片_肉蒲团从国内封禁到日本成经典_四虎影视最新网站入口在线观看_日韩视频91 | 免费无码av片在线观看网站_黑人太大太长疼死我了_亚洲精品蜜桃久久久久久_国产免费www_2021在线不卡国产麻豆_成人无码一区二区三区网站 | 糖心VLOG精品一区二区三区_精品999在线_制服丝袜日日夜夜_精品国产一级毛片_欧美在线A片一区二区三区_欧美特黄一级片 | 午夜毛片免费_无码一区二区三区爆白浆_成人区人妻精品一区二区不卡网站_69大片视频免费观看视频_91亚洲精品_亚洲一级毛片免费在线观看 | 精久久久久_国产高清在线观看视频_日韩美女一级片_日韩欧美激情兽交_成人免费午夜无码视频_精品在线视频亚洲小说 | 成人午夜国产_亚洲成人综合在线_国产9页_亚洲午夜久久久影院伊人_丰满少妇人妻HD高清大乳_成人毛片网站 | 9lporm自拍视频区_色婷婷成人网_国产精品入口尤物_香港毛片基地_91精品无码久久久久久久久_亚洲日韩av在线观看 | 午夜社区_国产中文字幕精品_午夜小视频在线免费观看_免费在线视频a_日产精品久久久一区二区福利_www.免费视频网站 | 精品国产乱码久久久久久丨区2区_18禁男女污污污午夜网站免费_91亚洲精品久久_91精品国产综合久久久密臀九色_鸳鸯谱在线观看高清_国产亚洲精品久久久久久快乐8 | 少妇人妻无码专区视频_99国产欧美另类久久片_四虎影视欧美_亚洲人成网站777色婷婷_欧洲精品VA无码一区二区三区_国产精品中文字幕av | 好紧好爽午夜视频_国产亚洲自拍一区_91影视一区二区三区_免费在线播放av_办公室高h文_九色视频网站在线观看 | 亚洲av毛片一区二二区三三区_91传媒91久久久_一本一道久久a久久综合精品图_无码国模大尺度视频在线观看_亚洲精品无码中文久久字幕_久草在线国产视频 | m麻豆传媒_依人在线免费视频_精品国产sm最大网免费站_日本公与丰满熄理论在线播放_成人特级片_成人伊人 | caopom在线视频免费观看_av免费播放_成年免费A级毛片免费看无码_一卡2卡3卡四卡精品免费网站_草莓香蕉樱桃黄瓜视频_91黄色看片 | 久久精热_爱爱视频在线免费观看_欧美精品在线视频_麻豆传媒网站在线观看_激情无码人妻又粗又大_亚洲第一网站男人都知道 | 91精品91久久久久久_a在线一区_性迷宫在线播放_欧美在线视频一二三区_久久99精品国产自在现线_久久精品超碰 | 又黄又爽又猛1000部A片_青春草免费在线视频_欧美成人精品高清在线播放_av黑人_午夜视频久久_91一区二区三区在线 | 亚洲va欧美va人人爽春色影视_少妇被粗大的猛进出69影院_亚洲真人无码永久在线观看_亚洲一二_av黄色免费在线观看_国产性×xxx盗摄xxxx | 亚洲精品成人免费_91女神娇喘疯狂3p之夜_精品韩国一级久久_av毛片网_www超碰com_午夜视频体内射.COM.COM | 国产精品一区毛片_在线啊v_兔子先生视频在线播放_国产AV区男人的天堂_午夜免费激情视频_91丝袜在线 | 天天操夜夜操国产精品_国产特级毛片AAAAAA高清_久久久久久久久久一本门道91_欧美片第一页_免费99精品国产人妻自在线_亚洲国产日韩一区三区 | 成人网页在线观看_国产视频毛片_日本特级片_欧美一区二区综合_国产亚洲精品激情久久_一级毛片在线免费播放 | 国产欧美精品一区二区粉嫩_日日噜噜噜噜久久久精品毛片_国产真人无码作爱免费视频_国产精品国产三级国产播12软件_亚洲精品日韩色噜噜久久五月_永久免费草莓视频入口 | 在线观看视频精品_1313午夜精品理论片蜜桃网_国产另类在线视频_美女张开腿让男人视频_国产性爱自拍av_亚洲永久精品免费www | 高清日韩在线_亚洲精品色图_成人伊人网_hd德国xxxxhdvideos_武侠古典av_偷拍粉嫩25位美女视频在线观看 | 蜜臀av片_国产有码在线观看_国产在线高清网址导航_av自拍一区_久久国产精品99久久久久久牛牛_久久精品国产麻豆 | 中文字幕一区二区三区乱码_天天干b_538国产精品一区二区_中文字幕丁香五月天_中国美女av_大地资源免费第二页 | 小泽マリアAV无码观看_国产福利在线小视频_在线成人小视频_不忠少妇_香蕉啪视频在线观看视频久_亚洲国产精品成人无码A片软件 | 黄色免费网站在线看_欧洲精品久久_啪啪午夜视频_国产成人综合亚洲色就色_国产超污视频在线观看_三个黑人上我一个 | 永夜星河在线观看_日韩色性视频_日本成人免费网站_日本在线看_国产a一级毛片爽爽影院无码_久久xxx | 国产精品乱码一区二区视频_国产精品视频播放_99热精品视_成人日韩在线观看_亚洲永久_第一色站 | 777午夜_女调教脚奴网站_亚洲精品~无码抽插_两个黑人大战嫩白金发美女_两个奶头被吃高潮_久久久国产精品免费a片3d | 色播网址_色花堂永久地址_国产午夜激无码AV毛片不卡_久一久久_久久精品re_2018av视频 | 高潮喷水无码中文字幕_国产精品XXX在线_无码永久免费AV网站_男人日女人网站_樱花草日本在线WWW官网_一区二区三区四区精品视频 | 91婷婷综合_四虎最新网址在线观看_午夜影院激情_日韩黄色影视_特级做A爰片毛片免费69_日本成人精品在线 | 啦啦啦高清视频在线观看_香港黄色大片_麻豆精品在线看_日韩欧美一级黄色片_日韩中文字幕免费在线播放_3344成人 | 久久综合精品一区_精品亚洲一区二区三区四区五区_国产亚洲人成无码网在线观看_国产乱淫av免费观看_久久久噜噜噜久噜久久综合_日韩三级av | 国产香蕉国产精品偷在线_国产亚洲欧美精品永久_www.九九九九_人人澡人人澡人人澡澡_欧美黄色一级片免费看_两个奶被揉到高潮视频 99成人精品日韩激情网站_www.影院_噜噜噜久久亚洲精品国产品91_九久久久久_久久人91精品久久久久久不卡_久久久久久久久久久网 | 97超碰人人网_国产福利片在线观看_国产做a爰片久久毛片_日本免费一本天堂在线_97超碰人人澡人人爱_91青青操 | 偷拍中文亚洲欧美动漫_一本色道久久综合亚洲精品图片_极品久久久久久久_欧美日本在线看_91成人高清无码在线观看_亲近乱子伦免费视频无码 |