比较两个图像特定区域的直方图? OpenCV的 [英] Compare histograms of specific areas of two images? OpenCV

查看:169
本文介绍了比较两个图像特定区域的直方图? OpenCV的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我希望能够比较两个直方图,但不能比较整个图像,而只能比较特定区域.我有图像A,并且在图像上有一个特定的矩形区域,我想与另一个图像B进行比较.有没有办法获取图像上可定义的矩形区域的直方图?我具有矩形区域的x y位置以及宽度和高度,并希望获得其直方图.我正在使用带有Python的opencv.

Basically, I want to be able to compare two histograms, but not of whole images just specific areas. I have image A and have a specific rectangular region on it that I want to compare to another image B. Is there a way to get the histogram of a definable rectangular region on an image? I have the x y position of the rectangular area, as well as it's width and height, and want to get its histogram. I'm using opencv with python.

很抱歉,如果不是很清楚:(

Sorry if that isn't very clear :(

(我正在建立一个程序,该程序可以拍摄电路板的图片,并检查每个焊垫是否与理想电路板的图像一致.如果一个焊垫处于关闭状态,则该程序会升起一个标志,指出特定的焊垫偏离x百分比,而不是整个董事会.

(I'm setting up a program that takes a picture of a circuit board, and checks each solder pad for consistency with an image of a perfect board. If one pad is off, the program raises a flag saying that specific pad is off by x percent, not the whole board.

推荐答案

注意:以下是C ++语言,但我认为找到与Python等效的函数并不难.

Note: The following is in C++ but I think it is not hard to find the equivalent functions for python.

您可以使用教程.例如,对于莉娜图像,我们得到:

You can find the histogram of an image using this tutorial. So for example for the lena image we get:

在这种情况下,由于具有矩形坐标,因此只需提取图像的ROI:

In your case, since you have the rectangle coordinates, you can just extract the ROI of the image:

// C++ code
cv::Mat image = cv::imread("lena.png", 0);
cv::Rect roiRect = cv::Rect(150, 150, 250, 250);
cv::Mat imageRoi = image(roiRect);

,然后以与上述相同的方式找到ROI的直方图:

and then find the histogram of just the ROI with the same way as above:

这是您想要的(至少在理论上)还是被我误解了?

Is this what you wanted (in theory at least) or I misunderstood?

这篇关于比较两个图像特定区域的直方图? OpenCV的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆