如何从三个鼠标点击在OpenCV绘制一个圆圈



我想在给定3次鼠标点击的图像上画一个圆圈。我的意思是,我有一个图像,当我在这个图像上点击三次时,圆就画出来了。此外,我已经有代码来查找给定3个点的圆的参数。

Mat cember_denklemi(Point2f A,Point2f B,Point2f C) {
    double W[3][3]={{A.x,A.y,1},
                    {B.x,B.y,1},
                    {C.x,C.y,1}};
    double T[3][1]={-(A.x*A.x+A.y*A.y),
                    -(B.x*B.x+B.y*B.y),
                    -(C.x*C.x+C.y*C.y)};
    Mat M=Mat(3,3,CV_64F,W);
    Mat N=Mat(3,1,CV_64F,T);
    Mat L=M.inv()*N;
    return L;
}

And this my main:

#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <stdio.h>
#include <iostream>
using namespace std;
using namespace cv;
void mouseKordinat(int evt, int x, int y, int flags, void* ptr);
void getPixelValue(Mat img, int x, int y);
Mat image;
int main() {
    image = imread("c:/opencv2.4.6./atlas15.jpg");
    imshow("MyWindow", image);
    setMouseCallback("MyWindow", mouseKordinat, 0 );
    waitKey(0);
    return 0;
}
void mouseKordinat(int evt, int c, int r, int flags, void* ptr) {
    if(evt==CV_EVENT_LBUTTONDOWN) {
        getPixelValue(image,r,c);
    }
} 
void getPixelValue(Mat img, int r, int c) {
    Vec3b pix=img.at<Vec3b>(r,c);
    int B = pix.val[0];
    int G = pix.val[1];
    int R = pix.val[2];
    cout<<"Row:"<<r<<" "<<"Column:"<<c<<" - "; // mouse kordinatlari
    cout<<"B:"<<B<<" "<<"G:"<<G<<" "<<"R:"<<R<<"n"; // kordinatın pixel değerleri
}

我不能合并这些代码;但我已经做到了

#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <stdio.h>
#include <iostream>
using namespace std;
using namespace cv;
static int mouse_x = -1;
static int mouse_y = -1;
Mat circle_eq(Point2f A,Point2f B,Point2f C)
{
    double W[3][3]={{A.x,A.y,1},
                    {B.x,B.y,1},
                    {C.x,C.y,1}};
    double T[3][1]={-(A.x*A.x+A.y*A.y),
                    -(B.x*B.x+B.y*B.y),
                    -(C.x*C.x+C.y*C.y)};
    Mat M=Mat(3,3,CV_64F,W);
    Mat N=Mat(3,1,CV_64F,T);
    Mat L=M.inv()*N;
    return L;
}
void mouseKordinat(int evt, int x, int y, int flags, void* ptr)
{
if(evt == CV_EVENT_MOUSEMOVE)
  {
    mouse_x = x;
    mouse_y = y;
  }
int tik;
  tik = tik + 1;
}
void getPixelValue(Mat img, int x, int y);
Mat image;
int main()
{
 image = imread("c:/qwz/1q.jpg");
 imshow("MyWindow", image);
 setMouseCallback("MyWindow", mouseKordinat, 0 );
tik = tik%=3;
if(tik==0)
{   
int merkez=circle_eq(nokta(0), nokta(1), nokta(2));
circle(image,merkez,3, Scalar(255,255,255),-1,8, nokta(0));
}
if(tik>3)
{
    int nokta[0][0]=0;

}
  waitKey(0);
 return 0;
}
void mouseKordinat(int evt, int c, int r, int flags, void* ptr)
{
 if(evt==CV_EVENT_LBUTTONDOWN)
 {
 getPixelValue(image,r,c);
 }
}
void getPixelValue(Mat img, int r, int c)
{
 Vec3b pix=img.at<Vec3b>(r,c);
 int B = pix.val[0];
 int G = pix.val[1];
 int R = pix.val[2];
 cout<<"Row:"<<r<<" "<<"Column:"<<c<<" - "; 
 cout<<"B:"<<B<<" "<<"G:"<<G<<" "<<"R:"<<R<<"n"; 
}

相关内容

  • 没有找到相关文章

最新更新