我是C ++代码的新手。
我正在将dlib gui_widget用于图形用户界面。我想做的是在image_display中显示摄像机流。我从cv :: VideoCapture cap(0);获取摄像机流。我的方法是只显示流的第一帧。我知道流正在继续执行任务。
请告诉我如何更改代码。
我的简单代码在这里。
#include <memory>
#include <sstream>
#include <string>
#include <dlib/gui_widgets.h>
#include <dlib/string.h>
#include <dlib/opencv.h>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace dlib;
class main_window : public drawable_window
{
public:
main_window();
~main_window();
private:
image_display drawF;
};
int WINAPI WinMain(HINSTANCE, HINSTANCE, PSTR cmds, int)
{
main_window my_window;
my_window.show();
my_window.wait_until_closed();
return 0;
}
main_window::main_window() :
drawF(*this)
{
set_title("camera stream example");
set_size(1000, 500);
drawF.set_pos(20, 20);
drawF.set_size(200, 200);
cv::VideoCapture cap(0);
if (cap.isOpened())
{
cv::Mat temp;
if (cap.read(temp))
{
cv_image<bgr_pixel> cimg(temp);
drawF.set_image(cimg);
}
}
else
{
message_box("Problem", "Unable to connect to camera");
}
on_window_resized();
}
main_window::~main_window()
{
close_window();
}
void main_window::on_window_resized()
{
drawable_window::on_window_resized();
unsigned long width, height;
get_size(width, height);
if (width < 500 || height < 350)
return;
}