美文网首页
读取图像像素点坐标[gray]

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

作者: 带着白卡去旅行 | 来源:发表于2018-09-27 19:38 被阅读131次

    参考资料:

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

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

    #include<opencv2/opencv.hpp>
    #include<math.h>
    #include<iostream>
    
    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]

          本文链接:https://www.haomeiwen.com/subject/fhryoftx.html