cvui顯示圖片
測試有bug:貌似不支持顯示灰度圖,即CV_8UC1,暫時只能顯示彩色圖
直接進入主題
核心函數:
void image(cv::Mat& theWhere, int theX, int theY, cv::Mat& theImage);
- 第一個參數:背景圖層
- 第二個參數:圖片位於背景圖層的座標x
- 第三個參數:圖片位於背景圖層的座標y
- 第四個參數:傳入的圖片
有一點要注意的是,背景圖片的大小不能比佈局之後的大小小,即傳入的圖片不能在背景圖層之外
測試代碼:
#include <iostream>
using namespace std;
#define CVUI_IMPLEMENTATION
#include "cvui.h"
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<chrono>
using namespace cv;
#define WINDOW_NAME "CVUI Hello World!"
int main()
{
//要顯示的圖片
cv::Mat srcImage=cv::imread("//home//msi//opencv.jpg", cv::IMREAD_COLOR);
if(!srcImage.data){
cout<<"failed to read"<<endl;
system("pause");
return -1;
}
//背景圖層
cv::Mat frame = cv::Mat(srcImage.rows+50, srcImage.cols*2, CV_8UC3);
cvui::init(WINDOW_NAME);
while (true) {
// Fill the frame with a nice color
frame = cv::Scalar(49, 52, 49);
// Render UI components to the frame
cvui::text(frame, 10, 10, "Hello, Opencv");
//顯示圖片
cvui::image(frame,10,30,srcImage);
// Update cvui stuff and show everything on the screen
cvui::imshow(WINDOW_NAME, frame);
if (cv::waitKey(20) == 'q') {
break;
}
}
return 0;
}
測試效果: