import numpy as np
def nms(dets,thres):
x1 = dets[:,0]
y1 = dets[:,1]
x2 = dets[:,2]
y2 = dets[:,3]
scores = dets[:,4]
area = (x2-x1+1)*(y2-y1+1)
order = scores.argsort()[::-1]
keep = []
while order.size >0:
index = order[0]
keep.append(index)
xx1 = np.maximum(x1[index],x1[order[1:]])
yy1 = np.maximum(y1[index],y1[order[1:]])
xx2 = np.minimum(x2[index],x2[order[1:]])
yy2 = np.minimum(y2[index],y2[order[1:]])
w = np.maximum(0,xx2-xx1+1)
h = np.maximum(0,yy2-yy1+1)
inter = w*h
iou = inter/(area[index]+area[order[1:]]-inter)
inds = np.where(iou<=thres)[0]
order = order[inds+1]
return keep
def conv(kernel,data):
h,w=data.shape
img_new = []
for i in range(h-3):
line =[]
for j in range(w-3):
a = data[i:i+3,j:j+3]
line.append(np.sum(np.multiply(kernel,a)))
img_new.append(line)
return np.array(img_new)
numpy实现卷积、nms
于 2022-03-04 09:50:47 首次发布