说明
本文用于保留,学习代码过程中,编写的鸡肋代码。
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