OPENCV / C++ - OPENCV检测鼠标单击位置并显示它,但没有绘制一个圆圈
我有此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;
}
I have this OpenCV Code where I want to draw a circle on a image each time i left click my mouse. It detect the position of my mouse at the time I pressed the left button and displays it aswell, but it doesn't draw a circle at the position.
Here is the code:
#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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简单地说:
循环中的
中,以便更新绘制圆圈后要显示的图像。
Simply put:
into a
while
loop, so that it updates the image being displayed after drawing the circle.