大佬教程收集整理的这篇文章主要介绍了c – 在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; void CallBACkFunc(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.更新的功能如下:
void CallBACkFunc(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()’功能?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。