【发布时间】:2021-01-01 05:49:12
【问题描述】:
我正在做一个项目,我必须从鸟瞰图检测彩色车辆。请参阅下面的图像框架
因为我认为在这种情况下,深度学习是多余的,所以我决定使用经典的检测管道,通过应用直方图反投影方法来检测红色车辆。
我使用的代码如下所示
#import packages
import cv2
import numpy as np
import matplotlib.pyplot as plt
#defining disk for the convolution
disc = cv2.getStructuringElement(cv2.MORPH_RECT,(10,10))
#defining Kernel
kernel=cv2.getStructuringElement(cv2.MORPH_RECT, (3,3))
kernel1 = np.ones((5,5),np.uint8)
#preparing the object model by cropping the target object and reading it
Red_Model=cv2.imread(r'C:/Users/kjbaili/.spyder-py3/webcam_calib/red_new_uniform.png')
#convert object_model to hsv
hsv_red = cv2.cvtColor(Red_Model, cv2.COLOR_BGR2HSV)
cv2.imshow('HSV_Model',hsv_red)
#calculating histogram of object_model
M = cv2.calcHist([hsv_red],[0,1],None,[180,256],[0,180,0,256])
#reading the image where we want to search for the target object
img=cv2.imread(r'C:/Users/kjbaili/.spyder-py3/Mean_Shift/MST_with_3D_projection/messigray1.png')
#converting the image to hsv
hsv_img = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
#calculating histogram of image
I= cv2.calcHist([hsv_img],[0,1],None,[180,256],[0,180,0,256])
#calculating the ration histogram
R=M.copy() /I.copy()
#extracting the image channels
h,s,v = cv2.split(hsv_img.copy())
#backprojecting the R_red hist
B1 = R[h.ravel(),s.ravel()]
#reshaping the resulted vector into image and normalize the values between 0 and 1
B2=B1.reshape(hsv_img.copy().shape[:2])
B = np.minimum(B1.copy(),1)
B = B.reshape(hsv_img.copy().shape[:2])
#removing noises
open_B_red=cv2.morphologyEx(B.copy(),cv2.MORPH_OPEN,kernel)
Filter_red=cv2.filter2D(open_B_red.copy(),-1,disc,open_B_red)
#displaying results
cv2.imshow('Filter',Filter_red)
cv2.waitKey(0)
cv2.destroyAllWindows()
但是,当对象的颜色与背景颜色相似时如下图_它也会检测到我的 T 恤,它会同时检测到这两种颜色,因此无法仅区分目标对象
因此,我想到了使用附加特征和颜色特征来增强检测,使其仍然检测到目标对象,尽管颜色相似度很小,结果如此称为“Local Binary Pattern-LBP”,它计算对象的纹理。事实上,我可以计算物体和图像的 LBP,但是不知道将它与上述方法集成,以便通过颜色纹理检测来检测红色车辆。
因此,我真的很想知道如何在这种情况下使用 LBP 的 T纹理特征甚至其他附加特征来改进检测。
有关 LBP 的信息,请参阅:https://towardsdatascience.com/face-recognition-how-lbph-works-90ec258c3d6b
有关直方图反投影如何工作的信息:https://theailearner.com/2019/04/18/histogram-backprojection/
【问题讨论】:
-
T恤和汽车有什么不同? 1.汽车是具有恒定 w/h 比 (~2-2.5) 的矩形。 2.汽车是凸形的。您可以尝试使用此属性。
-
感谢您的评论。你的意思是我告诉算法在结果蒙版图像中寻找矩形而不是其他所有东西? ?@AlexAlex
-
从蒙版图像中获取轮廓。然后过滤纵横比和面积。
-
。感谢您的评论。 .你能用一个例子来表达吗? . @fmw42
-
你的T恤很少有相同的方面和面积。因此,使用方面和区域的组合进行测试。汽车的尺寸几乎相同。
标签: python numpy opencv image-processing object-detection