您的位置:首页 > 产品设计 > UI/UE

OpenCV学习HighGUI

2016-05-22 08:54 483 查看
// Create windows
namedWindow("xuelian", CV_GUI_NORMAL);//WINDOW_NORMAL: 可以改变窗口大小
namedWindow("shihui", WINDOW_AUTOSIZE);//WINDOW_AUTOSIZE: 根据图像大小显示窗口,大小不可改变

// Move window显示窗口的位置
moveWindow("xuelian", 10, 10);
moveWindow("shihui", 520, 10);
// show images
imshow("xuelian", picture1);
imshow("shihui", picture2);
// Resize window, only non autosize
resizeWindow("xuelian", 512, 512);

waitKey(0);//等待任意键按下

// Destroy the windows
destroyWindow("xuelian");
destroyWindow("shihui");
// Create 10 windows
for (int i = 0; i< 10; i++)
{
ostringstream ss;
ss << "shuhui " << i;
namedWindow(ss.str());
moveWindow(ss.str(), 20 * i, 20 * i);
imshow(ss.str(), picture2);
}
waitKey(0);
// Destroy all windows
destroyAllWindows();
return 0;
using namespace std;
using namespace cv;

Mat img;
bool applyGray = false;
bool applyBlur = false;
bool applySobel = false;

void applyFilters();

void grayCallback(int state, void* userData)
{
applyGray = true;
applyFilters();
}
void bgrCallback(int state, void* userData)
{
applyGray = false;
applyFilters();
}
void blurCallback(int state, void* userData)
{
applyBlur = (bool)state;
applyFilters();
}
void sobelCallback(int state, void* userData)
{
applySobel = !applySobel;
applyFilters();
}

void applyFilters(){
Mat result;
img.copyTo(result);
if (applyGray){
cvtColor(result, result, COLOR_BGR2GRAY);
}
if (applyBlur){
blur(result, result, Size(5, 5));
}
if (applySobel){
Sobel(result, result, CV_8U, 1, 1);
}
imshow("xuelian", result);
}

int main(int argc, const char** argv)

{

Mat img = imread("E://VS2013//face//xuelian//jpg//1.jpg");//载入图像 见

// Create windows
namedWindow("xuelian");
// create Buttons 每个按钮有5个参数分别是:按钮名字;回调函数;传给回调函数的数据指针;按钮类别;默认的按钮初始化值
createButton("Blur", blurCallback, NULL, QT_CHECKBOX, 0);
createButton("Gray", grayCallback, NULL, QT_RADIOBOX, 0);
createButton("RGB", bgrCallback, NULL, QT_RADIOBOX, 1);
createButton("Sobel", sobelCallback, NULL, QT_PUSH_BUTTON, 0);
// wait app for a key to exit
waitKey(0);
// Destroy the windows
destroyWindow("xuelian");
return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: