c – 在OpenCV中是否有类似MATLAB的’impixelinfo()’功能?

c – 在OpenCV中是否有类似MATLAB的’impixelinfo()’功能?,第1张

概述我在OpenCV中搜索的函数类似于MATLAB中的impixelinfo(). impixelinfo()向您展示 >像素(x,y)和的位置 >光标悬停在图像中的像素强度, 喜欢: impixelinfo() in matlab shows you this OpenCV中是否有任何实现?有没有人创建它的个人版本? 你可以这样做: #include <opencv2/opencv.hpp>#in 我在OpenCV中搜索的函数类似于MATLAB中的impixelinfo().

impixelinfo()向您展示

>像素(x,y)和的位置
>光标悬停在图像中的像素强度,

喜欢:

impixelinfo() in matlab shows you this

OpenCV中是否有任何实现?有没有人创建它的个人版本?

解决方法 你可以这样做:

#include <opencv2/opencv.hpp>#include <iostream>using namespace std;using namespace cv;Mat img;voIDCallBackFunc(int event,int x,int y,int flags,voID* userdata){   if(event==EVENT_MOUSEMOVE){      cout << "Pixel (" << x << "," << y << "): " << img.at<Vec3b>(y,x) << endl;   }}int main(){   // Read image from file    img=imread("demo.jpg");   // Check it loaded   if(img.empty())    {       cout << "Error loading the image" << endl;      exit(1);   }   //Create a window   nameDWindow("Imagedisplay",1);   // Register a mouse callback   setMouseCallback("Imagedisplay",CallBackFunc,nullptr);   // Main loop   while(true){      imshow("Imagedisplay",img);      waitKey(50);   }}

作为有用的评论的结果,我(希望)改进了代码并且现在处理灰度图像,并且还将RGB排序设置为更类似于非OpenCV爱好者可能期望的 – 即RGB而不是BGR.更新的功能如下:

voIDCallBackFunc(int event,voID* userdata){   if(event==EVENT_MOUSEMOVE){      // Test if greyscale or color      if(img.channels()==1){         cout << "Grey Pixel (" << x << "," << y << "): " << (int)img.at<uchar>(y,x) << endl;      } else {         cout << "RGB Pixel (" << x << "," << y << "): " << (int)img.at<Vec3b>(y,x)[2] << "/" << (int)img.at<Vec3b>(y,x)[1] << "/" << (int)img.at<Vec3b>(y,x)[0] << endl;      }   }}
总结

以上是内存溢出为你收集整理的c – 在OpenCV中是否有类似MATLAB的’impixelinfo()’功能?全部内容,希望文章能够帮你解决c – 在OpenCV中是否有类似MATLAB的’impixelinfo()’功能?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1217582.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-05
下一篇 2022-06-05

发表评论

登录后才能评论

评论列表(0条)

保存