跨平台和窗口本地化

Posted on 2020-05-27 16:42  金色的省略号  阅读(160)  评论(0编辑  收藏  举报

  通过 HighGUI工具包,可以帮助我们 完成一些文件和设备相关的任务HighGUI库 中还提供了一些内建的用于 创建窗体、显示图像、处理一些可能操作 的特性

  一、HighGUI原生图形用户接口,这些接口函数是OpenCV的一部分,并不需要额外的工具包支持

  使用 cv::namedWindow() 创建窗口

int cv::namedWindow(
    const string& name, // Handle used to identify window
    int flags = 0 // Used to tell window to autosize
);

  销毁一个窗口

int cv::destroyWindow(
    const string& name, // Handle used to identify window
);

  通过cv::imshow() 显示图像

void cv::imshow(
    const string& name, // Handle used to identify window
    cv::InputArray image // Image to display in window
)

  函数的第二个参数,cv::InputArray类对象,使用cv::Mat类对象,cv::Mat类型把向量、矩阵、图像等都统一了操作,cv::Mat有更强大的矩阵运算能力,支持常见的矩阵运算;窗口会保存显示图像的一个副本,在需要的时候从缓存中重画,因此图像显示后输入原图的改变不会影响到显示图像的内容,除非重新调用cv::imshow()

  窗口更新和cv::waitKey()

int cv::waitKey(
    int delay = 0 // Milliseconds until giving up (0='never')
);

  cv::waitkey()函数是用于对键盘按键事件进行特定时长的等待,如果有按键输入,则返回按键值

  鼠标事件

void your_mouse_callback(
    int event, // Event type( 见下表 )
    int x, // x-location of mouse event
    int y, // y-location of mouse event
    int flags, // More details on event (see Table 9-1)
    void* param // Parameters from cv::setMouseCallback()
);

  your_mouse_callback函数的第一个参数,是 鼠标事件类型  ( 鼠标事件类型及对应值 )

cv::EVENT_MOUSEMOVE     0
cv::EVENT_LBUTTONDOWN   1
cv::EVENT_RBUTTONDOWN   2
cv::EVENT_MBUTTONDOWN   3
cv::EVENT_LBUTTONUP     4
cv::EVENT_RBUTTONUP     5
cv::EVENT_MBUTTONUP     6
cv::EVENT_LBUTTONDBLCLK 7

  滑动条、滚动条和开关

   创建滑动条,cv::createTrackbar

int cv::createTrackbar(
    const string& trackbarName, // Handle used to identify trackbar
    const string& windowName, // Handle used to identify window
    int* value, // Slider position gets put here
    int count, // Total counts for slider at far right
    cv::TrackbarCallback onChange = NULL,// Callback function (optional)
    void* param = NULL // Additional params for callback fn.
);