OpenCV / C++ - OpenCV 检测鼠标点击位置并显示它,但不画圆
OpenCV / C++ - OpenCV detect mouse click position and displays it, but doesn't draw a circle
我有这个 OpenCV 代码,每次左键单击鼠标时我都想在图像上画一个圆圈。它检测到我按下左键时鼠标的位置并显示出来,但它没有在该位置画圆。
代码如下:
#include <iostream>
#include <vector>
#include <string>
#include <opencv2/imgproc.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/core.hpp>
cv::Mat inputImage;
void Draw(int event, int x, int y, int flags, void* param)
{
if (event & cv::EVENT_LBUTTONDOWN)
{
std::cout << "X " << x << " Y " << y << std::endl;
cv::circle(inputImage, cv::Point(x, y), 25, cv::Scalar(0, 255, 0), cv::FILLED, cv::LINE_AA);
}
}
int main(int argc, char** argv)
{
std::string path = "C:\Users\dfad\Downloads\dyp.png";
inputImage = cv::imread(path);
cv::namedWindow("Image");
cv::setMouseCallback("Image", Draw, NULL);
cv::resize(inputImage, inputImage, cv::Size(800, 800), cv::INTER_LINEAR);
cv::circle(inputImage, cv::Point(130, 130), 10, cv::Scalar(0, 255, 0), cv::FILLED);
cv::imshow("Image", inputImage);
cv::waitKey(0);
return 0;
}
简单地说:
cv::imshow("Image", inputImage);
进入 while
循环,以便在绘制圆圈后更新正在显示的图像。
我有这个 OpenCV 代码,每次左键单击鼠标时我都想在图像上画一个圆圈。它检测到我按下左键时鼠标的位置并显示出来,但它没有在该位置画圆。
代码如下:
#include <iostream>
#include <vector>
#include <string>
#include <opencv2/imgproc.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/core.hpp>
cv::Mat inputImage;
void Draw(int event, int x, int y, int flags, void* param)
{
if (event & cv::EVENT_LBUTTONDOWN)
{
std::cout << "X " << x << " Y " << y << std::endl;
cv::circle(inputImage, cv::Point(x, y), 25, cv::Scalar(0, 255, 0), cv::FILLED, cv::LINE_AA);
}
}
int main(int argc, char** argv)
{
std::string path = "C:\Users\dfad\Downloads\dyp.png";
inputImage = cv::imread(path);
cv::namedWindow("Image");
cv::setMouseCallback("Image", Draw, NULL);
cv::resize(inputImage, inputImage, cv::Size(800, 800), cv::INTER_LINEAR);
cv::circle(inputImage, cv::Point(130, 130), 10, cv::Scalar(0, 255, 0), cv::FILLED);
cv::imshow("Image", inputImage);
cv::waitKey(0);
return 0;
}
简单地说:
cv::imshow("Image", inputImage);
进入 while
循环,以便在绘制圆圈后更新正在显示的图像。