而面板的模式可以参照如下opencv的显示
- class BasicDrawPane: public wxPanel {
- public:
- BasicDrawPane(wxFrame* parent);
- void paintEvent(wxPaintEvent& evt);
- void paintNow();
- void render(wxDC& dc);
- DECLARE_EVENT_TABLE()
- };
- BEGIN_EVENT_TABLE(BasicDrawPane, wxPanel)
- EVT_PAINT(BasicDrawPane::paintEvent) END_EVENT_TABLE()
- BasicDrawPane::BasicDrawPane(wxFrame* parent) :
- wxPanel(parent) {
- }
- void BasicDrawPane::paintEvent(wxPaintEvent& evt) {
- wxPaintDC dc(this);
- render(dc);
- }
- void BasicDrawPane::paintNow() {
- wxClientDC dc(this);
- render(dc);
- }
- void BasicDrawPane::render(wxDC& dc) {
- if (cap.read(ori))//从摄像头读取一帧图像到mat数据ori中
- process();//自己的opencv处理函数
- cvtColor(frame, temp, CV_RGB2BGR);
- wxImage wxImage0(temp.cols, temp.rows, temp.data, true);
- wxBitmap wxBitmap0 = wxBitmap(wxImage0);
- dc.DrawBitmap(wxBitmap0, 0, 0);
- }
当中一个关键点是是如何将opencv的mat数据显示出来 其实很简单的几句代码就可以了
frame和temp都是opencv的mat类数据
要将frame图像显示出来 先进行rgb到bgr转换 再wximage转换、wxbitmap转换即可
- cvtColor(frame, temp, CV_RGB2BGR);
- wxImage wxImage0(temp.cols, temp.rows, temp.data, true);
- wxBitmap wxBitmap0 = wxBitmap(wxImage0);
- dc.DrawBitmap(wxBitmap0, 0, 0);
