读取图像像素点坐标[gray]

参考资料:

链接:https://blog.csdn.net/jiakeyouwe/article/details/52075922
https://blog.csdn.net/bisheng250/article/details/53840682

最近遇到读取图像像素坐标点问题,查阅了相关问题的资料后发现,大部分都是基于opencv2.0以下的程序。所以打算通过借鉴大佬们的程序,写一个基于opencv3的程序,先完成初步的效果,后面再改进。
直接上程序:

#include
#include
#include

void Myshowpoint( int event, int x, int y, int flags,void*);
using namespace cv;

Mat image, dst;


void Myshowpoint(int event, int x, int y, int flags, void* param)
{
    static Point pre_pt = { -1,-1 };
    static Point cur_pt = { -1,-1 };

    CvFont font;
    uchar*ptr;
    char temp[20];
    cvInitFont(&font, CV_FONT_HERSHEY_PLAIN, 1, 1, 0, 1, 1);

    //鼠标事件
    if (event == CV_EVENT_LBUTTONDOWN)
    {
        image.copyTo(dst);

        //cvCopy(pSrcImg,pImg,NULL);   //代替 pImg = cvCloneImage(pSrcImg);
        sprintf(temp, "(%d,%d)", x, y);
        pre_pt = Point(x, y);
        //显示
        putText(image, temp, Point(x, y), FONT_HERSHEY_PLAIN, 0.5, Scalar(255, 255, 255));
        //选中的点绘制圆

        circle(image, pre_pt, 2, Scalar(0, 255, 0), 1, 8, 0);
        imshow("image", image);
        image.copyTo(dst);
    }
}



int main()
{

    //Mat src;
    image  = imread("a.jpg",0);
    if (!image.data)
    {
        printf("can not find image file..\n");
        return -1;
    }

    
    namedWindow("src", WINDOW_AUTOSIZE);

    setMouseCallback("src", Myshowpoint, 0);
    imshow("src", image);

    waitKey(0);
    return 0;
}

效果图:


读取像素坐标

你可能感兴趣的:(读取图像像素点坐标[gray])