如何刷新显示的窗口?

时间:2019-01-06 12:38:18

标签: opencv

每次单击显示的窗口时,我都希望绘制一个圆圈。以下代码不刷新窗口。怎么做?

#include <iostream>
#include <opencv2/opencv.hpp>

using namespace cv;
using namespace std;

const string filename = "family.jpg";
const string sourceWindow = "source";

void onMouse(int event, int x, int y, int flags, void* param)
{
    Mat* image = reinterpret_cast<Mat*>(param);
    switch (event)
    {
    case cv::EVENT_LBUTTONDOWN:
        cout << "at (" << x << "," << y << ") values is: "
            << static_cast<int>(image->at<uchar>(Point(x, y))) << endl;
        circle(*image, Point(x, y), 65, 0, 5);
        break;
    }
}

void main()
{
    Mat src = imread(filename, IMREAD_GRAYSCALE);
    if (!src.empty())
    {
        namedWindow(sourceWindow, WINDOW_NORMAL);
        imshow(sourceWindow, src);
        setMouseCallback(sourceWindow, onMouse, reinterpret_cast<void*>(&src));
    }
    waitKey(0);
}

1 个答案:

答案 0 :(得分:1)

就像视频捕获一样(请参见VideoCapture

您只需再次调用新图片imshow

void onMouse(int event, int x, int y, int flags, void* param)
{
    Mat* image = reinterpret_cast<Mat*>(param);
    switch (event)
    {
    case cv::EVENT_LBUTTONDOWN:
        cout << "at (" << x << "," << y << ") values is: "
            << static_cast<int>(image->at<uchar>(Point(x, y))) << endl;
        circle(*image, Point(x, y), 65, 0, 5);
        imshow(sourceWindow, image);
        break;
    }
}