基于makefile的程序编写示例

说明

本文用于保留,学习代码过程中,编写的鸡肋代码。
main.cpp

#include <librealsense2/rs.hpp>
#include <opencv2/opencv.hpp>


//                                     These parameters are reconfigurable                                        //

#define STREAM          RS2_STREAM_COLOR  // rs2_stream is a types of data provided by RealSense device           //
#define FORMAT          RS2_FORMAT_RGB8   // rs2_format identifies how binary data is encoded within a frame      //
#define WIDTH           640               // Defines the number of columns for each frame                         //
#define HEIGHT          480               // Defines the number of lines for each frame                           //
#define FPS             30                // Defines the rate of frames per second                                //
#define STREAM_INDEX    0                 // Defines the stream index, used for multiple streams of the same type //



class CAMERA
{
public:
    CAMERA();
    ~CAMERA();

    cv::Mat image;
    void cameraStart();

    rs2::pipeline pipe;
    rs2::config cfg;
    rs2::frameset frames;
    rs2::video_frame color_frame{nullptr};
};

CAMERA::CAMERA()
{
    cfg.enable_stream(RS2_STREAM_COLOR, WIDTH, HEIGHT, RS2_FORMAT_BGR8, FPS);
    pipe.start(cfg);
}

CAMERA::~CAMERA() { pipe.stop(); };

void CAMERA::cameraStart()
{

    frames = pipe.wait_for_frames();
    color_frame = frames.get_color_frame();
    if (!color_frame)
    {
    }
    auto width = color_frame.get_width();
    auto height = color_frame.get_height();
    image = cv::Mat(cv::Size(width, height), CV_8UC3, (void *)color_frame.get_data(), cv::Mat::AUTO_STEP);
    cv::waitKey(1);
    std::cout << "here" << std::endl;
}

int main()
{
    CAMERA camera;
    while (true)
    {
        camera.cameraStart();
        cv::imshow("test", camera.image);
        cv::waitKey(1);
    }
    cv::destroyAllWindows();
    return 0;
}

makefile

opencv_LIBDIR=D:/program/opencv/build/x64/vc16/lib
opencv_LIBS=libopencv_world4100

REALSENSE_LIBDIR=D:/program/IntelRealSense-SDK2.0/lib/x64
REALSENSE_LIBS=realsense2

# 源文件
SRC=main.cpp

# 目标文件(.obj 文件)
OBJ=$(SRC:.cpp=.obj)

# 最终的可执行文件
TARGET=main.exe

# 运行可执行文件
run: $(TARGET)
    $(TARGET)

# 默认目标
all: $(TARGET)

# 链接目标文件生成可执行文件
$(TARGET): $(OBJ)
    $(CXX) $(CXXFLAGS) -o $(TARGET) $(OBJ) $(opencv_LIBDIR)/$(opencv_LIBS).lib $(REALSENSE_LIBDIR)/$(REALSENSE_LIBS).lib

# 编译源文件生成目标文件
$(OBJ): $(SRC)
    $(CXX) $(CXXFLAGS) $(ALLINCLUDE) -c $(SRC) -o $(OBJ)

# 清除编译生成的文件
clean:
    del *.obj
    del $(TARGET)

使用

cd path/to/project/
make -j4
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值