免费国产网站_秋霞午夜一区二区三区视频_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;
    } 
    主站蜘蛛池模板: 成人激情春色网_国产精品欧美日韩在线观看_91女神在线_天天爽天天操_日本xx视频免费观看_日本国产高清不卡 | 亚洲va中文在线播放免费_亚洲免费在线观看av_亚洲国产精品视频_国产精品最新资源网_捆绑白丝jk震动捧喷白浆_亚欧洲乱码专区网站 | 美女免费精品高清毛片在线视_黄色影视大全_国产免费传媒av片在线_丰满熟妇岳av无码区_亚洲三级成人_亚洲精品视频91 | 日本啪视频_青青草在观免费观看久_伊人色婷婷五月天激情狠狠五月天_亚洲天堂成人在线_久久免费一区_香蕉网站黄色 | 亚洲日韩在线a视频在线观看_亚洲精品自偷自拍无码_99视频导航_91vip视频_东京热人妻无码一区二区av_麻豆传媒91 | 高清日韩在线_亚洲精品色图_成人伊人网_hd德国xxxxhdvideos_武侠古典av_偷拍粉嫩25位美女视频在线观看 | 国内外一级毛片_av橹橹_成熟人妻AV无码专区_国产一国产二_日本精品aaa_国产无遮挡又黄又爽的视频 | 中文字日产幕码三区的做法大全_日日噜噜噜噜人人爽亚洲精品_国产互换人妻好紧hd无码_欧美1级a_国产性xx_国产亚洲小视频 | 国产精品久久久久久久久免费看_天天干天天天_丰满少妇作爱视频免费观看_精品三级在线看_久久精品中文视频_琉璃免费看 | 日本福利网站_日本视频三区_国产成人精品亚洲午夜麻豆_亚洲精品日日夜夜_久久久久久爱_少妇的丰满3中文字幕 | 在线观看视频精品_1313午夜精品理论片蜜桃网_国产另类在线视频_美女张开腿让男人视频_国产性爱自拍av_亚洲永久精品免费www | 日本BBWW高潮BBWR_免费无码的av片在线观看_国产精品久久久久这里只有精品_在线免费精品_加勒比一区二区无码视频在线_久久ZYZ资源站无码中文动漫 | 毛片毛片_18成年片免费视频网站_国内精品国产三级国产AV_久久成人激情_久草三级_搞逼视频免费 | 亚洲色图第一页_精品亚洲欧美无人区乱码_国产伦乱_蜜桃麻豆www久久国产精品_无码人妻h动漫_国产精品久久久久久无码不卡 | 日本久久小视频_一区不卡av_免费av毛片在线观看_中文字幕国产在线视频_无码免费H成年动漫在线观看网站_黑人又粗又大XXX精品 | 亚洲精品中文字幕一区二区三区_国产制服丝袜在线无码_噼里啪啦影视_日本成人一区二区三区_亚洲av无码1区2区久久_成av人在线 | 欧美亚洲日本国产_亚洲天堂2017无码_黄毛片在线观看_成人免费视频久久_天码欧美日本一道免费_成人久久亚洲 | 国产精品综合av无码_丰满少妇人妻久久久久久4_欧洲极品无码一区二区三区_亚洲精品mv免费_欧美日韩精品视频一区二区_国产精品视频海角社区88 | 色亚洲导航_av在线不卡一区_一本一本久久a久久_芭蕉视频在线观看成人_18出禁止看的啪视频网站_黄色在线免费网站 | 三级日本_好男人好视频好资源在线观看_国产老肥熟一区二区三区_国产线播放免费人成视频播放_亚洲视频2_国产无遮挡A片又黄又爽软件 | 中文字幕大香视频蕉免费_蜜臀av夜夜澡人人爽人人网站_欧美BBBWBBWBBWBBW_国产视频欧美_97夜夜模夜夜爽夜夜喊_性毛片视频 | 久久99热只有频精品8_欧美大黑帍在线播放_国产成人私拍pans大尺度_一区二区视频日韩免费_亚洲熟妇少妇任你躁在线观看_久久男人 | 玖草视频在线_天天做天天爱夜夜爽毛片毛片_久国产精品_国产黄a三级三级三级老年人_久久一区二区精品视频_黄色大片一区二区三区 | 亚洲AV福利天堂一区二区三_免费看中国毛片_久操视频网_手机永久无码国产AV毛片_国产欧美一区二区视频_制服丝袜中文字幕第一页 | 99亚洲国产精品_丰满熟女大屁股水多多_亚洲国语_日本五十路一区二区三区在线观看_婷婷日日夜夜_久久国产精品免费看 | 飘香影院午夜理论片A片_最近免费中文字幕大全免费_美女视频黄频a美女大全免费下_欧美在线观看a_国产一级毛片aa_日日爱网址 | 日日噜噜噜夜夜爽爽狠狠视频寻花_av视频在线观看_一区av_国产视频第一页在线观看_免费无码国产裸体_亚洲精品无码不卡 | 妖精视频一区二区三区_亚洲自拍p_久草在线资源网站_18禁无遮挡啪啪摇乳动态图_午夜不卡久久精品无码免费_美女视频黄是免费视频 | 日日夜操_久久国产精品系列_又大又粗又长的高潮视频_亚洲精品天天影视综合网_国内精品视频久久_麻豆乱码国产一区二区三区的优势 | 久在线播放_课中坏事在线看_欧美熟妇bbbbbb搡bbbb_黄色一级性片_亚洲国产精品二区_欧美一区二区三区人妻熟妇 国产精品成人观看视频国产奇米_欧美日韩中文视频_五月丁香五月伦理_亚洲国产精品成人综合久久久久久久_69式高清视频在线观看_四虎com | 黄页网站视频免费大全_2021高清精品国产_久久国产精品99久久久大便_亚洲精品国产剧情久久9191_国产欧美一区二区精品性_激情片一区二区 | 曰欧一片内射vα在线影院_少妇和教练在车里激情_精品视频久久久久_国产又黄又爽无遮挡不要VIP_久久久久亚洲AV无码专区网站_精品久久97 | 又爽又猛又粗国产免费_夜夜躁狠狠躁_欧美三极_无码成人片在线播放_高清一区二区三区视频_欧美久久久久久久久久伊人 | 久久久穴_九九九九免费视频_西西人体44www大胆无码_日韩精品在线看_日韩女同一区二区三区在线观看_斗破苍穹第三季免费观看 | 黄色一级播放_久久91精品国产91久久小草_美女黄网站免费福利视频_欧美亚洲综合网_久久人与动人物a级毛片_欧美视频网站在线观看 | 青娱乐国产在线观看_四虎影院在线免费观看视频_国产xxx在线观看_精品国产高清在线看国产_国产真实愉拍系列在线视频_国产成人无码一区二区在线播放 | 97超碰人人做人人爽3d_黄色片免费看._免费观看日韩毛片_中文字幕在线观看视频网站_亚洲精品久久五月天堂_亚洲色偷偷综合亚洲AV伊人 | 激情五月天色色狼婷婷_成人网站免费视频可能被黑_亚洲精品白浆高清久久久久久_国产又粗又猛又爽的视频A片_永久精品_浪货跪下给我好好含着羞辱调教 | 国产美女精品一区_免费看国产片在线观看_芭乐视频在线播放_囯产乱色国产精品免费视频_超碰97色_伊人日韩 | 最近中文字幕mv在线视频2018_在线日韩中文字幕_久久99亚洲精品久久99果冻_亚洲精品第三页_www.欧美在线观看_亚洲中文字幕无码专区 | 国产精品乱码一区二区视频_国产精品视频播放_99热精品视_成人日韩在线观看_亚洲永久_第一色站 |