【问题标题】:How to identify same objects in a image with different background, size and dimension如何识别具有不同背景、大小和尺寸的图像中的相同对象
【发布时间】:2021-05-10 11:34:15
【问题描述】:

我的要求有所不同。 我有一张放在桌面上的钥匙的图像。我有相同的钥匙,在地板上。照片和按键的尺寸和大小不同,但按键相同。现在我只想比较键并显示它们是相同的。如何使用 python 和 OpenCV。我当前的代码正在分析整个图像的直方图和灰度图像,但我希望它用于图像中的特定对象(这是关键)。

我当前的代码是;

# Original image
      image = cv2.imread(values[0])
      gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
      histogram = cv2.calcHist([gray_image], [0], 
                                 None, [256], [0, 256])

           
# Input1 image
      image1 = cv2.imread(values[1])
      gray_image1 = cv2.cvtColor(image1, cv2.COLOR_BGR2GRAY)
      histogram1 = cv2.calcHist([gray_image1], [0], 
                                  None, [256], [0, 256])

     
  
   
c1 = 0
   

i = 0
while i<len(histogram) and i<len(histogram1):
    c1+=(histogram[i]-histogram1[i])**2
    i+= 1
c1 = c1**(1 / 2)
   
  

if(c1==0):
    print("Input image is matching with original image.")
elif(c1>0 or c1<0):
 

print("输入图像与原图不匹配")

【问题讨论】:

    标签: python opencv image-processing image-comparison imageai


    【解决方案1】:

    您可以使用 OpenCv findHomographyperspectiveTransform,如文档 https://docs.opencv.org/2.4/doc/tutorials/features2d/feature_homography/feature_homography.html#feature-homography(旧版本)中的示例所示。

    已针对 Python 更新:https://docs.opencv.org/master/d1/de0/tutorial_py_feature_homography.html

    这个想法是在考虑单应性的两个图像中找到相同的对象特征:

    【讨论】:

    猜你喜欢
    • 2012-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-15
    • 2017-03-07
    • 1970-01-01
    • 2018-04-14
    • 2021-07-09
    相关资源
    最近更新 更多