为了解决以上问题,基于OpenCV和ORB的多摄像头拼接行人检测系统应运而生。OpenCV是一个开源的计算机视觉库,提供了丰富的图像处理和计算机视觉算法,可以方便地进行图像的处理、特征提取和目标检测等操作。ORB(Oriented FAST and Rotated BRIEF)是一种快速的特征提取和匹配算法,具有旋转不变性和尺度不变性,适用于多摄像头拼接行人检测系统中的特征匹配和跟踪。
goodPoints = [] for i inrange(len(matches) - 1): if matches[i].distance < self.GOOD_POINTS_LIMITED * matches[i + 1].distance: goodPoints.append(matches[i])
src_pts = np.float32([kp1[m.queryIdx].pt for m in goodPoints]).reshape(-1, 1, 2) dst_pts = np.float32([kp2[m.trainIdx].pt for m in goodPoints]).reshape(-1, 1, 2)
M, mask = cv.findHomography(dst_pts, src_pts, cv.RHO)
classStitcher: def__init__(self): global model model = ['ORB', 'SIFT', 'SURF', 'BRISK', 'AKAZE'] # determine if we are using OpenCV v3.X self.isv3 = imutils.is_cv3()
defforward(self, x): return x + self.cv2(self.cv1(x)) if self.add else self.cv2(self.cv1(x))
classSum(nn.Module): # Weighted sum of 2 or more layers https://arxiv.org/abs/1911.09070 def__init__(self, n, weight=False): # n: number of inputs super().__init__() self.weight = weight # apply weights boolean self.iter = range(n - 1) # iter object if weight: self.w = nn.Parameter(-torch.arange(1.0, n) / 2, requires_grad=True) # layer weights
defforward(self, x): y = x[0] # no weight if self.weight: w = torch.sigmoid(self.w) * 2 for i in self.iter: y = y + x[i + 1] * w[i] else: for i in self.iter: y = y + x[i + 1] return y
classMixConv2d(nn.Module): # Mixed Depth-wise Conv https://arxiv.org/abs/1907.09595 def__init__(self, c1, c2, k=(1, 3), s=1, equal_ch=True): # ch_in, ch_out, kernel, stride, ch_strategy super().__init__() n = len(k) # number of convolutions if equal_ch: # equal c_ per group i = torch.linspace(0, n - 1E-6, c2).floor() # c2 indices c_ = [(i == g).sum() for g inrange(n)] # intermediate channels else: # equal weight.numel() per group b = [c2] + [0] * n a = np.eye(n + 1, n, k=-1) a -= np.roll(a, 1, axis=1) a *= np.array(k) ** 2 a[0] = 1 c_ = np.linalg.lstsq(a, b, rcond=None)[0].round() # solve for equal weight indices, ax = b
defforward(self, x): return self.act(self.bn(torch.cat([m(x) for m in self.m], 1)))
classEnsemble(nn.ModuleList): # Ensemble of models def__init__(self): super().__init__()
defforward(self, x, augment=False, profile=False, visualize=False): y = [] for module in self: y.append(module(x, augment, profile, visualize)[0]) # y = torch.stack(y).max(0)[0] # max ensemble # y = torch.stack(y).mean(0) # mean ensemble y = torch.cat(y, 1) # nms ensemble return y, None# inference, train output
defattempt_load(weights, map_location=None, inplace=True, fuse=True): from models.yolo import Detect, Model
# Loads an ensemble of models weights=[a,b,c] or a single model weights=[a] or weights=a model = Ensemble() for w in weights ifisinstance(weights, list) else [weights]: ckpt = torch.load(attempt_download(w), map_location=map_location) # load if fuse: model.append(ckpt['ema'if ckpt.get('ema') else'model'].float().fuse().eval()) # FP32 model else: model.append(ckpt['ema'if ckpt.get('ema') else'model'].float().eval()) # without layer fuse
# Compatibility updates for m in model.modules(): iftype(m) in [nn.Hardswish, nn.LeakyReLU, nn.ReLU, nn.ReLU6, nn.SiLU, Detect, Model]: m.inplace = inplace # pytorch 1.7.0 compatibility iftype(m) is Detect: ifnotisinstance(m.anchor_grid, list): # new Detect Layer compatibility delattr(m, 'anchor_grid') setattr(m, 'anchor_grid', [torch.zeros(1)] * m.nl) eliftype(m) is Conv: m._non_persistent_buffers_set = set() # pytorch 1.6.0 compatibility
iflen(model) == 1: return model[-1] # return model else: print(f'Ensemble created with {weights}\n') for k in ['names']: setattr(model, k, getattr(model[-1], k)) model.stride = model[torch.argmax(torch.tensor([m.stride.max() for m in model])).int()].stride # max stride return model # return ensemble
[1]罗浩,姜伟,范星,等.基于深度学习的行人重识别研究进展[J].自动化学报.2019,(11).DOI:10.16383/j.aas.c180154. [2]佚名.Person re-identification with dictionary learning regularized by stretching regularization and label consistency constraint[J].Neurocomputing.2020,379(Feb.28).356-369.DOI:10.1016/j.neucom.2019.11.001. [3]Xiang Bai,Mingkun Yang.Deep-Person: Learning discriminative deep features for person Re-Identification[J].Pattern Recognition.2020.98107036.DOI:10.1016/j.patcog.2019.107036. [4]Lin, Yutian,Zheng, Liang,Zheng, Zhedong,等.Improving person re-identification by attribute and identity learning[J].Pattern Recognition: The Journal of the Pattern Recognition Society.2019.95151-161.DOI:10.1016/j.patcog.2019.06.006. [5]Huafeng Li,Shuanglin Yan,Zhengtao Yu,等.Attribute-Identity Embedding and Self-Supervised Learning for Scalable Person Re-Identification[J].Circuits & Systems for Video Technology, IEEE Transactions on.2019,30(10).3472-3485.DOI:10.1109/TCSVT.2019.2952550. [6]Li, Huafeng,Xu, Jiajia,Zhu, Jinting,等.Top distance regularized projection and dictionary learning for person re-identification[J].Information Sciences: An International Journal.2019.502472-491.DOI:10.1016/j.ins.2019.06.046. [7]Zhedong Zheng,Liang Zheng,Yi Yang.Pedestrian Alignment Network for Large-scale Person Re-Identification[J].Circuits & Systems for Video Technology, IEEE Transactions on.2018,29(10).3037-3045.DOI:10.1109/TCSVT.2018.2873599. [8]Hao Liu,Jiashi Feng,Meibin Qi,等.End-to-End Comparative Attention Networks for Person Re-Identification[J].IEEE Transactions on Image Processing.2017,26(7).3492-3506.DOI:10.1109/TIP.2017.2700762. [9]Dapeng Tao,Yanan Guo,Baosheng Yu,等.Deep Multi-View Feature Learning for Person Re-Identification[J].IEEE Transactions on Circuits & Systems for Video Technology.2017,28(10).2657-2666. [10]Zhao, Rui,Ouyang, Wanli,Wang, Xiaogang.Unsupervised Salience Learning for Person Re-identification[C].2013.